fix persist validators

This commit is contained in:
amentis 2024-01-17 18:20:39 +02:00
parent d0df9c7e79
commit 3bd60509e7
13 changed files with 38 additions and 41 deletions

View File

@ -10,6 +10,7 @@ import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -84,14 +85,16 @@ public abstract class BaseFieldDataPersist {
}
protected List<Specification> getBaseSpecifications(T item) {
return Arrays.asList(
List<Specification> specifications = new ArrayList<>();
specifications.addAll(Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getLabel()))
.failOn(BaseFieldDataPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{BaseFieldDataPersist._label}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getFieldType()))
.failOn(BaseFieldDataPersist._fieldType).failWith(messageSource.getMessage("Validation_Required", new Object[]{BaseFieldDataPersist._fieldType}, LocaleContextHolder.getLocale()))
);
));
return specifications;
}
}

View File

@ -55,7 +55,7 @@ public class DefinitionPersist {
this.spec()
.must(() -> !this.isNull(item.getSections()))
.failOn(DefinitionPersist._sections).failWith(messageSource.getMessage("Validation_Required", new Object[]{eu.eudat.model.persist.descriptiontemplatedefinition.DefinitionPersist._sections}, LocaleContextHolder.getLocale())),
this.refSpec()
this.navSpec()
.iff(() -> !this.isNull(item.getSections()))
.on(DefinitionPersist._sections)
.over(item.getSections())

View File

@ -10,6 +10,7 @@ import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
@ -117,7 +118,8 @@ public abstract class FieldPersist {
}
protected List<Specification> getBaseSpecifications(T item) {
return Arrays.asList(
List<Specification> specifications = new ArrayList<>();
specifications.addAll( Arrays.asList(
this.spec()
.must(() -> this.isValidGuid(item.getId()))
.failOn(FieldPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._id}, LocaleContextHolder.getLocale())),
@ -136,7 +138,8 @@ public abstract class FieldPersist {
this.spec()
.must(() -> !this.isNull(item.getRequired()))
.failOn(FieldPersist._required).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._required}, LocaleContextHolder.getLocale()))
);
));
return specifications;
}
}

View File

@ -138,23 +138,23 @@ public class SectionPersist {
.failOn(SectionPersist._hasTemplates).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._hasTemplates}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getFields()))
.must(() -> !this.isListNullOrEmpty(item.getFields()))
.failOn(SectionPersist._fields).failWith(messageSource.getMessage("Validation_Required", new Object[]{eu.eudat.model.persist.descriptiontemplatedefinition.SectionPersist._fieldSets}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getFields()))
.iff(() -> !this.isListNullOrEmpty(item.getFields()))
.on(SectionPersist._fields)
.over(item.getFields().stream().filter(x -> x.getCategory() == DmpBlueprintFieldCategory.System).toList())
.using(() -> this.validatorFactory.validator(SystemFieldPersist.SystemFieldPersistValidator.class)),
this.navSpec()
.iff(() -> !this.isNull(item.getFields()))
.iff(() -> !this.isListNullOrEmpty(item.getFields()))
.on(SectionPersist._fields)
.over(item.getFields().stream().filter(x -> x.getCategory() == DmpBlueprintFieldCategory.Extra).toList())
.using(() -> this.validatorFactory.validator(ExtraFieldPersist.ExtraFieldPersistValidator.class)),
this.spec()
.must(() -> !this.isNull(item.getDescriptionTemplates()))
.must(() -> !this.isListNullOrEmpty(item.getDescriptionTemplates()))
.failOn(SectionPersist._descriptionTemplates).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._descriptionTemplates}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getDescriptionTemplates()))
.iff(() -> !this.isListNullOrEmpty(item.getDescriptionTemplates()))
.on(SectionPersist._descriptionTemplates)
.over(item.getDescriptionTemplates())
.using(() -> this.validatorFactory.validator(DescriptionTemplatePersist.DescriptionTemplatePersistValidator.class))

View File

