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;
|
2024-01-17 10:20:02 +01:00
|
|
|
import gr.cite.tools.validation.specification.Specification;
|
2023-12-21 17:45:49 +01:00
|
|
|
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 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 getValue() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setValue(String value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
2024-02-01 15:40:11 +01:00
|
|
|
@Component(PersistValidator.ValidatorName)
|
|
|
|
public static class PersistValidator extends BaseValidator<FieldPersist> {
|
2023-12-21 17:45:49 +01:00
|
|
|
|
|
|
|
public static final String ValidatorName = "Description.FieldPersistValidator";
|
|
|
|
|
|
|
|
private final MessageSource messageSource;
|
|
|
|
|
2024-02-01 15:40:11 +01:00
|
|
|
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
|
2023-12-21 17:45:49 +01:00
|
|
|
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.getValue()))
|
|
|
|
.failOn(FieldPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._value}, LocaleContextHolder.getLocale()))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-11-15 16:06:49 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|