From 3bd60509e7c4fdf1a5fd761759799fa671b31809 Mon Sep 17 00:00:00 2001 From: amentis Date: Wed, 17 Jan 2024 18:20:39 +0200 Subject: [PATCH] fix persist validators --- .../fielddata/BaseFieldDataPersist.java | 7 +++++-- .../DefinitionPersist.java | 2 +- .../dmpblueprintdefinition/FieldPersist.java | 7 +++++-- .../dmpblueprintdefinition/SectionPersist.java | 10 +++++----- .../referencedefinition/DefinitionPersist.java | 5 +---- .../ReferenceTypeDefinitionPersist.java | 11 ++++------- ...enceTypeSourceBaseConfigurationPersist.java | 18 +++++++++--------- ...ferenceTypeSourceBaseDependencyPersist.java | 4 ++-- ...eSourceExternalApiConfigurationPersist.java | 5 +---- ...SourceStaticOptionConfigurationPersist.java | 2 +- .../ResultsConfigurationPersist.java | 4 ++-- .../TenantDepositConfigPersist.java | 2 +- .../TenantFileTransformersConfigPersist.java | 2 +- 13 files changed, 38 insertions(+), 41 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/BaseFieldDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/BaseFieldDataPersist.java index 3aac4c0f1..61ad2b1fe 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/BaseFieldDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/BaseFieldDataPersist.java @@ -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 getBaseSpecifications(T item) { - return Arrays.asList( + List 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; } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/DefinitionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/DefinitionPersist.java index 137d3db5b..af732c798 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/DefinitionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/DefinitionPersist.java @@ -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()) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/FieldPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/FieldPersist.java index 1005801e2..3aeaf1840 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/FieldPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/FieldPersist.java @@ -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 getBaseSpecifications(T item) { - return Arrays.asList( + List 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; } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/SectionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/SectionPersist.java index a042c1fdc..b687d5f5d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/SectionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/SectionPersist.java @@ -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)) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencedefinition/DefinitionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencedefinition/DefinitionPersist.java index 0fed037d2..389f1db63 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencedefinition/DefinitionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencedefinition/DefinitionPersist.java @@ -56,11 +56,8 @@ public class DefinitionPersist { @Override protected List 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)) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeDefinitionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeDefinitionPersist.java index 5fbb67e05..9daea64be 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeDefinitionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeDefinitionPersist.java @@ -65,24 +65,21 @@ public class ReferenceTypeDefinitionPersist { @Override protected List 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)) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseConfigurationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseConfigurationPersist.java index c23d09769..bba124b62 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseConfigurationPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseConfigurationPersist.java @@ -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 getBaseSpecifications(T item) { - return Arrays.asList( + List 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; } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseDependencyPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseDependencyPersist.java index 95738ea92..e90454f36 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseDependencyPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseDependencyPersist.java @@ -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)) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceExternalApiConfigurationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceExternalApiConfigurationPersist.java index 8734cb2e8..a195e8a28 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceExternalApiConfigurationPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceExternalApiConfigurationPersist.java @@ -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)) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceStaticOptionConfigurationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceStaticOptionConfigurationPersist.java index 589bfafdd..163386585 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceStaticOptionConfigurationPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceStaticOptionConfigurationPersist.java @@ -44,7 +44,7 @@ public class ReferenceTypeSourceStaticOptionConfigurationPersist extends Referen protected List specifications(ReferenceTypeSourceStaticOptionConfigurationPersist item) { List specifications = getBaseSpecifications(item); specifications.add( - this.refSpec() + this.navSpec() .iff(() -> !this.isNull(item.getOptions())) .on(ReferenceTypeSourceStaticOptionConfigurationPersist._options) .over(item.getOptions()) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ResultsConfigurationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ResultsConfigurationPersist.java index fb75a191e..36d90990f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ResultsConfigurationPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ResultsConfigurationPersist.java @@ -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)) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/tenantconfig/TenantDepositConfigPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/tenantconfig/TenantDepositConfigPersist.java index 992397775..dcef33f67 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/tenantconfig/TenantDepositConfigPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/tenantconfig/TenantDepositConfigPersist.java @@ -48,7 +48,7 @@ public class TenantDepositConfigPersist { protected List 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)) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/tenantconfig/TenantFileTransformersConfigPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/tenantconfig/TenantFileTransformersConfigPersist.java index 19751a798..e79c11aa8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/tenantconfig/TenantFileTransformersConfigPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/tenantconfig/TenantFileTransformersConfigPersist.java @@ -48,7 +48,7 @@ public class TenantFileTransformersConfigPersist { protected List 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))