@ -56,11 +56,8 @@ public class DefinitionPersist {
@Override
protected List<Specification> specifications(DefinitionPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getFields()))
.failOn(DefinitionPersist._fields).failWith(messageSource.getMessage("Validation_Required", new Object[]{DefinitionPersist._fields}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getFields()))
.iff(() -> !this.isListNullOrEmpty(item.getFields()))
.on(DefinitionPersist._fields)
.over(item.getFields())
.using(() -> this.validatorFactory.validator(FieldPersist.FieldPersistValidator.class))

View File

@ -65,24 +65,21 @@ public class ReferenceTypeDefinitionPersist {
@Override
protected List<Specification> specifications(ReferenceTypeDefinitionPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getFields()))
.failOn(ReferenceTypeDefinitionPersist._fields).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeDefinitionPersist._fields}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getFields()))
.iff(() -> !this.isListNullOrEmpty(item.getFields()))
.on(ReferenceTypeDefinitionPersist._fields)
.over(item.getFields())
.using(() -> this.validatorFactory.validator(ReferenceTypeFieldPersist.ReferenceTypeFieldPersistValidator.class)),
this.spec()
.must(() -> !this.isNull(item.getSources()))
.must(() -> !this.isListNullOrEmpty(item.getSources()))
.failOn(ReferenceTypeDefinitionPersist._sources).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeDefinitionPersist._sources}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getSources()))
.iff(() -> !this.isListNullOrEmpty(item.getSources()))
.on(ReferenceTypeDefinitionPersist._sources)
.over(item.getSources().stream().filter(x -> x.getType() == ReferenceTypeSourceType.API).toList())
.using(() -> this.validatorFactory.validator(ReferenceTypeSourceExternalApiConfigurationPersist.ReferenceTypeSourceExternalApiConfigurationPersistValidator.class)),
this.navSpec()
.iff(() -> !this.isNull(item.getSources()))
.iff(() -> !this.isListNullOrEmpty(item.getSources()))
.on(ReferenceTypeDefinitionPersist._sources)
.over(item.getSources().stream().filter(x -> x.getType() == ReferenceTypeSourceType.STATIC).toList())
.using(() -> this.validatorFactory.validator(ReferenceTypeSourceStaticOptionConfigurationPersist.ReferenceTypeSourceStaticOptionConfigurationPersistValidator.class))

View File

@ -11,6 +11,7 @@ import gr.cite.tools.validation.specification.Specification;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -98,29 +99,28 @@ public abstract class ReferenceTypeSourceBaseConfigurationPersist {
}
protected List<Specification> getBaseSpecifications(T item) {
return Arrays.asList(
List<Specification> specifications = new ArrayList<>();
specifications.addAll(Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getKey()))
.failOn(ReferenceTypeSourceBaseConfigurationPersist._key).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._label}, LocaleContextHolder.getLocale())),
.failOn(ReferenceTypeSourceBaseConfigurationPersist._key).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._key}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getLabel()))
.failOn(ReferenceTypeSourceBaseConfigurationPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._label}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getOrdinal()))
.failOn(ReferenceTypeSourceBaseConfigurationPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._label}, LocaleContextHolder.getLocale())),
.failOn(ReferenceTypeSourceBaseConfigurationPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._ordinal}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getType()))
.failOn(ReferenceTypeSourceBaseConfigurationPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._label}, LocaleContextHolder.getLocale())),
.failOn(ReferenceTypeSourceBaseConfigurationPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._type}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getDependencies()))
.failOn(ReferenceTypeSourceBaseConfigurationPersist._dependencies).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._dependencies}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getDependencies()))
.iff(() -> !this.isListNullOrEmpty(item.getDependencies()))
.on(ReferenceTypeSourceBaseConfigurationPersist._dependencies)
.over(item.getDependencies())
.using(() -> this.validatorFactory.validator(ReferenceTypeSourceBaseDependencyPersist.ReferenceTypeSourceBaseDependencyPersistValidator.class))
);
));
return specifications;
}
}

View File

