argos/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/DependencyPropertyPersist.java

89 lines
3.1 KiB
Java

package eu.eudat.model.persist.referencetypedefinition;
import eu.eudat.commons.validation.BaseValidator;
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 DependencyPropertyPersist {
private String code;
public static final String _code = "code";
private String target;
public static final String _target = "target";
private Boolean required;
public static final String _required = "required";
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
public Boolean getRequired() {
return required;
}
public void setRequired(Boolean required) {
this.required = required;
}
@Component(DependencyPropertyPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DependencyPropertyPersistValidator extends BaseValidator<DependencyPropertyPersist> {
public static final String ValidatorName = "DependencyPropertyPersistValidator";
private final MessageSource messageSource;
protected DependencyPropertyPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<DependencyPropertyPersist> modelClass() {
return DependencyPropertyPersist.class;
}
@Override
protected List<Specification> specifications(DependencyPropertyPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getCode()))
.failOn(DependencyPropertyPersist._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{DependencyPropertyPersist._code}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getTarget()))
.failOn(DependencyPropertyPersist._target).failWith(messageSource.getMessage("Validation_Required", new Object[]{DependencyPropertyPersist._target}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getRequired()))
.failOn(DependencyPropertyPersist._required).failWith(messageSource.getMessage("Validation_Required", new Object[]{DependencyPropertyPersist._required}, LocaleContextHolder.getLocale()))
);
}
}
}