99 lines
3.6 KiB
Java
99 lines
3.6 KiB
Java
package eu.eudat.model.persist.referencetypedefinition;
|
|
|
|
import eu.eudat.commons.validation.BaseValidator;
|
|
import gr.cite.tools.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 QueryConfigPersist {
|
|
|
|
private String condition;
|
|
public static final String _condition = "condition";
|
|
|
|
private String separator;
|
|
public static final String _separator = "separator";
|
|
|
|
private String value;
|
|
public static final String _value = "value";
|
|
|
|
private Integer ordinal;
|
|
public static final String _ordinal = "ordinal";
|
|
|
|
public String getCondition() {
|
|
return condition;
|
|
}
|
|
|
|
public void setCondition(String condition) {
|
|
this.condition = condition;
|
|
}
|
|
|
|
public String getSeparator() {
|
|
return separator;
|
|
}
|
|
|
|
public void setSeparator(String separator) {
|
|
this.separator = separator;
|
|
}
|
|
|
|
public String getValue() {
|
|
return value;
|
|
}
|
|
|
|
public void setValue(String value) {
|
|
this.value = value;
|
|
}
|
|
|
|
public Integer getOrdinal() {
|
|
return ordinal;
|
|
}
|
|
|
|
public void setOrdinal(Integer ordinal) {
|
|
this.ordinal = ordinal;
|
|
}
|
|
|
|
@Component(QueryConfigPersistValidator.ValidatorName)
|
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
public static class QueryConfigPersistValidator extends BaseValidator<QueryConfigPersist> {
|
|
|
|
public static final String ValidatorName = "QueryConfigPersistValidator";
|
|
private final MessageSource messageSource;
|
|
|
|
protected QueryConfigPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
|
|
super(conventionService, errors);
|
|
this.messageSource = messageSource;
|
|
}
|
|
|
|
@Override
|
|
protected Class<QueryConfigPersist> modelClass() {
|
|
return QueryConfigPersist.class;
|
|
}
|
|
|
|
@Override
|
|
protected List<Specification> specifications(QueryConfigPersist item) {
|
|
return Arrays.asList(
|
|
this.spec()
|
|
.must(() -> !this.isEmpty(item.getCondition()))
|
|
.failOn(QueryConfigPersist._condition).failWith(messageSource.getMessage("Validation_Required", new Object[]{QueryConfigPersist._condition}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.must(() -> !this.isEmpty(item.getSeparator()))
|
|
.failOn(QueryConfigPersist._separator).failWith(messageSource.getMessage("Validation_Required", new Object[]{QueryConfigPersist._separator}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.must(() -> !this.isEmpty(item.getValue()))
|
|
.failOn(QueryConfigPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{QueryConfigPersist._value}, LocaleContextHolder.getLocale())),
|
|
this.spec()
|
|
.must(() -> !this.isNull(item.getOrdinal()))
|
|
.failOn(QueryConfigPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{QueryConfigPersist._ordinal}, LocaleContextHolder.getLocale()))
|
|
);
|
|
}
|
|
}
|
|
|
|
}
|