@ -99,10 +99,10 @@ public class ReferenceTypeSourceBaseDependencyPersist {
.failOn(ReferenceTypeSourceBaseDependencyPersist._required).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseDependencyPersist._required}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getProperties()))
.must(() -> !this.isListNullOrEmpty(item.getProperties()))
.failOn(ReferenceTypeSourceBaseDependencyPersist._properties).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseDependencyPersist._properties}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getProperties()))
.iff(() -> !this.isListNullOrEmpty(item.getProperties()))
.on(ReferenceTypeSourceBaseDependencyPersist._properties)
.over(item.getProperties())
.using(() -> this.validatorFactory.validator(DependencyPropertyPersist.DependencyPropertyPersistValidator.class))

View File

@ -183,11 +183,8 @@ public class ReferenceTypeSourceExternalApiConfigurationPersist extends Referenc
.on(ReferenceTypeSourceExternalApiConfigurationPersist._auth)
.over(item.getAuth())
.using(() -> this.validatorFactory.validator(AuthenticationConfigurationPersist.AuthenticationConfigurationPersistValidator.class)),
this.spec()
.must(() -> !this.isNull(item.getQueries()))
.failOn(ReferenceTypeSourceExternalApiConfigurationPersist._queries).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceExternalApiConfigurationPersist._queries}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getQueries()))
.iff(() -> !this.isListNullOrEmpty(item.getQueries()))
.on(ReferenceTypeSourceExternalApiConfigurationPersist._queries)
.over(item.getQueries())
.using(() -> this.validatorFactory.validator(QueryConfigPersist.QueryConfigPersistValidator.class))

View File

@ -44,7 +44,7 @@ public class ReferenceTypeSourceStaticOptionConfigurationPersist extends Referen
protected List<Specification> specifications(ReferenceTypeSourceStaticOptionConfigurationPersist item) {
List<Specification> specifications = getBaseSpecifications(item);
specifications.add(
this.refSpec()
this.navSpec()
.iff(() -> !this.isNull(item.getOptions()))
.on(ReferenceTypeSourceStaticOptionConfigurationPersist._options)
.over(item.getOptions())

View File

@ -69,10 +69,10 @@ public class ResultsConfigurationPersist {
.failOn(ResultsConfigurationPersist._resultsArrayPath).failWith(messageSource.getMessage("Validation_Required", new Object[]{ResultsConfigurationPersist._resultsArrayPath}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getFieldsMapping()))
.must(() -> !this.isListNullOrEmpty(item.getFieldsMapping()))
.failOn(ResultsConfigurationPersist._fieldsMapping).failWith(messageSource.getMessage("Validation_Required", new Object[]{ResultsConfigurationPersist._fieldsMapping}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getFieldsMapping()))
.iff(() -> !this.isListNullOrEmpty(item.getFieldsMapping()))
.on(ResultsConfigurationPersist._fieldsMapping)
.over(item.getFieldsMapping())
.using(() -> this.validatorFactory.validator(ResultFieldsMappingConfigurationPersist.ResultFieldsMappingConfigurationPersistValidator.class))

View File

@ -48,7 +48,7 @@ public class TenantDepositConfigPersist {
protected List<Specification> specifications(TenantDepositConfigPersist item) {
return Collections.singletonList(
this.navSpec()
.iff(() -> !this.isNull(item.getSources()))
.iff(() -> !this.isListNullOrEmpty(item.getSources()))
.on(TenantDepositConfigPersist._sources)
.over(item.getSources())
.using(() -> this.validatorFactory.validator(TenantSourcePersist.TenantSourcePersistValidator.class))

View File

@ -48,7 +48,7 @@ public class TenantFileTransformersConfigPersist {
protected List<Specification> specifications(TenantFileTransformersConfigPersist item) {
return Collections.singletonList(
this.navSpec()
.iff(() -> !this.isNull(item.getSources()))
.iff(() -> !this.isListNullOrEmpty(item.getSources()))
.on(TenantFileTransformersConfigPersist._sources)
.over(item.getSources())
.using(() -> this.validatorFactory.validator(TenantSourcePersist.TenantSourcePersistValidator.class))