2023-11-24 14:12:02 +01:00
|
|
|
package eu.eudat.model.persist.tenantconfig;
|
|
|
|
|
2024-01-04 10:51:56 +01:00
|
|
|
import eu.eudat.commons.validation.BaseValidator;
|
2024-01-17 10:20:02 +01:00
|
|
|
import gr.cite.tools.validation.specification.Specification;
|
2024-01-04 10:51:56 +01:00
|
|
|
import eu.eudat.convention.ConventionService;
|
|
|
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
|
|
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
|
|
|
import org.springframework.context.MessageSource;
|
|
|
|
import org.springframework.context.annotation.Scope;
|
|
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
2023-11-24 14:12:02 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class TenantSourcePersist {
|
|
|
|
|
|
|
|
private String url;
|
|
|
|
|
2024-01-04 10:51:56 +01:00
|
|
|
public static final String _url = "url";
|
|
|
|
|
2023-11-24 14:12:02 +01:00
|
|
|
private List<String> codes;
|
|
|
|
|
2024-01-04 10:51:56 +01:00
|
|
|
public static final String _codes = "codes";
|
|
|
|
|
|
|
|
private String issuerUrl;
|
|
|
|
|
|
|
|
public static final String _issuerUrl = "issuerUrl";
|
2023-11-24 14:12:02 +01:00
|
|
|
|
|
|
|
private String clientId;
|
|
|
|
|
2024-01-04 10:51:56 +01:00
|
|
|
public static final String _clientId = "clientId";
|
|
|
|
|
2023-11-24 14:12:02 +01:00
|
|
|
private String clientSecret;
|
|
|
|
|
2024-01-04 10:51:56 +01:00
|
|
|
public static final String _clientSecret = "clientSecret";
|
|
|
|
|
2023-11-24 14:12:02 +01:00
|
|
|
private String scope;
|
|
|
|
|
2024-01-04 10:51:56 +01:00
|
|
|
public static final String _scope = "scope";
|
|
|
|
|
2023-11-24 14:12:02 +01:00
|
|
|
public String getUrl() {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setUrl(String url) {
|
|
|
|
this.url = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<String> getCodes() {
|
|
|
|
return codes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCodes(List<String> codes) {
|
|
|
|
this.codes = codes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getIssuerUrl() {
|
|
|
|
return issuerUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setIssuerUrl(String issuerUrl) {
|
|
|
|
this.issuerUrl = issuerUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getClientId() {
|
|
|
|
return clientId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setClientId(String clientId) {
|
|
|
|
this.clientId = clientId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getClientSecret() {
|
|
|
|
return clientSecret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setClientSecret(String clientSecret) {
|
|
|
|
this.clientSecret = clientSecret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getScope() {
|
|
|
|
return scope;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setScope(String scope) {
|
|
|
|
this.scope = scope;
|
|
|
|
}
|
2024-01-04 10:51:56 +01:00
|
|
|
|
|
|
|
@Component(TenantSourcePersistValidator.ValidatorName)
|
|
|
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
|
|
public static class TenantSourcePersistValidator extends BaseValidator<TenantSourcePersist> {
|
|
|
|
|
|
|
|
public static final String ValidatorName = "TenantSourcePersistValidator";
|
|
|
|
|
|
|
|
private final MessageSource messageSource;
|
|
|
|
|
|
|
|
protected TenantSourcePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
|
|
|
|
super(conventionService, errors);
|
|
|
|
this.messageSource = messageSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Class<TenantSourcePersist> modelClass() {
|
|
|
|
return TenantSourcePersist.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<Specification> specifications(TenantSourcePersist item) {
|
|
|
|
return Arrays.asList(
|
|
|
|
this.spec()
|
|
|
|
.must(() -> !this.isEmpty(item.getUrl()))
|
|
|
|
.failOn(TenantSourcePersist._url).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantSourcePersist._url}, LocaleContextHolder.getLocale())),
|
|
|
|
this.spec()
|
2024-01-16 10:55:46 +01:00
|
|
|
.must(() -> !this.isListNullOrEmpty(item.getCodes()))
|
2024-01-04 10:51:56 +01:00
|
|
|
.failOn(TenantSourcePersist._codes).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantSourcePersist._codes}, LocaleContextHolder.getLocale())),
|
|
|
|
this.spec()
|
|
|
|
.must(() -> !this.isEmpty(item.getIssuerUrl()))
|
|
|
|
.failOn(TenantSourcePersist._issuerUrl).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantSourcePersist._issuerUrl}, LocaleContextHolder.getLocale())),
|
|
|
|
this.spec()
|
|
|
|
.must(() -> !this.isEmpty(item.getClientId()))
|
|
|
|
.failOn(TenantSourcePersist._clientId).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantSourcePersist._clientId}, LocaleContextHolder.getLocale())),
|
|
|
|
this.spec()
|
|
|
|
.must(() -> !this.isEmpty(item.getClientSecret()))
|
|
|
|
.failOn(TenantSourcePersist._clientSecret).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantSourcePersist._clientSecret}, LocaleContextHolder.getLocale())),
|
|
|
|
this.spec()
|
|
|
|
.must(() -> !this.isEmpty(item.getScope()))
|
|
|
|
.failOn(TenantSourcePersist._scope).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantSourcePersist._scope}, LocaleContextHolder.getLocale()))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-24 14:12:02 +01:00
|
|
|
}
|