2023-10-30 14:07:59 +01:00
|
|
|
package eu.eudat.model.persist.descriptiontemplatedefinition;
|
|
|
|
|
2023-12-22 18:00:53 +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-22 18:00:53 +01:00
|
|
|
import eu.eudat.convention.ConventionService;
|
|
|
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
|
|
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
2024-02-05 16:59:11 +01:00
|
|
|
import org.springframework.context.MessageSource;
|
2023-12-22 18:00:53 +01:00
|
|
|
import org.springframework.context.annotation.Scope;
|
2024-02-05 16:59:11 +01:00
|
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
2023-12-22 18:00:53 +01:00
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
2024-02-05 16:59:11 +01:00
|
|
|
import java.util.Arrays;
|
2023-12-22 18:00:53 +01:00
|
|
|
import java.util.List;
|
2023-10-30 14:07:59 +01:00
|
|
|
|
2023-11-01 17:12:59 +01:00
|
|
|
public class MultiplicityPersist {
|
2023-10-30 14:07:59 +01:00
|
|
|
|
2023-12-22 18:00:53 +01:00
|
|
|
private Integer min = null;
|
2024-02-05 16:59:11 +01:00
|
|
|
public static final String _min = "min";
|
2023-12-22 18:00:53 +01:00
|
|
|
|
|
|
|
private Integer max = null;
|
2024-02-05 16:59:11 +01:00
|
|
|
public static final String _max = "max";
|
|
|
|
|
2023-12-22 18:00:53 +01:00
|
|
|
|
|
|
|
private String placeholder = null;
|
|
|
|
|
|
|
|
private Boolean tableView = null;
|
|
|
|
|
|
|
|
public Integer getMin() {
|
|
|
|
return min;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMin(Integer min) {
|
|
|
|
this.min = min;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Integer getMax() {
|
|
|
|
return max;
|
|
|
|
}
|
2023-10-30 14:07:59 +01:00
|
|
|
|
2023-12-22 18:00:53 +01:00
|
|
|
public void setMax(Integer max) {
|
|
|
|
this.max = max;
|
|
|
|
}
|
2023-10-30 14:07:59 +01:00
|
|
|
|
2023-12-22 18:00:53 +01:00
|
|
|
public String getPlaceholder() {
|
|
|
|
return placeholder;
|
|
|
|
}
|
2023-10-30 14:07:59 +01:00
|
|
|
|
2023-12-22 18:00:53 +01:00
|
|
|
public void setPlaceholder(String placeholder) {
|
|
|
|
this.placeholder = placeholder;
|
|
|
|
}
|
2023-10-30 14:07:59 +01:00
|
|
|
|
2023-12-22 18:00:53 +01:00
|
|
|
public Boolean getTableView() {
|
|
|
|
return tableView;
|
|
|
|
}
|
2023-10-30 14:07:59 +01:00
|
|
|
|
2023-12-22 18:00:53 +01:00
|
|
|
public void setTableView(Boolean tableView) {
|
|
|
|
this.tableView = tableView;
|
|
|
|
}
|
2023-10-30 14:07:59 +01:00
|
|
|
|
2023-12-22 18:00:53 +01:00
|
|
|
@Component(MultiplicityValidator.ValidatorName)
|
|
|
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
|
|
public static class MultiplicityValidator extends BaseValidator<MultiplicityPersist> {
|
2023-10-30 14:07:59 +01:00
|
|
|
|
2023-12-22 18:00:53 +01:00
|
|
|
public static final String ValidatorName = "DescriptionTemplate.MultiplicityValidator";
|
2023-10-30 14:07:59 +01:00
|
|
|
|
2024-02-05 16:59:11 +01:00
|
|
|
private final MessageSource messageSource;
|
|
|
|
|
|
|
|
protected MultiplicityValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
|
2023-12-22 18:00:53 +01:00
|
|
|
super(conventionService, errors);
|
2024-02-05 16:59:11 +01:00
|
|
|
this.messageSource = messageSource;
|
2023-12-22 18:00:53 +01:00
|
|
|
}
|
2023-10-30 14:07:59 +01:00
|
|
|
|
2023-12-22 18:00:53 +01:00
|
|
|
@Override
|
|
|
|
protected Class<MultiplicityPersist> modelClass() {
|
|
|
|
return MultiplicityPersist.class;
|
|
|
|
}
|
2023-10-30 14:07:59 +01:00
|
|
|
|
2023-12-22 18:00:53 +01:00
|
|
|
@Override
|
|
|
|
protected List<Specification> specifications(MultiplicityPersist item) {
|
2024-02-05 16:59:11 +01:00
|
|
|
return Arrays.asList(
|
|
|
|
this.spec()
|
|
|
|
.iff(() -> !this.isNull(item.getMin()))
|
|
|
|
.must(() -> item.getMin() >= 0)
|
|
|
|
.failOn(MultiplicityPersist._min).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{MultiplicityPersist._min}, LocaleContextHolder.getLocale())),
|
|
|
|
this.spec()
|
|
|
|
.iff(() -> !this.isNull(item.getMax()))
|
|
|
|
.must(() -> item.getMax() >= 0)
|
|
|
|
.failOn(MultiplicityPersist._max).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{MultiplicityPersist._max}, LocaleContextHolder.getLocale())),
|
|
|
|
this.spec()
|
|
|
|
.iff(() -> !this.isNull(item.getMax()))
|
|
|
|
.must(() -> !this.isNull(item.getMin()) && (item.getMax() >= item.getMin()))
|
|
|
|
.failOn(MultiplicityPersist._max).failWith(messageSource.getMessage("Validation.LowerThanMin", new Object[]{MultiplicityPersist._min}, LocaleContextHolder.getLocale()))
|
|
|
|
);
|
2023-12-22 18:00:53 +01:00
|
|
|
}
|
|
|
|
}
|
2023-10-30 14:07:59 +01:00
|
|
|
|
|
|
|
}
|