2023-10-30 14:07:59 +01:00
|
|
|
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
|
|
|
|
|
2024-01-17 10:20:02 +01:00
|
|
|
import gr.cite.tools.validation.ValidatorFactory;
|
|
|
|
import gr.cite.tools.validation.specification.Specification;
|
2024-01-02 10:50:32 +01:00
|
|
|
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;
|
2023-10-30 14:07:59 +01:00
|
|
|
|
2024-01-02 10:50:32 +01:00
|
|
|
import java.util.Arrays;
|
2023-10-30 14:07:59 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class WordListDataPersist extends BaseFieldDataPersist {
|
2024-01-02 10:50:32 +01:00
|
|
|
|
2023-10-30 14:07:59 +01:00
|
|
|
private List<ComboBoxOptionPersist> options = null;
|
2024-01-02 10:50:32 +01:00
|
|
|
|
|
|
|
public static final String _options = "options";
|
|
|
|
|
2023-10-30 14:07:59 +01:00
|
|
|
private Boolean multiList = null;
|
|
|
|
|
2024-01-02 10:50:32 +01:00
|
|
|
public static final String _multiList = "multiList";
|
|
|
|
|
2023-10-30 14:07:59 +01:00
|
|
|
public List<ComboBoxOptionPersist> getOptions() {
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOptions(List<ComboBoxOptionPersist> options) {
|
|
|
|
this.options = options;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Boolean getMultiList() {
|
|
|
|
return multiList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMultiList(Boolean multiList) {
|
|
|
|
this.multiList = multiList;
|
|
|
|
}
|
2024-01-02 10:50:32 +01:00
|
|
|
|
|
|
|
@Component(WordListDataPersistValidator.ValidatorName)
|
|
|
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
|
|
public static class WordListDataPersistValidator extends BaseFieldDataPersistValidator<WordListDataPersist> {
|
|
|
|
|
|
|
|
public static final String ValidatorName = "DescriptionTemplate.WordListDataPersistValidator";
|
|
|
|
|
|
|
|
private final ValidatorFactory validatorFactory;
|
|
|
|
|
|
|
|
protected WordListDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
|
|
|
|
super(conventionService, errors, messageSource);
|
|
|
|
this.validatorFactory = validatorFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Class<WordListDataPersist> modelClass() {
|
|
|
|
return WordListDataPersist.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<Specification> specifications(WordListDataPersist item) {
|
|
|
|
List<Specification> specifications = getBaseSpecifications(item);
|
|
|
|
specifications.addAll(Arrays.asList(
|
|
|
|
this.spec()
|
|
|
|
.must(() -> !this.isNull(item.getMultiList()))
|
|
|
|
.failOn(WordListDataPersist._multiList).failWith(messageSource.getMessage("Validation_Required", new Object[]{WordListDataPersist._multiList}, LocaleContextHolder.getLocale())),
|
|
|
|
|
|
|
|
this.spec()
|
|
|
|
.must(() -> !this.isNull(item.getOptions()))
|
|
|
|
.failOn(WordListDataPersist._options).failWith(messageSource.getMessage("Validation_Required", new Object[]{WordListDataPersist._options}, LocaleContextHolder.getLocale())),
|
|
|
|
this.navSpec()
|
|
|
|
.iff(() -> !this.isNull(item.getOptions()))
|
|
|
|
.on(WordListDataPersist._options)
|
|
|
|
.over(item.getOptions())
|
|
|
|
.using(() -> this.validatorFactory.validator(ComboBoxOptionPersist.ComboBoxOptionPersistValidator.class))
|
|
|
|
));
|
|
|
|
return specifications;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-30 14:07:59 +01:00
|
|
|
}
|