2023-11-15 16:06:49 +01:00
|
|
|
package eu.eudat.model.persist.descriptionproperties;
|
|
|
|
|
2023-12-21 17:45:49 +01:00
|
|
|
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.context.MessageSource;
|
|
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
|
|
|
import org.springframework.stereotype.Component;
|
2023-11-15 16:06:49 +01:00
|
|
|
|
2023-12-21 17:45:49 +01:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2023-11-15 16:06:49 +01:00
|
|
|
|
|
|
|
public class FieldPersist {
|
|
|
|
|
2023-12-21 17:45:49 +01:00
|
|
|
private String key;
|
2023-11-15 16:06:49 +01:00
|
|
|
|
2023-12-21 17:45:49 +01:00
|
|
|
public static final String _key = "key";
|
2023-11-15 16:06:49 +01:00
|
|
|
|
2023-12-21 17:45:49 +01:00
|
|
|
private String value;
|
2023-11-15 16:06:49 +01:00
|
|
|
|
2023-12-21 17:45:49 +01:00
|
|
|
public static final String _value = "value";
|
2023-11-15 16:06:49 +01:00
|
|
|
|
2023-12-21 17:45:49 +01:00
|
|
|
public String getKey() {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setKey(String key) {
|
|
|
|
this.key = key;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getValue() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setValue(String value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component(FieldPersistValidator.ValidatorName)
|
|
|
|
public static class FieldPersistValidator extends BaseValidator<FieldPersist> {
|
|
|
|
|
|
|
|
public static final String ValidatorName = "Description.FieldPersistValidator";
|
|
|
|
|
|
|
|
private final MessageSource messageSource;
|
|
|
|
|
|
|
|
protected FieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
|
|
|
|
super(conventionService, errors);
|
|
|
|
this.messageSource = messageSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Class<FieldPersist> modelClass() {
|
|
|
|
return FieldPersist.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<Specification> specifications(FieldPersist item) {
|
|
|
|
return Arrays.asList(
|
|
|
|
this.spec()
|
|
|
|
.must(() -> !this.isEmpty(item.getKey()))
|
|
|
|
.failOn(FieldPersist._key).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._key}, LocaleContextHolder.getLocale())),
|
|
|
|
this.spec()
|
|
|
|
.must(() -> !this.isEmpty(item.getValue()))
|
|
|
|
.failOn(FieldPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._value}, LocaleContextHolder.getLocale()))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-11-15 16:06:49 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|