158 lines
6.2 KiB
Java
158 lines
6.2 KiB
Java
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
|
|
|
|
import eu.eudat.commons.types.descriptiontemplate.fielddata.AutoCompleteDataEntity;
|
|
import eu.eudat.commons.validation.BaseValidator;
|
|
import eu.eudat.commons.validation.ValidatorFactory;
|
|
import eu.eudat.commons.validation.specification.Specification;
|
|
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;
|
|
import java.util.List;
|
|
|
|
public class AutoCompleteSingleDataPersist {
|
|
|
|
private AutoCompleteDataEntity.AutocompleteType autocompleteType;
|
|
|
|
public static final String _autocompleteType = "autocompleteType";
|
|
|
|
private String url = null;
|
|
|
|
public static final String _url = "url";
|
|
|
|
private ComboBoxOptionPersist autoCompleteOptions;
|
|
|
|
public static final String _autoCompleteOptions = "autoCompleteOptions";
|
|
|
|
private String optionsRoot;
|
|
|
|
private Boolean hasAuth = null;
|
|
|
|
public static final String _hasAuth = "hasAuth";
|
|
|
|
private AuthAutoCompleteDataPersist auth;
|
|
|
|
public static final String _auth = "auth";
|
|
|
|
private String method = null;
|
|
|
|
public static final String _method = "method";
|
|
|
|
public AutoCompleteDataEntity.AutocompleteType getAutocompleteType() {
|
|
return autocompleteType;
|
|
}
|
|
|
|
public void setAutocompleteType(AutoCompleteDataEntity.AutocompleteType autocompleteType) {
|
|
this.autocompleteType = autocompleteType;
|
|
}
|
|
|
|
public String getOptionsRoot() {
|
|
return optionsRoot;
|
|
}
|
|
|
|
public void setOptionsRoot(String optionsRoot) {
|
|
this.optionsRoot = optionsRoot;
|
|
}
|
|
|
|
public String getUrl() {
|
|
return url;
|
|
}
|
|
|
|
public void setUrl(String url) {
|
|
this.url = url;
|
|
}
|
|
|
|
public Boolean getHasAuth() {
|
|
return hasAuth;
|
|
}
|
|
|
|
public void setHasAuth(Boolean hasAuth) {
|
|
this.hasAuth = hasAuth;
|
|
}
|
|
|
|
public AuthAutoCompleteDataPersist getAuth() {
|
|
return auth;
|
|
}
|
|
|
|
public void setAuth(AuthAutoCompleteDataPersist auth) {
|
|
this.auth = auth;
|
|
}
|
|
|
|
public ComboBoxOptionPersist getAutoCompleteOptions() {
|
|
return autoCompleteOptions;
|
|
}
|
|
|
|
public void setAutoCompleteOptions(ComboBoxOptionPersist autoCompleteOptions) {
|
|
this.autoCompleteOptions = autoCompleteOptions;
|
|
}
|
|
|
|
public String getMethod() {
|
|
return method;
|
|
}
|
|
|
|
public void setMethod(String method) {
|
|
this.method = method;
|
|
}
|
|
|
|
@Component(AutoCompleteSingleDataPersistValidator.ValidatorName)
|
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
public static class AutoCompleteSingleDataPersistValidator extends BaseValidator<AutoCompleteSingleDataPersist> {
|
|
|
|
public static final String ValidatorName = "DescriptionTemplate.AutoCompleteSingleDataPersistValidator";
|
|
|
|
private final MessageSource messageSource;
|
|
|
|
private final ValidatorFactory validatorFactory;
|
|
|
|
protected AutoCompleteSingleDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
|
|
super(conventionService, errors);
|
|
this.messageSource = messageSource;
|
|
this.validatorFactory = validatorFactory;
|
|
}
|
|
|
|
@Override
|
|
protected Class<AutoCompleteSingleDataPersist> modelClass() {
|
|
return AutoCompleteSingleDataPersist.class;
|
|
}
|
|
|
|
@Override
|
|
protected List<Specification> specifications(AutoCompleteSingleDataPersist item) {
|
|
return Arrays.asList(
|
|
this.spec()
|
|
.must(() -> !this.isNull(item.getAutocompleteType()))
|
|
.failOn(AutoCompleteSingleDataPersist._autocompleteType).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteSingleDataPersist._autocompleteType}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.must(() -> !this.isEmpty(item.getUrl()))
|
|
.failOn(AutoCompleteSingleDataPersist._url).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteSingleDataPersist._url}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.must(() -> !this.isNull(item.getHasAuth()))
|
|
.failOn(AutoCompleteSingleDataPersist._hasAuth).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteSingleDataPersist._hasAuth}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.must(() -> !this.isEmpty(item.getMethod()))
|
|
.failOn(AutoCompleteSingleDataPersist._method).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteSingleDataPersist._method}, LocaleContextHolder.getLocale())),
|
|
|
|
this.refSpec()
|
|
.iff(() -> !this.isNull(item.getAutoCompleteOptions()))
|
|
.on(AutoCompleteSingleDataPersist._autoCompleteOptions)
|
|
.over(item.getAutoCompleteOptions())
|
|
.using(() -> this.validatorFactory.validator(ComboBoxOptionPersist.ComboBoxOptionPersistValidator.class)),
|
|
this.spec()
|
|
.iff(() -> !this.isNull(item.getHasAuth()) && item.getHasAuth())
|
|
.must(() -> !this.isNull(item.getAuth()))
|
|
.failOn(AutoCompleteSingleDataPersist._auth).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteSingleDataPersist._auth}, LocaleContextHolder.getLocale())),
|
|
this.refSpec()
|
|
.iff(() -> !this.isNull(item.getAuth()))
|
|
.on(AutoCompleteSingleDataPersist._auth)
|
|
.over(item.getAuth())
|
|
.using(() -> this.validatorFactory.validator(AuthAutoCompleteDataPersist.AuthAutoCompleteDataPersistValidator.class))
|
|
);
|
|
}
|
|
}
|
|
|
|
}
|