2024-02-23 13:30:05 +01:00
|
|
|
package eu.eudat.model.persist.externalfetcher;
|
2023-11-15 15:09:24 +01:00
|
|
|
|
2024-01-17 10:20:02 +01:00
|
|
|
import gr.cite.tools.validation.ValidatorFactory;
|
|
|
|
import gr.cite.tools.validation.specification.Specification;
|
2024-01-03 15:45:57 +01:00
|
|
|
import eu.eudat.convention.ConventionService;
|
|
|
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
2024-01-03 17:09:14 +01:00
|
|
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
2024-01-03 15:45:57 +01:00
|
|
|
import org.springframework.context.MessageSource;
|
2024-01-03 17:09:14 +01:00
|
|
|
import org.springframework.context.annotation.Scope;
|
2024-04-09 15:15:15 +02:00
|
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
2024-01-03 17:09:14 +01:00
|
|
|
import org.springframework.stereotype.Component;
|
2023-11-15 15:09:24 +01:00
|
|
|
|
2024-04-09 15:15:15 +02:00
|
|
|
import java.util.Arrays;
|
2023-11-15 15:09:24 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2024-02-23 13:30:05 +01:00
|
|
|
public class ExternalFetcherStaticOptionSourceConfigurationPersist extends ExternalFetcherBaseSourceConfigurationPersist {
|
2023-11-15 15:09:24 +01:00
|
|
|
|
2024-04-09 15:15:15 +02:00
|
|
|
List<StaticPersist> items;
|
2023-11-15 15:09:24 +01:00
|
|
|
|
2024-04-09 15:15:15 +02:00
|
|
|
public static final String _items = "items";
|
2024-01-03 17:09:14 +01:00
|
|
|
|
2024-04-09 15:15:15 +02:00
|
|
|
|
|
|
|
public List<StaticPersist> getItems() {
|
|
|
|
return items;
|
2023-11-15 15:09:24 +01:00
|
|
|
}
|
|
|
|
|
2024-04-09 15:15:15 +02:00
|
|
|
public void setItems(List<StaticPersist> items) {
|
|
|
|
this.items = items;
|
2023-11-15 15:09:24 +01:00
|
|
|
}
|
2024-01-03 15:45:57 +01:00
|
|
|
|
2024-02-26 18:47:20 +01:00
|
|
|
@Component(ExternalFetcherStaticOptionSourceConfigurationPersistValidator.ValidatorName)
|
2024-01-03 17:09:14 +01:00
|
|
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
2024-02-26 18:47:20 +01:00
|
|
|
public static class ExternalFetcherStaticOptionSourceConfigurationPersistValidator extends ExternalFetcherBaseSourceConfigurationPersistValidator<ExternalFetcherStaticOptionSourceConfigurationPersist> {
|
2024-01-03 15:45:57 +01:00
|
|
|
|
2024-02-26 18:47:20 +01:00
|
|
|
public static final String ValidatorName = "ExternalFetcherStaticOptionSourceConfigurationPersistValidator";
|
2024-01-03 17:09:14 +01:00
|
|
|
|
2024-02-26 18:47:20 +01:00
|
|
|
protected ExternalFetcherStaticOptionSourceConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
|
2024-01-03 15:45:57 +01:00
|
|
|
super(conventionService, errors, messageSource, validatorFactory);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-02-23 13:30:05 +01:00
|
|
|
protected Class<ExternalFetcherStaticOptionSourceConfigurationPersist> modelClass() {
|
|
|
|
return ExternalFetcherStaticOptionSourceConfigurationPersist.class;
|
2024-01-03 15:45:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-02-23 13:30:05 +01:00
|
|
|
protected List<Specification> specifications(ExternalFetcherStaticOptionSourceConfigurationPersist item) {
|
2024-01-03 17:09:14 +01:00
|
|
|
List<Specification> specifications = getBaseSpecifications(item);
|
2024-04-09 15:15:15 +02:00
|
|
|
specifications.addAll(Arrays.asList(
|
|
|
|
this.spec()
|
|
|
|
.must(() -> !this.isListNullOrEmpty(item.getItems()))
|
|
|
|
.failOn(ExternalFetcherStaticOptionSourceConfigurationPersist._items).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalFetcherStaticOptionSourceConfigurationPersist._items}, LocaleContextHolder.getLocale())),
|
2024-01-17 17:20:39 +01:00
|
|
|
this.navSpec()
|
2024-04-09 15:15:15 +02:00
|
|
|
.iff(() -> !this.isListNullOrEmpty(item.getItems()))
|
|
|
|
.on(ExternalFetcherStaticOptionSourceConfigurationPersist._items)
|
|
|
|
.over(item.getItems())
|
|
|
|
.using((itm) -> this.validatorFactory.validator(StaticPersist.StaticPersistValidator.class))
|
|
|
|
));
|
2024-01-03 17:09:14 +01:00
|
|
|
return specifications;
|
2024-01-03 15:45:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-15 15:09:24 +01:00
|
|
|
}
|