diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/validation/BaseValidator.java b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/BaseValidator.java index 829cfdd30..3ae8839fa 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/validation/BaseValidator.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/BaseValidator.java @@ -35,6 +35,14 @@ public abstract class BaseValidator extends AbstractValidator { protected Boolean isEmpty(String value) { return this.conventionService.isNullOrEmpty(value); } + protected Boolean isNull(Object value) { + return value == null; + } + + protected Boolean isNull(Collection value) { + return value == null; + } + protected Boolean lessEqual(String value, int size) { return value.length() <= size; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/ActionConfirmationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/ActionConfirmationPersist.java index b1993da53..08bf4058c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/ActionConfirmationPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/ActionConfirmationPersist.java @@ -2,49 +2,60 @@ package eu.eudat.model.persist; import eu.eudat.commons.enums.ActionConfirmationStatus; import eu.eudat.commons.enums.ActionConfirmationType; -import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; -import eu.eudat.commons.validation.old.ValidEnum; -import eu.eudat.commons.validation.old.ValidId; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.ValidatorFactory; +import eu.eudat.commons.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.model.persist.actionconfirmation.DmpInvitationPersist; import eu.eudat.model.persist.actionconfirmation.EmailConfirmationPersist; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +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; import java.time.Instant; +import java.util.Arrays; +import java.util.List; import java.util.UUID; -@FieldNotNullIfOtherSet(message = "{validation.hashempty}") public class ActionConfirmationPersist { - @ValidId(message = "{validation.invalidid}") + private UUID id; - @ValidEnum(message = "{validation.empty}") private ActionConfirmationType type; - @ValidEnum(message = "{validation.empty}") + private static final String _type = "type"; + private ActionConfirmationStatus status; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") + private static final String _status = "status"; + private String token; - @Valid + private static final String _token = "token"; + private DmpInvitationPersist dmpInvitation; - @Valid + private static final String _dmpInvitation = "dmpInvitation"; + private EmailConfirmationPersist emailConfirmation; - @NotNull(message = "{validation.empty}") - @Valid + private static final String _emailConfirmation = "emailConfirmation"; + private Instant expiresAt; - @NotNull(message = "{validation.empty}") - @Valid + private static final String _expiresAt = "expiresAt"; + private UUID createdById; + private static final String _createdById = "createdById"; + private String hash; + private static final String _hash = "hash"; + public UUID getId() { return id; } @@ -116,6 +127,70 @@ public class ActionConfirmationPersist { public void setHash(String hash) { this.hash = hash; } + + @Component(ActionConfirmationPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class ActionConfirmationPersistValidator extends BaseValidator { + + public static final String ValidatorName = "ActionConfirmationPersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + public ActionConfirmationPersistValidator(MessageSource messageSource, ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return ActionConfirmationPersist.class; + } + + @Override + protected List specifications(ActionConfirmationPersist item) { + return Arrays.asList( + this.spec() + .iff(() -> this.isValidGuid(item.getId())) + .must(() -> this.isValidHash(item.getHash())) + .failOn(ActionConfirmationPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{ActionConfirmationPersist._hash}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isValidGuid(item.getId())) + .must(() -> !this.isValidHash(item.getHash())) + .failOn(ActionConfirmationPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getType())) + .failOn(ActionConfirmationPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ActionConfirmationPersist._type}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getStatus())) + .failOn(ActionConfirmationPersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{ActionConfirmationPersist._status}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getToken())) + .failOn(ActionConfirmationPersist._token).failWith(messageSource.getMessage("Validation_Required", new Object[]{ActionConfirmationPersist._token}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getExpiresAt())) + .failOn(ActionConfirmationPersist._expiresAt).failWith(messageSource.getMessage("Validation_Required", new Object[]{ActionConfirmationPersist._expiresAt}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getCreatedById())) + .failOn(ActionConfirmationPersist._createdById).failWith(messageSource.getMessage("Validation_Required", new Object[]{ActionConfirmationPersist._createdById}, LocaleContextHolder.getLocale())), + + this.refSpec() + .iff(() -> !this.isNull(item.getDmpInvitation())) + .on(ActionConfirmationPersist._dmpInvitation) + .over(item.getDmpInvitation()) + .using(() -> this.validatorFactory.validator(DmpInvitationPersist.DmpInvitationPersistValidator.class)), + this.refSpec() + .iff(() -> !this.isNull(item.getEmailConfirmation())) + .on(ActionConfirmationPersist._emailConfirmation) + .over(item.getEmailConfirmation()) + .using(() -> this.validatorFactory.validator(EmailConfirmationPersist.EmailConfirmationPersistValidator.class)) + ); + } + + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/CloneDmpPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/CloneDmpPersist.java index 3a4c80277..bf097fd00 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/CloneDmpPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/CloneDmpPersist.java @@ -1,30 +1,38 @@ package eu.eudat.model.persist; -import eu.eudat.commons.validation.old.ValidId; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; import org.apache.commons.compress.utils.Lists; +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; +import java.util.Arrays; import java.util.List; import java.util.UUID; public class CloneDmpPersist { - @NotNull(message = "{validation.empty}") - @ValidId(message = "{validation.invalidid}") private UUID id = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") + public static final String _id = "id"; + private String label = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") + public static final String _label = "label"; + private String description = null; - @NotNull(message = "{validation.empty}") + public static final String _description = "description"; + private List descriptions = Lists.newArrayList(); + public static final String _descriptions = "descriptions"; + public UUID getId() { return id; } @@ -56,4 +64,42 @@ public class CloneDmpPersist { public void setDescriptions(List descriptions) { this.descriptions = descriptions; } + + @Component(CloneDmpPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class CloneDmpPersistValidator extends BaseValidator { + + public static final String ValidatorName = "CloneDmpPersistValidator"; + + private final MessageSource messageSource; + + protected CloneDmpPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return CloneDmpPersist.class; + } + + @Override + protected List specifications(CloneDmpPersist item) { + return Arrays.asList( + this.spec() + .must(() -> this.isValidGuid(item.getId())) + .failOn(CloneDmpPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{CloneDmpPersist._id}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> this.isEmpty(item.getLabel())) + .failOn(CloneDmpPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{CloneDmpPersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> this.isEmpty(item.getDescription())) + .failOn(CloneDmpPersist._description).failWith(messageSource.getMessage("Validation_Required", new Object[]{CloneDmpPersist._description}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> this.isNull(item.getDescriptions())) + .failOn(CloneDmpPersist._descriptions).failWith(messageSource.getMessage("Validation_Required", new Object[]{CloneDmpPersist._descriptions}, LocaleContextHolder.getLocale())) + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionPersist.java index 2332c235f..eaab7cb1f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionPersist.java @@ -1,61 +1,68 @@ package eu.eudat.model.persist; import eu.eudat.commons.enums.DescriptionStatus; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.ValidatorFactory; import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; -import eu.eudat.commons.validation.old.ValidEnum; -import eu.eudat.commons.validation.old.ValidId; -import eu.eudat.data.DescriptionEntity; +import eu.eudat.commons.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; +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; +import java.util.Arrays; import java.util.List; import java.util.UUID; @FieldNotNullIfOtherSet(message = "{validation.hashempty}") public class DescriptionPersist { - @ValidId(message = "{validation.invalidid}") private UUID id; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - @Size(max = DescriptionEntity._labelLength, message = "{validation.largerthanmax}") private String label; - @NotNull(message = "{validation.empty}") - @ValidId(message = "{validation.invalidid}") + public static final String _label = "label"; + + public static final int _labelLength = 250; + private UUID dmpId; - @NotNull(message = "{validation.empty}") - @ValidId(message = "{validation.invalidid}") + public static final String _dmpId = "dmpId"; + private UUID dmpDescriptionTemplateId; - @NotNull(message = "{validation.empty}") - @ValidId(message = "{validation.invalidid}") + public static final String _dmpDescriptionTemplateId = "dmpDescriptionTemplateId"; + private UUID descriptionTemplateId; - @ValidEnum(message = "{validation.empty}") + public static final String _descriptionTemplateId = "descriptionTemplateId"; + private DescriptionStatus status; + public static final String _status = "status"; + private String description; - @NotNull(message = "{validation.empty}") - @Valid private PropertyDefinitionPersist properties; - @NotNull(message = "{validation.empty}") - @Valid + public static final String _properties = "properties"; + private List tags; - @NotNull(message = "{validation.empty}") - @Valid + public static final String _tags = "tags"; + private List references; - + + public static final String _references = "references"; + private String hash; + public static final String _hash = "hash"; + public UUID getId() { return id; } @@ -143,4 +150,80 @@ public class DescriptionPersist { public void setDescriptionTemplateId(UUID descriptionTemplateId) { this.descriptionTemplateId = descriptionTemplateId; } + + @Component(DescriptionPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class DescriptionPersistValidator extends BaseValidator { + + public static final String ValidatorName = "DescriptionPersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + protected DescriptionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return DescriptionPersist.class; + } + + @Override + protected List specifications(DescriptionPersist item) { + return Arrays.asList( + this.spec() + .iff(() -> this.isValidGuid(item.getId())) + .must(() -> this.isValidHash(item.getHash())) + .failOn(DescriptionPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._hash}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isValidGuid(item.getId())) + .must(() -> !this.isValidHash(item.getHash())) + .failOn(DescriptionPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getLabel())) + .failOn(DescriptionPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isEmpty(item.getLabel())) + .must(() -> this.lessEqual(item.getLabel(), DescriptionPersist._labelLength)) + .failOn(DescriptionPersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DescriptionPersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> this.isValidGuid(item.getDmpId())) + .failOn(DescriptionPersist._dmpId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._dmpId}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> this.isValidGuid(item.getDescriptionTemplateId())) + .failOn(DescriptionPersist._descriptionTemplateId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._descriptionTemplateId}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> this.isValidGuid(item.getDmpDescriptionTemplateId())) + .failOn(DescriptionPersist._dmpDescriptionTemplateId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._dmpDescriptionTemplateId}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getStatus())) + .failOn(DescriptionPersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._status}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getTags())) + .failOn(DescriptionPersist._tags).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._tags}, LocaleContextHolder.getLocale())), + + this.spec() + .must(() -> !this.isNull(item.getProperties())) + .failOn(DescriptionPersist._properties).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._properties}, LocaleContextHolder.getLocale())), + this.refSpec() + .iff(() -> !this.isNull(item.getProperties())) + .on(DescriptionPersist._properties) + .over(item.getProperties()) + .using(() -> this.validatorFactory.validator(PropertyDefinitionPersist.PropertyDefinitionPersistValidator.class)), + this.spec() + .must(() -> !this.isNull(item.getReferences())) + .failOn(DescriptionPersist._references).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._references}, LocaleContextHolder.getLocale())), + this.navSpec() + .iff(() -> !this.isNull(item.getReferences())) + .on(DescriptionPersist._references) + .over(item.getReferences()) + .using(() -> this.validatorFactory.validator(DescriptionReferencePersist.DescriptionReferencePersistValidator.class)) + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionReferencePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionReferencePersist.java index 59ad3732b..147dc37ef 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionReferencePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionReferencePersist.java @@ -1,24 +1,32 @@ package eu.eudat.model.persist; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.ValidatorFactory; +import eu.eudat.commons.validation.specification.Specification; +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; -import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; -import eu.eudat.commons.validation.old.ValidId; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotNull; - +import java.util.Arrays; +import java.util.List; import java.util.UUID; -@FieldNotNullIfOtherSet(message = "{validation.hashempty}") public class DescriptionReferencePersist { - @ValidId(message = "{validation.invalidid}") + private UUID id; - @NotNull(message = "{validation.empty}") - @Valid private ReferencePersist reference = null; + public static final String _reference = "reference"; + private String hash; + public static final String _hash = "hash"; + public UUID getId() { return id; } @@ -42,6 +50,52 @@ public class DescriptionReferencePersist { public void setHash(String hash) { this.hash = hash; } + + @Component(DescriptionReferencePersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class DescriptionReferencePersistValidator extends BaseValidator { + + public static final String ValidatorName = "DescriptionReferencePersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + protected DescriptionReferencePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return DescriptionReferencePersist.class; + } + + @Override + protected List specifications(DescriptionReferencePersist item) { + return Arrays.asList( + this.spec() + .iff(() -> this.isValidGuid(item.getId())) + .must(() -> this.isValidHash(item.getHash())) + .failOn(DescriptionReferencePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferencePersist._hash}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isValidGuid(item.getId())) + .must(() -> !this.isValidHash(item.getHash())) + .failOn(DescriptionReferencePersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), + + this.spec() + .must(() -> !this.isNull(item.getReference())) + .failOn(DescriptionReferencePersist._reference).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferencePersist._reference}, LocaleContextHolder.getLocale())), + this.refSpec() + .iff(() -> !this.isNull(item.getReference())) + .on(DescriptionReferencePersist._reference) + .over(item.getReference()) + .using(() -> this.validatorFactory.validator(ReferencePersist.ReferencePersistValidator.class)) + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionStatusPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionStatusPersist.java index a9d623447..361918915 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionStatusPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionStatusPersist.java @@ -1,28 +1,34 @@ package eu.eudat.model.persist; import eu.eudat.commons.enums.DescriptionStatus; -import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; -import eu.eudat.commons.validation.old.ValidEnum; -import eu.eudat.commons.validation.old.ValidId; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.specification.Specification; +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; +import java.util.Arrays; +import java.util.List; import java.util.UUID; -@FieldNotNullIfOtherSet(message = "{validation.hashempty}") public class DescriptionStatusPersist { - @NotNull(message = "{validation.empty}") - @ValidId(message = "{validation.invalidid}") private UUID id; - @ValidEnum(message = "{validation.empty}") + public static final String _id = "id"; + private DescriptionStatus status; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") + public static final String _status = "status"; + private String hash; + public static final String _hash = "hash"; + public UUID getId() { return id; } @@ -46,4 +52,40 @@ public class DescriptionStatusPersist { public void setHash(String hash) { this.hash = hash; } + + @Component(DescriptionStatusPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class DescriptionStatusPersistValidator extends BaseValidator { + + public static final String ValidatorName = "DescriptionStatusPersistValidator"; + + private final MessageSource messageSource; + + protected DescriptionStatusPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return DescriptionStatusPersist.class; + } + + @Override + protected List specifications(DescriptionStatusPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isValidGuid(item.getId())) + .failOn(DescriptionStatusPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionStatusPersist._id}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> this.isValidGuid(item.getId())) + .must(() -> this.isValidHash(item.getHash())) + .failOn(DescriptionStatusPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionStatusPersist._hash}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getStatus())) + .failOn(DescriptionStatusPersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionStatusPersist._status}, LocaleContextHolder.getLocale())) + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionTemplatePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionTemplatePersist.java index cde3040b5..2d159f9d1 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionTemplatePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionTemplatePersist.java @@ -1,55 +1,65 @@ package eu.eudat.model.persist; - import eu.eudat.commons.enums.DescriptionTemplateStatus; -import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; -import eu.eudat.commons.validation.old.ValidEnum; -import eu.eudat.commons.validation.old.ValidId; -import eu.eudat.data.DescriptionTemplateEntity; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.ValidatorFactory; +import eu.eudat.commons.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.model.persist.descriptiontemplatedefinition.DefinitionPersist; import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; +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; +import java.util.Arrays; import java.util.List; import java.util.UUID; -@FieldNotNullIfOtherSet(message = "{validation.hashempty}") public class DescriptionTemplatePersist { - @ValidId(message = "{validation.invalidid}") private UUID id; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - @Size(max = DescriptionTemplateEntity._labelLength, message = "{validation.largerthanmax}") private String label = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") + public static final String _label = "label"; + + public static final int _labelLength = 250; + private String description = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") + public static final String _description = "description"; + private String language = null; - @NotNull(message = "{validation.empty}") - @ValidId(message = "{validation.invalidid}") + public static final String _language = "language"; + private UUID type = null; - @ValidEnum(message = "{validation.empty}") + public static final String _type = "type"; + private DescriptionTemplateStatus status; + public static final String _status = "status"; + @NotNull(message = "{validation.empty}") @Valid private DefinitionPersist definition = null; + public static final String _definition = "definition"; + @Valid private List users = null; + public static final String _users = "users"; + private String hash; + public static final String _hash = "hash"; + public UUID getId() { return id; } @@ -121,6 +131,79 @@ public class DescriptionTemplatePersist { public void setUsers(List users) { this.users = users; } + + @Component(DescriptionTemplatePersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class DescriptionTemplatePersistValidator extends BaseValidator { + + public static final String ValidatorName = "DescriptionTemplatePersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + protected DescriptionTemplatePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return DescriptionTemplatePersist.class; + } + + @Override + protected List specifications(DescriptionTemplatePersist item) { + return Arrays.asList( + this.spec() + .iff(() -> this.isValidGuid(item.getId())) + .must(() -> this.isValidHash(item.getHash())) + .failOn(DescriptionTemplatePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._hash}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isValidGuid(item.getId())) + .must(() -> !this.isValidHash(item.getHash())) + .failOn(DescriptionTemplatePersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getLabel())) + .failOn(DescriptionTemplatePersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isEmpty(item.getLabel())) + .must(() -> this.lessEqual(item.getLabel(), DescriptionTemplatePersist._labelLength)) + .failOn(DescriptionTemplatePersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DescriptionTemplatePersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getDescription())) + .failOn(DescriptionTemplatePersist._description).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._description}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getLanguage())) + .failOn(DescriptionTemplatePersist._language).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._language}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> this.isValidGuid(item.getType())) + .failOn(DescriptionTemplatePersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._type}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getStatus())) + .failOn(DescriptionTemplatePersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._status}, LocaleContextHolder.getLocale())), + + this.spec() + .must(() -> !this.isNull(item.getDefinition())) + .failOn(DescriptionTemplatePersist._definition).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._definition}, LocaleContextHolder.getLocale())), + this.refSpec() + .iff(() -> !this.isNull(item.getDefinition())) + .on(DescriptionTemplatePersist._definition) + .over(item.getDefinition()) + .using(() -> this.validatorFactory.validator(DefinitionPersist.DefinitionPersistValidator.class)), + this.spec() + .must(() -> !this.isNull(item.getUsers())) + .failOn(DescriptionTemplatePersist._users).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._users}, LocaleContextHolder.getLocale())), + this.navSpec() + .iff(() -> !this.isNull(item.getUsers())) + .on(DescriptionTemplatePersist._users) + .over(item.getUsers()) + .using(() -> null) //TODO (thgiannos) + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/ReferencePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/ReferencePersist.java index 694216cc5..9635ea972 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/ReferencePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/ReferencePersist.java @@ -1,53 +1,74 @@ package eu.eudat.model.persist; -import eu.eudat.commons.enums.ReferenceType; import eu.eudat.commons.enums.ReferenceSourceType; -import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; +import eu.eudat.commons.enums.ReferenceType; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.ValidatorFactory; import eu.eudat.commons.validation.old.ValidEnum; -import eu.eudat.commons.validation.old.ValidId; +import eu.eudat.commons.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.model.persist.referencedefinition.DefinitionPersist; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; +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; +import java.util.Arrays; +import java.util.List; import java.util.UUID; -@FieldNotNullIfOtherSet(message = "{validation.hashempty}") public class ReferencePersist { - @ValidId(message = "{validation.invalidid}") private UUID id; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - @Size(max = 250, message = "{validation.largerthanmax}") private String label; - @ValidEnum(message = "{validation.empty}") + public static final String _label = "label"; + + public static final int _labelLength = 250; + private ReferenceType type; + public static final String _type = "type"; + private String description; - @Valid private DefinitionPersist definition; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - @Size(max = 1024, message = "{validation.largerthanmax}") + public static final String _definition = "definition"; + private String reference; + public static final String _reference = "reference"; + + public static final int _referenceLength = 1024; + @Size(max = 50, message = "{validation.largerthanmax}") private String abbreviation; + public static final String _abbreviation = "abbreviation"; + + public static final int _abbreviationLength = 50; + @Size(max = 1024, message = "{validation.largerthanmax}") private String source; + public static final String _source = "source"; + + public static final int _sourceLength = 1024; + @ValidEnum(message = "{validation.empty}") private ReferenceSourceType sourceType; + public static final String _sourceType = "sourceType"; + private String hash; + public static final String _hash = "hash"; + public UUID getId() { return id; } @@ -127,4 +148,84 @@ public class ReferencePersist { public void setHash(String hash) { this.hash = hash; } + + @Component(ReferencePersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class ReferencePersistValidator extends BaseValidator { + + public static final String ValidatorName = "ReferencePersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + protected ReferencePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return ReferencePersist.class; + } + + @Override + protected List specifications(ReferencePersist item) { + return Arrays.asList( + this.spec() + .iff(() -> this.isValidGuid(item.getId())) + .must(() -> this.isValidHash(item.getHash())) + .failOn(ReferencePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._hash}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isValidGuid(item.getId())) + .must(() -> !this.isValidHash(item.getHash())) + .failOn(ReferencePersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getLabel())) + .failOn(ReferencePersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isEmpty(item.getLabel())) + .must(() -> this.lessEqual(item.getLabel(), ReferencePersist._labelLength)) + .failOn(ReferencePersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getType())) + .failOn(ReferencePersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._type}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getReference())) + .failOn(ReferencePersist._reference).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._reference}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isEmpty(item.getReference())) + .must(() -> this.lessEqual(item.getReference(), ReferencePersist._referenceLength)) + .failOn(ReferencePersist._reference).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._reference}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getAbbreviation())) + .failOn(ReferencePersist._abbreviation).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._abbreviation}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isEmpty(item.getAbbreviation())) + .must(() -> this.lessEqual(item.getAbbreviation(), ReferencePersist._abbreviationLength)) + .failOn(ReferencePersist._abbreviation).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._abbreviation}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getSource())) + .failOn(ReferencePersist._source).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._source}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isEmpty(item.getSource())) + .must(() -> this.lessEqual(item.getSource(), ReferencePersist._sourceLength)) + .failOn(ReferencePersist._source).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._source}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getSourceType())) + .failOn(ReferencePersist._sourceType).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._sourceType}, LocaleContextHolder.getLocale())), + + this.spec() + .must(() -> !this.isNull(item.getDefinition())) + .failOn(ReferencePersist._definition).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._definition}, LocaleContextHolder.getLocale())), + this.refSpec() + .iff(() -> !this.isNull(item.getDefinition())) + .on(ReferencePersist._definition) + .over(item.getDefinition()) + .using(() -> this.validatorFactory.validator(DefinitionPersist.DefinitionPersistValidator.class)) + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/actionconfirmation/DmpInvitationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/actionconfirmation/DmpInvitationPersist.java index 4d1ef7688..ae03465f3 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/actionconfirmation/DmpInvitationPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/actionconfirmation/DmpInvitationPersist.java @@ -1,53 +1,96 @@ package eu.eudat.model.persist.actionconfirmation; import eu.eudat.commons.enums.DmpUserRole; -import eu.eudat.commons.validation.old.ValidEnum; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.specification.Specification; +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; +import java.util.Arrays; +import java.util.List; import java.util.UUID; public class DmpInvitationPersist { - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String email; + private String email; - @NotNull(message = "{validation.empty}") - @Valid - private UUID dmpId; + public static final String _email = "email"; - @ValidEnum(message = "{validation.empty}") - private DmpUserRole role; + private UUID dmpId; - public DmpInvitationPersist(String email, UUID dmpId, DmpUserRole role) { - this.email = email; - this.dmpId = dmpId; - this.role = role; - } + public static final String _dmpId = "dmpId"; - public String getEmail() { - return email; - } + private DmpUserRole role; - public void setEmail(String email) { - this.email = email; - } + public static final String _role = "role"; - public UUID getDmpId() { - return dmpId; - } + public DmpInvitationPersist(String email, UUID dmpId, DmpUserRole role) { + this.email = email; + this.dmpId = dmpId; + this.role = role; + } - public void setDmpId(UUID dmpId) { - this.dmpId = dmpId; - } + public String getEmail() { + return email; + } - public DmpUserRole getRole() { - return role; - } + public void setEmail(String email) { + this.email = email; + } + + public UUID getDmpId() { + return dmpId; + } + + public void setDmpId(UUID dmpId) { + this.dmpId = dmpId; + } + + public DmpUserRole getRole() { + return role; + } + + public void setRole(DmpUserRole role) { + this.role = role; + } + + @Component(DmpInvitationPersistValidator.ValidatorName) + @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class DmpInvitationPersistValidator extends BaseValidator { + + public static final String ValidatorName = "DmpInvitationPersistValidator"; + + private final MessageSource messageSource; + + protected DmpInvitationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return DmpInvitationPersist.class; + } + + @Override + protected List specifications(DmpInvitationPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isEmpty(item.getEmail())) + .failOn(DmpInvitationPersist._email).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpInvitationPersist._email}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getDmpId())) + .failOn(DmpInvitationPersist._dmpId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpInvitationPersist._dmpId}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getRole())) + .failOn(DmpInvitationPersist._role).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpInvitationPersist._role}, LocaleContextHolder.getLocale())) + ); + } + } - public void setRole(DmpUserRole role) { - this.role = role; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/actionconfirmation/EmailConfirmationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/actionconfirmation/EmailConfirmationPersist.java index 948ddc6eb..302d5d256 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/actionconfirmation/EmailConfirmationPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/actionconfirmation/EmailConfirmationPersist.java @@ -1,16 +1,23 @@ package eu.eudat.model.persist.actionconfirmation; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.specification.Specification; +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; + +import java.util.Collections; +import java.util.List; public class EmailConfirmationPersist { - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") private String email; - public EmailConfirmationPersist() { - } + public static final String _email = "email"; public EmailConfirmationPersist(String email) { this.email = email; @@ -23,4 +30,33 @@ public class EmailConfirmationPersist { public void setEmail(String email) { this.email = email; } + + @Component(EmailConfirmationPersistValidator.ValidatorName) + @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class EmailConfirmationPersistValidator extends BaseValidator { + + public static final String ValidatorName = "EmailConfirmationPersistValidator"; + + private final MessageSource messageSource; + + protected EmailConfirmationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return EmailConfirmationPersist.class; + } + + @Override + protected List specifications(EmailConfirmationPersist item) { + return Collections.singletonList( + this.spec() + .must(() -> !this.isEmpty(item.getEmail())) + .failOn(EmailConfirmationPersist._email).failWith(messageSource.getMessage("Validation_Required", new Object[]{EmailConfirmationPersist._email}, LocaleContextHolder.getLocale())) + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/FieldPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/FieldPersist.java index d7dd2bf6b..6cc55c753 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/FieldPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/FieldPersist.java @@ -1,34 +1,72 @@ package eu.eudat.model.persist.descriptionproperties; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; +import org.springframework.context.MessageSource; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.stereotype.Component; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +import java.util.Arrays; +import java.util.List; public class FieldPersist { - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String key; + private String key; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String value; + public static final String _key = "key"; - public String getKey() { - return key; - } + private String value; - public void setKey(String key) { - this.key = key; - } + public static final String _value = "value"; - public String getValue() { - return value; - } + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @Component(FieldPersistValidator.ValidatorName) + public static class FieldPersistValidator extends BaseValidator { + + public static final String ValidatorName = "Description.FieldPersistValidator"; + + private final MessageSource messageSource; + + protected FieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return FieldPersist.class; + } + + @Override + protected List specifications(FieldPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isEmpty(item.getKey())) + .failOn(FieldPersist._key).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._key}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getValue())) + .failOn(FieldPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._value}, LocaleContextHolder.getLocale())) + ); + } + } - public void setValue(String value) { - this.value = value; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionPersist.java index bbf9d6c60..90f8664f2 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionPersist.java @@ -1,21 +1,67 @@ package eu.eudat.model.persist.descriptionproperties; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.ValidatorFactory; +import eu.eudat.commons.validation.specification.Specification; +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; +import java.util.Arrays; import java.util.List; public class PropertyDefinitionPersist { - @NotNull(message = "{validation.empty}") - @Valid - private List fields; + private List fields; - public List getFields() { - return fields; - } + public static final String _fields = "fields"; + + public List getFields() { + return fields; + } + + public void setFields(List fields) { + this.fields = fields; + } + + @Component(PropertyDefinitionPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class PropertyDefinitionPersistValidator extends BaseValidator { + + public static final String ValidatorName = "Description.PropertyDefinitionPersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + protected PropertyDefinitionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return PropertyDefinitionPersist.class; + } + + @Override + protected List specifications(PropertyDefinitionPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isNull(item.getFields())) + .failOn(PropertyDefinitionPersist._fields).failWith(messageSource.getMessage("Validation_Required", new Object[]{PropertyDefinitionPersist._fields}, LocaleContextHolder.getLocale())), + this.navSpec() + .iff(() -> !this.isNull(item.getFields())) + .on(PropertyDefinitionPersist._fields) + .over(item.getFields()) + .using(() -> this.validatorFactory.validator(FieldPersist.FieldPersistValidator.class)) + ); + } + } - public void setFields(List fields) { - this.fields = fields; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/DefinitionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/DefinitionPersist.java index b1fb3aa68..d9896f9c7 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/DefinitionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/DefinitionPersist.java @@ -1,33 +1,87 @@ package eu.eudat.model.persist.descriptiontemplatedefinition; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.ValidatorFactory; +import eu.eudat.commons.validation.specification.Specification; +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; +import java.util.Arrays; import java.util.List; public class DefinitionPersist { - @NotNull(message = "{validation.empty}") - @Valid - private List sections = null; + private List sections = null; - @NotNull(message = "{validation.empty}") - @Valid - private List pages = null; + public static final String _sections = "sections"; - public List getSections() { - return sections; - } + private List pages = null; - public void setSections(List sections) { - this.sections = sections; - } + public static final String _pages = "pages"; - public List getPages() { - return pages; - } + public List getSections() { + return sections; + } + + public void setSections(List sections) { + this.sections = sections; + } + + public List getPages() { + return pages; + } + + public void setPages(List pages) { + this.pages = pages; + } + + @Component(DefinitionPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class DefinitionPersistValidator extends BaseValidator { + + public static final String ValidatorName = "DescriptionTemplate.DefinitionPersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + public DefinitionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return DefinitionPersist.class; + } + + @Override + protected List specifications(DefinitionPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isNull(item.getSections())) + .failOn(DefinitionPersist._sections).failWith(messageSource.getMessage("Validation_Required", new Object[]{DefinitionPersist._sections}, LocaleContextHolder.getLocale())), + this.refSpec() + .iff(() -> !this.isNull(item.getSections())) + .on(DefinitionPersist._sections) + .over(item.getSections()) + .using(() -> this.validatorFactory.validator(SectionPersist.SectionPersistValidator.class)), + this.spec() + .must(() -> !this.isNull(item.getPages())) + .failOn(DefinitionPersist._pages).failWith(messageSource.getMessage("Validation_Required", new Object[]{DefinitionPersist._pages}, LocaleContextHolder.getLocale())), + this.refSpec() + .iff(() -> !this.isNull(item.getPages())) + .on(DefinitionPersist._pages) + .over(item.getPages()) + .using(() -> this.validatorFactory.validator(PagePersist.PagePersistValidator.class)) + ); + } + } - public void setPages(List pages) { - this.pages = pages; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/FieldPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/FieldPersist.java index be84fb58c..bf8fdaef1 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/FieldPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/FieldPersist.java @@ -1,99 +1,215 @@ package eu.eudat.model.persist.descriptiontemplatedefinition; +import eu.eudat.commons.enums.FieldType; import eu.eudat.commons.enums.FieldValidationType; -import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.BaseFieldDataPersist; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.ValidatorFactory; +import eu.eudat.commons.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; +import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.*; +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; +import java.util.Arrays; import java.util.List; public class FieldPersist { - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String id = null; + private String id = null; - @NotNull(message = "{validation.empty}") - private Integer ordinal = null; + public static final String _id = "id"; - private List schematics; + private Integer ordinal = null; - private String defaultValue; + public static final String _ordinal = "ordinal"; - @Valid - private List visibilityRules; + private List schematics; - private List validations; + private String defaultValue; - @NotNull(message = "{validation.empty}") - private Boolean includeInExport = null; + private List visibilityRules; - @NotNull(message = "{validation.empty}") - @Valid - private BaseFieldDataPersist data = null; + public static final String _visibilityRules = "visibilityRules"; - public String getId() { - return id; - } + private List validations; - public void setId(String id) { - this.id = id; - } + private Boolean includeInExport = null; - public Integer getOrdinal() { - return ordinal; - } + public static final String _includeInExport = "includeInExport"; - public void setOrdinal(Integer ordinal) { - this.ordinal = ordinal; - } + private BaseFieldDataPersist data = null; - public List getSchematics() { - return schematics; - } + public static final String _data = "data"; - public void setSchematics(List schematics) { - this.schematics = schematics; - } + public String getId() { + return id; + } - public String getDefaultValue() { - return defaultValue; - } + public void setId(String id) { + this.id = id; + } - public void setDefaultValue(String defaultValue) { - this.defaultValue = defaultValue; - } + public Integer getOrdinal() { + return ordinal; + } - public List getVisibilityRules() { - return visibilityRules; - } + public void setOrdinal(Integer ordinal) { + this.ordinal = ordinal; + } - public void setVisibilityRules(List visibilityRules) { - this.visibilityRules = visibilityRules; - } + public List getSchematics() { + return schematics; + } - public List getValidations() { - return validations; - } + public void setSchematics(List schematics) { + this.schematics = schematics; + } - public void setValidations(List validations) { - this.validations = validations; - } + public String getDefaultValue() { + return defaultValue; + } - public Boolean getIncludeInExport() { - return includeInExport; - } + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } - public void setIncludeInExport(Boolean includeInExport) { - this.includeInExport = includeInExport; - } + public List getVisibilityRules() { + return visibilityRules; + } - public BaseFieldDataPersist getData() { - return data; - } + public void setVisibilityRules(List visibilityRules) { + this.visibilityRules = visibilityRules; + } + + public List getValidations() { + return validations; + } + + public void setValidations(List validations) { + this.validations = validations; + } + + public Boolean getIncludeInExport() { + return includeInExport; + } + + public void setIncludeInExport(Boolean includeInExport) { + this.includeInExport = includeInExport; + } + + public BaseFieldDataPersist getData() { + return data; + } + + public void setData(BaseFieldDataPersist data) { + this.data = data; + } + + @Component(FieldPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class FieldPersistValidator extends BaseValidator { + + public static final String ValidatorName = "DescriptionTemplate.FieldPersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + protected FieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return FieldPersist.class; + } + + @Override + protected List specifications(FieldPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isEmpty(item.getId())) + .failOn(FieldPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._id}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getOrdinal())) + .failOn(FieldPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._ordinal}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getIncludeInExport())) + .failOn(FieldPersist._includeInExport).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._includeInExport}, LocaleContextHolder.getLocale())), + + this.navSpec() + .iff(() -> !this.isNull(item.getVisibilityRules())) + .on(FieldPersist._visibilityRules) + .over(item.getVisibilityRules()) + .using(() -> this.validatorFactory.validator(RulePersist.RulePersistValidator.class)), + this.refSpec() + .iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.AUTO_COMPLETE) + .on(FieldPersist._data) + .over(item.getData()) + .using(() -> this.validatorFactory.validator(AutoCompleteDataPersist.AutoCompleteDataPersistValidator.class)), + this.refSpec() + .iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.BOOLEAN_DECISION) + .on(FieldPersist._data) + .over(item.getData()) + .using(() -> this.validatorFactory.validator(BooleanDecisionDataPersist.BooleanDecisionPersistValidator.class)), + this.refSpec() + .iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.INTERNAL_DMP_ENTRIES_DATASETS) + .on(FieldPersist._data) + .over(item.getData()) + .using(() -> this.validatorFactory.validator(DatasetAutoCompleteDataPersist.DatasetAutoCompleteDataPersistValidator.class)), + this.refSpec() + .iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.INTERNAL_DMP_ENTRIES_DMPS) + .on(FieldPersist._data) + .over(item.getData()) + .using(() -> this.validatorFactory.validator(DmpAutoCompleteDataPersist.DmpAutoCompleteDataPersistValidator.class)), + this.refSpec() + .iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.CHECK_BOX) + .on(FieldPersist._data) + .over(item.getData()) + .using(() -> this.validatorFactory.validator(CheckBoxDataPersist.CheckBoxDataPersistValidator.class)), + this.refSpec() + .iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.DATE_PICKER) + .on(FieldPersist._data) + .over(item.getData()) + .using(() -> this.validatorFactory.validator(DatePickerDataPersist.DatePickerDataPersistValidator.class)), + this.refSpec() + .iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.EXTERNAL_DATASETS) + .on(FieldPersist._data) + .over(item.getData()) + .using(() -> this.validatorFactory.validator(ExternalDatasetDataPersist.ExternalDatasetDataPersistValidator.class)), + this.refSpec() + .iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.FREE_TEXT) + .on(FieldPersist._data) + .over(item.getData()) + .using(() -> this.validatorFactory.validator(FreeTextDataPersist.FreeTextDataPersistValidator.class)), + this.refSpec() + .iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.LICENSES) + .on(FieldPersist._data) + .over(item.getData()) + .using(() -> this.validatorFactory.validator(LicenseDataPersist.LicenseDataPersistValidator.class)), + this.refSpec() + .iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.ORGANIZATIONS) + .on(FieldPersist._data) + .over(item.getData()) + .using(() -> this.validatorFactory.validator(OrganizationDataPersist.OrganizationDataPersistValidator.class)), + this.refSpec() + .iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.PUBLICATIONS) + .on(FieldPersist._data) + .over(item.getData()) + .using(() -> this.validatorFactory.validator(PublicationDataPersist.PublicationDataPersistValidator.class)), + this.refSpec() + .iff(() -> !this.isNull(item.getData()) && item.getData().getFieldType() == FieldType.RADIO_BOX) + .on(FieldPersist._data) + .over(item.getData()) + .using(() -> this.validatorFactory.validator(RadioBoxDataPersist.RadioBoxDataPersistValidator.class)) + ); + } + } - public void setData(BaseFieldDataPersist data) { - this.data = data; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/FieldSetPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/FieldSetPersist.java index 1cf21610d..fedd67717 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/FieldSetPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/FieldSetPersist.java @@ -1,127 +1,187 @@ package eu.eudat.model.persist.descriptiontemplatedefinition; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.ValidatorFactory; +import eu.eudat.commons.validation.specification.Specification; +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; +import java.util.Arrays; import java.util.List; public class FieldSetPersist { - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String id = null; + private String id = null; - @NotNull(message = "{validation.empty}") - private Integer ordinal = null; + public static final String _id = "id"; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String numbering = null; + private Integer ordinal = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String title = null; + public static final String _ordinal = "ordinal"; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String description = null; + private String numbering = null; -// @NotNull(message = "{validation.empty}") -// @NotEmpty(message = "{validation.empty}") - private String extendedDescription = null; - -// @NotNull(message = "{validation.empty}") -// @NotEmpty(message = "{validation.empty}") - private String additionalInformation = null; + public static final String _numbering = "numbering"; - @Valid - private MultiplicityPersist multiplicity= null; + private String title = null; + public static final String _title = "title"; - private Boolean hasCommentField = null; + private String description = null; - @NotNull(message = "{validation.empty}") - @Valid - private List fields = null; + public static final String _description = "description"; - public String getId() { - return id; - } + private String extendedDescription = null; - public void setId(String id) { - this.id = id; - } + private String additionalInformation = null; - public Integer getOrdinal() { - return ordinal; - } + private MultiplicityPersist multiplicity = null; - public void setOrdinal(Integer ordinal) { - this.ordinal = ordinal; - } + public static final String _multiplicity = "multiplicity"; - public String getNumbering() { - return numbering; - } + private Boolean hasCommentField = null; - public void setNumbering(String numbering) { - this.numbering = numbering; - } + private List fields = null; - public String getTitle() { - return title; - } + public static final String _fields = "fields"; - public void setTitle(String title) { - this.title = title; - } + public String getId() { + return id; + } - public String getDescription() { - return description; - } + public void setId(String id) { + this.id = id; + } - public void setDescription(String description) { - this.description = description; - } + public Integer getOrdinal() { + return ordinal; + } - public String getExtendedDescription() { - return extendedDescription; - } + public void setOrdinal(Integer ordinal) { + this.ordinal = ordinal; + } - public void setExtendedDescription(String extendedDescription) { - this.extendedDescription = extendedDescription; - } + public String getNumbering() { + return numbering; + } - public String getAdditionalInformation() { - return additionalInformation; - } + public void setNumbering(String numbering) { + this.numbering = numbering; + } - public void setAdditionalInformation(String additionalInformation) { - this.additionalInformation = additionalInformation; - } + public String getTitle() { + return title; + } - public MultiplicityPersist getMultiplicity() { - return multiplicity; - } + public void setTitle(String title) { + this.title = title; + } - public void setMultiplicity(MultiplicityPersist multiplicity) { - this.multiplicity = multiplicity; - } + public String getDescription() { + return description; + } - public Boolean getHasCommentField() { - return hasCommentField; - } + public void setDescription(String description) { + this.description = description; + } - public void setHasCommentField(Boolean hasCommentField) { - this.hasCommentField = hasCommentField; - } + public String getExtendedDescription() { + return extendedDescription; + } - public List getFields() { - return fields; - } + public void setExtendedDescription(String extendedDescription) { + this.extendedDescription = extendedDescription; + } + + public String getAdditionalInformation() { + return additionalInformation; + } + + public void setAdditionalInformation(String additionalInformation) { + this.additionalInformation = additionalInformation; + } + + public MultiplicityPersist getMultiplicity() { + return multiplicity; + } + + public void setMultiplicity(MultiplicityPersist multiplicity) { + this.multiplicity = multiplicity; + } + + public Boolean getHasCommentField() { + return hasCommentField; + } + + public void setHasCommentField(Boolean hasCommentField) { + this.hasCommentField = hasCommentField; + } + + public List getFields() { + return fields; + } + + public void setFields(List fields) { + this.fields = fields; + } + + @Component(FieldSetPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class FieldSetPersistValidator extends BaseValidator { + + public static final String ValidatorName = "DescriptionTemplate.FieldSetPersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + protected FieldSetPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return FieldSetPersist.class; + } + + @Override + protected List specifications(FieldSetPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isEmpty(item.getId())) + .failOn(FieldSetPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._id}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getOrdinal())) + .failOn(FieldSetPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._ordinal}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getNumbering())) + .failOn(FieldSetPersist._numbering).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._numbering}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getTitle())) + .failOn(FieldSetPersist._title).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._title}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getDescription())) + .failOn(FieldSetPersist._description).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._description}, LocaleContextHolder.getLocale())), + + this.refSpec() + .iff(() -> !this.isNull(item.getMultiplicity())) + .on(FieldSetPersist._multiplicity) + .over(item.getMultiplicity()) + .using(() -> this.validatorFactory.validator(MultiplicityPersist.MultiplicityValidator.class)), + this.navSpec() + .iff(() -> !this.isNull(item.getFields())) + .on(FieldSetPersist._fields) + .over(item.getFields()) + .using(() -> this.validatorFactory.validator(FieldPersist.FieldPersistValidator.class)) + ); + } + } - public void setFields(List fields) { - this.fields = fields; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/MultiplicityPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/MultiplicityPersist.java index d68fe2170..ac6b63ca3 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/MultiplicityPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/MultiplicityPersist.java @@ -1,47 +1,77 @@ package eu.eudat.model.persist.descriptiontemplatedefinition; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; +import org.apache.commons.compress.utils.Lists; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.List; public class MultiplicityPersist { - private Integer min = null; + private Integer min = null; - private Integer max = null; + private Integer max = null; - private String placeholder = null; + private String placeholder = null; - private Boolean tableView = null; + private Boolean tableView = null; - public Integer getMin() { - return min; - } + public Integer getMin() { + return min; + } - public void setMin(Integer min) { - this.min = min; - } + public void setMin(Integer min) { + this.min = min; + } - public Integer getMax() { - return max; - } + public Integer getMax() { + return max; + } - public void setMax(Integer max) { - this.max = max; - } + public void setMax(Integer max) { + this.max = max; + } - public String getPlaceholder() { - return placeholder; - } + public String getPlaceholder() { + return placeholder; + } - public void setPlaceholder(String placeholder) { - this.placeholder = placeholder; - } + public void setPlaceholder(String placeholder) { + this.placeholder = placeholder; + } - public Boolean getTableView() { - return tableView; - } + public Boolean getTableView() { + return tableView; + } + + public void setTableView(Boolean tableView) { + this.tableView = tableView; + } + + @Component(MultiplicityValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class MultiplicityValidator extends BaseValidator { + + public static final String ValidatorName = "DescriptionTemplate.MultiplicityValidator"; + + protected MultiplicityValidator(ConventionService conventionService, ErrorThesaurusProperties errors) { + super(conventionService, errors); + } + + @Override + protected Class modelClass() { + return MultiplicityPersist.class; + } + + @Override + protected List specifications(MultiplicityPersist item) { + return Lists.newArrayList(); + } + } - public void setTableView(Boolean tableView) { - this.tableView = tableView; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/PagePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/PagePersist.java index a7e14e565..802395039 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/PagePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/PagePersist.java @@ -1,44 +1,90 @@ package eu.eudat.model.persist.descriptiontemplatedefinition; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.specification.Specification; +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; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +import java.util.Arrays; +import java.util.List; public class PagePersist { - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String id = null; - @NotNull(message = "{validation.empty}") - private Integer ordinal = null; + private String id = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String title = null; + public static final String _id = "id"; - public String getId() { - return id; - } + private Integer ordinal = null; - public void setId(String id) { - this.id = id; - } + public static final String _ordinal = "ordinal"; - public int getOrdinal() { - return ordinal; - } + private String title = null; - public void setOrdinal(int ordinal) { - this.ordinal = ordinal; - } + public static final String _title = "title"; - public String getTitle() { - return title; - } + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public int getOrdinal() { + return ordinal; + } + + public void setOrdinal(int ordinal) { + this.ordinal = ordinal; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + @Component(PagePersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class PagePersistValidator extends BaseValidator { + + public static final String ValidatorName = "DescriptionTemplate.PagePersistValidator"; + + private final MessageSource messageSource; + + protected PagePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return PagePersist.class; + } + + @Override + protected List specifications(PagePersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isEmpty(item.getId())) + .failOn(PagePersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{PagePersist._id}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getOrdinal())) + .failOn(PagePersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{PagePersist._ordinal}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getTitle())) + .failOn(PagePersist._title).failWith(messageSource.getMessage("Validation_Required", new Object[]{PagePersist._title}, LocaleContextHolder.getLocale())) + ); + } + } - public void setTitle(String title) { - this.title = title; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/RulePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/RulePersist.java index 127786f65..a9738f83c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/RulePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/RulePersist.java @@ -1,33 +1,73 @@ package eu.eudat.model.persist.descriptiontemplatedefinition; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.specification.Specification; +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; + +import java.util.Arrays; +import java.util.List; public class RulePersist { - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String target = null; + private String target = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String value= null; + public static final String _target = "target"; + private String value = null; - public String getTarget() { - return target; - } + public static final String _value = "value"; - public void setTarget(String target) { - this.target = target; - } + public String getTarget() { + return target; + } - public String getValue() { - return value; - } + public void setTarget(String target) { + this.target = target; + } - public void setValue(String value) { - this.value = value; - } + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @Component(RulePersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class RulePersistValidator extends BaseValidator { + + public static final String ValidatorName = "DescriptionTemplate.RulePersistValidator"; + + private final MessageSource messageSource; + + protected RulePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return RulePersist.class; + } + + @Override + protected List specifications(RulePersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isEmpty(item.getTarget())) + .failOn(RulePersist._target).failWith(messageSource.getMessage("Validation_Required", new Object[]{RulePersist._target}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getValue())) + .failOn(RulePersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{RulePersist._value}, LocaleContextHolder.getLocale())) + ); + } + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/SectionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/SectionPersist.java index 688a8b653..9fae38779 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/SectionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/SectionPersist.java @@ -1,118 +1,194 @@ package eu.eudat.model.persist.descriptiontemplatedefinition; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.ValidatorFactory; +import eu.eudat.commons.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; +import eu.eudat.model.persist.ActionConfirmationPersist; +import eu.eudat.model.persist.actionconfirmation.DmpInvitationPersist; +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; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; - +import java.util.Arrays; import java.util.List; public class SectionPersist { - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String id = null; + private String id = null; - @NotNull(message = "{validation.empty}") - private Integer ordinal = null; + public static final String _id = "id"; - @NotNull(message = "{validation.empty}") - private Boolean defaultVisibility = null; + private Integer ordinal = null; - @NotNull(message = "{validation.empty}") - private Boolean multiplicity = null; + public static final String _ordinal = "ordinal"; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String page = null; + private Boolean defaultVisibility = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String title = null; + public static final String _defaultVisibility = "defaultVisibility"; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String description = null; + private Boolean multiplicity = null; - @NotNull(message = "{validation.empty}") - @Valid - private List sections = null; - - @NotNull(message = "{validation.empty}") - @Valid - private List fieldSets = null; + public static final String _multiplicity = "multiplicity"; - public String getId() { - return id; - } + private String page = null; - public void setId(String id) { - this.id = id; - } + public static final String _page = "page"; - public int getOrdinal() { - return ordinal; - } + private String title = null; - public void setOrdinal(int ordinal) { - this.ordinal = ordinal; - } + public static final String _title = "title"; - public Boolean getDefaultVisibility() { - return defaultVisibility; - } + private String description = null; - public void setDefaultVisibility(Boolean defaultVisibility) { - this.defaultVisibility = defaultVisibility; - } + public static final String _description = "description"; - public Boolean getMultiplicity() { - return multiplicity; - } + private List sections = null; - public void setMultiplicity(Boolean multiplicity) { - this.multiplicity = multiplicity; - } + public static final String _sections = "sections"; - public String getPage() { - return page; - } + private List fieldSets = null; - public void setPage(String page) { - this.page = page; - } + public static final String _fieldSets = "fieldSets"; - public String getTitle() { - return title; - } + public String getId() { + return id; + } - public void setTitle(String title) { - this.title = title; - } + public void setId(String id) { + this.id = id; + } - public String getDescription() { - return description; - } + public int getOrdinal() { + return ordinal; + } - public void setDescription(String description) { - this.description = description; - } + public void setOrdinal(int ordinal) { + this.ordinal = ordinal; + } - public List getSections() { - return sections; - } + public Boolean getDefaultVisibility() { + return defaultVisibility; + } - public void setSections(List sections) { - this.sections = sections; - } + public void setDefaultVisibility(Boolean defaultVisibility) { + this.defaultVisibility = defaultVisibility; + } - public List getFieldSets() { - return fieldSets; - } + public Boolean getMultiplicity() { + return multiplicity; + } + + public void setMultiplicity(Boolean multiplicity) { + this.multiplicity = multiplicity; + } + + public String getPage() { + return page; + } + + public void setPage(String page) { + this.page = page; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public List getSections() { + return sections; + } + + public void setSections(List sections) { + this.sections = sections; + } + + public List getFieldSets() { + return fieldSets; + } + + public void setFieldSets(List fieldSets) { + this.fieldSets = fieldSets; + } + + @Component(SectionPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class SectionPersistValidator extends BaseValidator { + + public static final String ValidatorName = "DescriptionTemplate.SectionPersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + protected SectionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return SectionPersist.class; + } + + @Override + protected List specifications(SectionPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isEmpty(item.getId())) + .failOn(SectionPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._id}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getOrdinal())) + .failOn(SectionPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._ordinal}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getDefaultVisibility())) + .failOn(SectionPersist._defaultVisibility).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._defaultVisibility}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getMultiplicity())) + .failOn(SectionPersist._multiplicity).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._multiplicity}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getPage())) + .failOn(SectionPersist._page).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._page}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getTitle())) + .failOn(SectionPersist._title).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._title}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getDescription())) + .failOn(SectionPersist._description).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._description}, LocaleContextHolder.getLocale())), + + this.navSpec() + .iff(() -> !this.isNull(item.getSections())) + .on(SectionPersist._sections) + .over(item.getSections()) + .using(() -> this.validatorFactory.validator(SectionPersistValidator.class)), + this.spec() + .must(() -> !this.isNull(item.getFieldSets())) + .failOn(SectionPersist._fieldSets).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._fieldSets}, LocaleContextHolder.getLocale())), + this.navSpec() + .iff(() -> !this.isNull(item.getFieldSets())) + .on(SectionPersist._fieldSets) + .over(item.getFieldSets()) + .using(() -> this.validatorFactory.validator(FieldSetPersist.FieldSetPersistValidator.class)) + ); + } + } - public void setFieldSets(List fieldSets) { - this.fieldSets = fieldSets; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/AuthAutoCompleteDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/AuthAutoCompleteDataPersist.java index f075bc094..3185f4d68 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/AuthAutoCompleteDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/AuthAutoCompleteDataPersist.java @@ -1,66 +1,113 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; +import org.springframework.context.MessageSource; +import org.springframework.context.i18n.LocaleContextHolder; + +import java.util.Arrays; +import java.util.List; public class AuthAutoCompleteDataPersist { - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String url = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String method = null; + private String url = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String body = null; + public static final String _uri = "uri"; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String path = null; + private String method = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String type = null; + public static final String _method = "method"; - public String getUrl() { - return url; - } + private String body = null; - public void setUrl(String url) { - this.url = url; - } + public static final String _body = "body"; - public String getMethod() { - return method; - } + private String path = null; - public void setMethod(String method) { - this.method = method; - } + public static final String _path = "path"; - public String getBody() { - return body; - } + private String type = null; - public void setBody(String body) { - this.body = body; - } + public static final String _type = "type"; - public String getPath() { - return path; - } + public String getUrl() { + return url; + } - public void setPath(String path) { - this.path = path; - } + public void setUrl(String url) { + this.url = url; + } - public String getType() { - return type; - } + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public static class AuthAutoCompleteDataPersistValidator extends BaseValidator { + + public static final String ValidatorName = "DescriptionTemplate.AuthAutoCompleteDataPersistValidator"; + + private final MessageSource messageSource; + + protected AuthAutoCompleteDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return AuthAutoCompleteDataPersist.class; + } + + @Override + protected List specifications(AuthAutoCompleteDataPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isEmpty(item.getUrl())) + .failOn(AuthAutoCompleteDataPersist._uri).failWith(messageSource.getMessage("Validation_Required", new Object[]{AuthAutoCompleteDataPersist._uri}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getMethod())) + .failOn(AuthAutoCompleteDataPersist._method).failWith(messageSource.getMessage("Validation_Required", new Object[]{AuthAutoCompleteDataPersist._method}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getBody())) + .failOn(AuthAutoCompleteDataPersist._body).failWith(messageSource.getMessage("Validation_Required", new Object[]{AuthAutoCompleteDataPersist._body}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getPath())) + .failOn(AuthAutoCompleteDataPersist._path).failWith(messageSource.getMessage("Validation_Required", new Object[]{AuthAutoCompleteDataPersist._path}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getType())) + .failOn(AuthAutoCompleteDataPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{AuthAutoCompleteDataPersist._type}, LocaleContextHolder.getLocale())) + ); + } + } - public void setType(String type) { - this.type = type; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/AutoCompleteDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/AutoCompleteDataPersist.java index 1ccdc7c1c..4c5e1a065 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/AutoCompleteDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/AutoCompleteDataPersist.java @@ -1,20 +1,35 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.ValidatorFactory; +import eu.eudat.commons.validation.specification.Specification; +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; +import java.util.Arrays; import java.util.List; public class AutoCompleteDataPersist extends BaseFieldDataPersist { - @NotNull(message = "{validation.empty}") + private Boolean multiAutoComplete = null; - @NotNull(message = "{validation.empty}") - @Valid + public static final String _multiAutoComplete = "multiAutoComplete"; + private List autoCompleteSingleDataList = null; - public Boolean getMultiAutoComplete() { return multiAutoComplete; } - public void setMultiAutoComplete(Boolean multiAutoComplete) { this.multiAutoComplete = multiAutoComplete; } + public static final String _autoCompleteSingleDataList = "autoCompleteSingleDataList"; + + public Boolean getMultiAutoComplete() { + return multiAutoComplete; + } + + public void setMultiAutoComplete(Boolean multiAutoComplete) { + this.multiAutoComplete = multiAutoComplete; + } public List getAutoCompleteSingleDataList() { return autoCompleteSingleDataList; @@ -23,5 +38,40 @@ public class AutoCompleteDataPersist extends BaseFieldDataPersist { public void setAutoCompleteSingleDataList(List autoCompleteSingleDataList) { this.autoCompleteSingleDataList = autoCompleteSingleDataList; } + + @Component(AutoCompleteDataPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class AutoCompleteDataPersistValidator extends BaseFieldDataPersistValidator { + + public static final String ValidatorName = "DescriptionTemplate.AutoCompleteDataPersistValidator"; + + private final ValidatorFactory validatorFactory; + + protected AutoCompleteDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors, messageSource); + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return AutoCompleteDataPersist.class; + } + + @Override + protected List specifications(AutoCompleteDataPersist item) { + List specifications = getBaseSpecifications(item); + specifications.addAll(Arrays.asList( + this.spec() + .must(() -> !this.isNull(item.getMultiAutoComplete())) + .failOn(AutoCompleteDataPersist._multiAutoComplete).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteDataPersist._multiAutoComplete}, LocaleContextHolder.getLocale())), + this.navSpec() + .iff(() -> !this.isNull(item.getAutoCompleteSingleDataList())) + .on(AutoCompleteDataPersist._autoCompleteSingleDataList) + .over(item.getAutoCompleteSingleDataList()) + .using(() -> this.validatorFactory.validator(AutoCompleteSingleDataPersist.AutoCompleteSingleDataPersistValidator.class)) + )); + return specifications; + } + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/AutoCompleteSingleDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/AutoCompleteSingleDataPersist.java index c300150cc..3671b83c5 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/AutoCompleteSingleDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/AutoCompleteSingleDataPersist.java @@ -1,88 +1,157 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; import eu.eudat.commons.types.descriptiontemplate.fielddata.AutoCompleteDataEntity; -import eu.eudat.commons.validation.old.ValidEnum; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.ValidatorFactory; +import eu.eudat.commons.validation.specification.Specification; +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; + +import java.util.Arrays; +import java.util.List; public class AutoCompleteSingleDataPersist { - @ValidEnum(message = "{validation.empty}") - private AutoCompleteDataEntity.AutocompleteType autocompleteType; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String url = null; - - @Valid - private ComboBoxOptionPersist autoCompleteOptions; - - private String optionsRoot; + private AutoCompleteDataEntity.AutocompleteType autocompleteType; + public static final String _autocompleteType = "autocompleteType"; - @NotNull(message = "{validation.empty}") - private Boolean hasAuth = null; + private String url = null; - @Valid - private AuthAutoCompleteDataPersist auth; + public static final String _url = "url"; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String method = null; + private ComboBoxOptionPersist autoCompleteOptions; - public AutoCompleteDataEntity.AutocompleteType getAutocompleteType() { - return autocompleteType; - } + public static final String _autoCompleteOptions = "autoCompleteOptions"; - public void setAutocompleteType(AutoCompleteDataEntity.AutocompleteType autocompleteType) { - this.autocompleteType = autocompleteType; - } + private String optionsRoot; - public String getOptionsRoot() { - return optionsRoot; - } + private Boolean hasAuth = null; - public void setOptionsRoot(String optionsRoot) { - this.optionsRoot = optionsRoot; - } + public static final String _hasAuth = "hasAuth"; - public String getUrl() { - return url; - } + private AuthAutoCompleteDataPersist auth; - public void setUrl(String url) { - this.url = url; - } + public static final String _auth = "auth"; - public Boolean getHasAuth() { - return hasAuth; - } + private String method = null; - public void setHasAuth(Boolean hasAuth) { - this.hasAuth = hasAuth; - } + public static final String _method = "method"; - public AuthAutoCompleteDataPersist getAuth() { - return auth; - } + public AutoCompleteDataEntity.AutocompleteType getAutocompleteType() { + return autocompleteType; + } - public void setAuth(AuthAutoCompleteDataPersist auth) { - this.auth = auth; - } + public void setAutocompleteType(AutoCompleteDataEntity.AutocompleteType autocompleteType) { + this.autocompleteType = autocompleteType; + } - public ComboBoxOptionPersist getAutoCompleteOptions() { - return autoCompleteOptions; - } + public String getOptionsRoot() { + return optionsRoot; + } - public void setAutoCompleteOptions(ComboBoxOptionPersist autoCompleteOptions) { - this.autoCompleteOptions = autoCompleteOptions; - } + public void setOptionsRoot(String optionsRoot) { + this.optionsRoot = optionsRoot; + } - public String getMethod() { - return method; - } + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public Boolean getHasAuth() { + return hasAuth; + } + + public void setHasAuth(Boolean hasAuth) { + this.hasAuth = hasAuth; + } + + public AuthAutoCompleteDataPersist getAuth() { + return auth; + } + + public void setAuth(AuthAutoCompleteDataPersist auth) { + this.auth = auth; + } + + public ComboBoxOptionPersist getAutoCompleteOptions() { + return autoCompleteOptions; + } + + public void setAutoCompleteOptions(ComboBoxOptionPersist autoCompleteOptions) { + this.autoCompleteOptions = autoCompleteOptions; + } + + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + + @Component(AutoCompleteSingleDataPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class AutoCompleteSingleDataPersistValidator extends BaseValidator { + + public static final String ValidatorName = "DescriptionTemplate.AutoCompleteSingleDataPersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + protected AutoCompleteSingleDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return AutoCompleteSingleDataPersist.class; + } + + @Override + protected List specifications(AutoCompleteSingleDataPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isNull(item.getAutocompleteType())) + .failOn(AutoCompleteSingleDataPersist._autocompleteType).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteSingleDataPersist._autocompleteType}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getUrl())) + .failOn(AutoCompleteSingleDataPersist._url).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteSingleDataPersist._url}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getHasAuth())) + .failOn(AutoCompleteSingleDataPersist._hasAuth).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteSingleDataPersist._hasAuth}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getMethod())) + .failOn(AutoCompleteSingleDataPersist._method).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteSingleDataPersist._method}, LocaleContextHolder.getLocale())), + + this.refSpec() + .iff(() -> !this.isNull(item.getAutoCompleteOptions())) + .on(AutoCompleteSingleDataPersist._autoCompleteOptions) + .over(item.getAutoCompleteOptions()) + .using(() -> this.validatorFactory.validator(ComboBoxOptionPersist.ComboBoxOptionPersistValidator.class)), + this.spec() + .iff(() -> !this.isNull(item.getHasAuth()) && item.getHasAuth()) + .must(() -> !this.isNull(item.getAuth())) + .failOn(AutoCompleteSingleDataPersist._auth).failWith(messageSource.getMessage("Validation_Required", new Object[]{AutoCompleteSingleDataPersist._auth}, LocaleContextHolder.getLocale())), + this.refSpec() + .iff(() -> !this.isNull(item.getAuth())) + .on(AutoCompleteSingleDataPersist._auth) + .over(item.getAuth()) + .using(() -> this.validatorFactory.validator(AuthAutoCompleteDataPersist.AuthAutoCompleteDataPersistValidator.class)) + ); + } + } - public void setMethod(String method) { - this.method = method; - } } 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 f64f5eaee..6fe490360 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 @@ -3,67 +3,97 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; import eu.eudat.commons.enums.FieldType; -import eu.eudat.commons.validation.old.ValidEnum; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; +import org.springframework.context.MessageSource; +import org.springframework.context.i18n.LocaleContextHolder; + +import java.util.Arrays; +import java.util.List; @JsonTypeInfo( - use = JsonTypeInfo.Id.NAME, - include = JsonTypeInfo.As.PROPERTY, - property = "fieldType", - visible = true) + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.PROPERTY, + property = "fieldType", + visible = true) @JsonSubTypes({ - @JsonSubTypes.Type(value = AutoCompleteDataPersist.class, name = FieldType.Names.Autocomplete), - @JsonSubTypes.Type(value = BooleanDecisionDataPersist.class, name = FieldType.Names.BooleanDecision), - @JsonSubTypes.Type(value = DatasetAutoCompleteDataPersist.class, name = FieldType.Names.InternalDmpDatasets), - @JsonSubTypes.Type(value = DmpAutoCompleteDataPersist.class, name = FieldType.Names.InternalDmpDmps), - @JsonSubTypes.Type(value = CheckBoxDataPersist.class, name = FieldType.Names.CheckBox), - @JsonSubTypes.Type(value = DatePickerDataPersist.class, name = FieldType.Names.DatePicker), - @JsonSubTypes.Type(value = ExternalDatasetDataPersist.class, name = FieldType.Names.ExternalDatasets), - @JsonSubTypes.Type(value = FreeTextDataPersist.class, name = FieldType.Names.FreeText), - @JsonSubTypes.Type(value = LicenseDataPersist.class, name = FieldType.Names.Licenses), - @JsonSubTypes.Type(value = OrganizationDataPersist.class, name = FieldType.Names.Organizations), - @JsonSubTypes.Type(value = PublicationDataPersist.class, name = FieldType.Names.Publications), - @JsonSubTypes.Type(value = RadioBoxDataPersist.class, name = FieldType.Names.RadioBox), - @JsonSubTypes.Type(value = RegistryDataPersist.class, name = FieldType.Names.Registries), - @JsonSubTypes.Type(value = ResearcherAutoCompleteDataPersist.class, name = FieldType.Names.InternalDmpResearchers), - @JsonSubTypes.Type(value = ResearcherDataPersist.class, name = FieldType.Names.Researchers), - @JsonSubTypes.Type(value = RichTextAreaDataPersist.class, name = FieldType.Names.RichTextarea), - @JsonSubTypes.Type(value = ServiceDataPersist.class, name = FieldType.Names.Services), - @JsonSubTypes.Type(value = TagDataPersist.class, name = FieldType.Names.Tags), - @JsonSubTypes.Type(value = TaxonomyDataPersist.class, name = FieldType.Names.Taxonomies), - @JsonSubTypes.Type(value = TextAreaDataPersist.class, name = FieldType.Names.TextArea), - @JsonSubTypes.Type(value = UploadDataPersist.class, name = FieldType.Names.Upload), - @JsonSubTypes.Type(value = ValidationDataPersist.class, name = FieldType.Names.Validation), - @JsonSubTypes.Type(value = DatasetIdentifierDataPersist.class, name = FieldType.Names.DatasetIdentifier), - @JsonSubTypes.Type(value = CurrencyDataPersist.class, name = FieldType.Names.Currency), - @JsonSubTypes.Type(value = WordListDataPersist.class, name = FieldType.Names.Wordlist), - @JsonSubTypes.Type(value = DataRepositoryDataPersist.class, name = FieldType.Names.DataRepositories), - @JsonSubTypes.Type(value = JournalRepositoryDataPersist.class, name = FieldType.Names.JournalRepositories), - @JsonSubTypes.Type(value = PublicationRepositoryDataPersist.class, name = FieldType.Names.Publications), + @JsonSubTypes.Type(value = AutoCompleteDataPersist.class, name = FieldType.Names.Autocomplete), + @JsonSubTypes.Type(value = BooleanDecisionDataPersist.class, name = FieldType.Names.BooleanDecision), + @JsonSubTypes.Type(value = DatasetAutoCompleteDataPersist.class, name = FieldType.Names.InternalDmpDatasets), + @JsonSubTypes.Type(value = DmpAutoCompleteDataPersist.class, name = FieldType.Names.InternalDmpDmps), + @JsonSubTypes.Type(value = CheckBoxDataPersist.class, name = FieldType.Names.CheckBox), + @JsonSubTypes.Type(value = DatePickerDataPersist.class, name = FieldType.Names.DatePicker), + @JsonSubTypes.Type(value = ExternalDatasetDataPersist.class, name = FieldType.Names.ExternalDatasets), + @JsonSubTypes.Type(value = FreeTextDataPersist.class, name = FieldType.Names.FreeText), + @JsonSubTypes.Type(value = LicenseDataPersist.class, name = FieldType.Names.Licenses), + @JsonSubTypes.Type(value = OrganizationDataPersist.class, name = FieldType.Names.Organizations), + @JsonSubTypes.Type(value = PublicationDataPersist.class, name = FieldType.Names.Publications), + @JsonSubTypes.Type(value = RadioBoxDataPersist.class, name = FieldType.Names.RadioBox), + @JsonSubTypes.Type(value = RegistryDataPersist.class, name = FieldType.Names.Registries), + @JsonSubTypes.Type(value = ResearcherAutoCompleteDataPersist.class, name = FieldType.Names.InternalDmpResearchers), + @JsonSubTypes.Type(value = ResearcherDataPersist.class, name = FieldType.Names.Researchers), + @JsonSubTypes.Type(value = RichTextAreaDataPersist.class, name = FieldType.Names.RichTextarea), + @JsonSubTypes.Type(value = ServiceDataPersist.class, name = FieldType.Names.Services), + @JsonSubTypes.Type(value = TagDataPersist.class, name = FieldType.Names.Tags), + @JsonSubTypes.Type(value = TaxonomyDataPersist.class, name = FieldType.Names.Taxonomies), + @JsonSubTypes.Type(value = TextAreaDataPersist.class, name = FieldType.Names.TextArea), + @JsonSubTypes.Type(value = UploadDataPersist.class, name = FieldType.Names.Upload), + @JsonSubTypes.Type(value = ValidationDataPersist.class, name = FieldType.Names.Validation), + @JsonSubTypes.Type(value = DatasetIdentifierDataPersist.class, name = FieldType.Names.DatasetIdentifier), + @JsonSubTypes.Type(value = CurrencyDataPersist.class, name = FieldType.Names.Currency), + @JsonSubTypes.Type(value = WordListDataPersist.class, name = FieldType.Names.Wordlist), + @JsonSubTypes.Type(value = DataRepositoryDataPersist.class, name = FieldType.Names.DataRepositories), + @JsonSubTypes.Type(value = JournalRepositoryDataPersist.class, name = FieldType.Names.JournalRepositories), + @JsonSubTypes.Type(value = PublicationRepositoryDataPersist.class, name = FieldType.Names.Publications), }) public abstract class BaseFieldDataPersist { - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String label = null; + private String label = null; - @ValidEnum(message = "{validation.empty}") - private FieldType fieldType; + public static final String _label = "label"; - public String getLabel() { - return label; - } + private FieldType fieldType; - public void setLabel(String label) { - this.label = label; - } + public static final String _fieldType = "fieldType"; - public FieldType getFieldType() { - return fieldType; - } + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public FieldType getFieldType() { + return fieldType; + } + + public void setFieldType(FieldType fieldType) { + this.fieldType = fieldType; + } + + public abstract static class BaseFieldDataPersistValidator extends BaseValidator { + + protected final MessageSource messageSource; + + protected BaseFieldDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + protected List getBaseSpecifications(T item) { + return 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())) + ); + } + + } - public void setFieldType(FieldType fieldType) { - this.fieldType = fieldType; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/BooleanDecisionDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/BooleanDecisionDataPersist.java index 2815510f5..13f8d515d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/BooleanDecisionDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/BooleanDecisionDataPersist.java @@ -1,5 +1,40 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; +import eu.eudat.commons.validation.ValidatorFactory; +import eu.eudat.commons.validation.specification.Specification; +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.stereotype.Component; + +import java.util.List; + public class BooleanDecisionDataPersist extends BaseFieldDataPersist { + @Component(BooleanDecisionPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class BooleanDecisionPersistValidator extends BaseFieldDataPersistValidator { + + public static final String ValidatorName = "DescriptionTemplate.BooleanDecisionPersistValidator"; + + private final ValidatorFactory validatorFactory; + + protected BooleanDecisionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors, messageSource); + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return BooleanDecisionDataPersist.class; + } + + @Override + protected List specifications(BooleanDecisionDataPersist item) { + return getBaseSpecifications(item); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/CheckBoxDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/CheckBoxDataPersist.java index 81885a3c3..7fe287582 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/CheckBoxDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/CheckBoxDataPersist.java @@ -1,6 +1,37 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; +import eu.eudat.commons.validation.ValidatorFactory; +import eu.eudat.commons.validation.specification.Specification; +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.stereotype.Component; + +import java.util.List; + public class CheckBoxDataPersist extends BaseFieldDataPersist { - + @Component(CheckBoxDataPersist.CheckBoxDataPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class CheckBoxDataPersistValidator extends BaseFieldDataPersistValidator { + + public static final String ValidatorName = "DescriptionTemplate.CheckBoxDataPersistValidator"; + + protected CheckBoxDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors, messageSource); + } + + @Override + protected Class modelClass() { + return CheckBoxDataPersist.class; + } + + @Override + protected List specifications(CheckBoxDataPersist item) { + return getBaseSpecifications(item); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/ComboBoxOptionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/ComboBoxOptionPersist.java index c4b358a2e..113e4b04b 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/ComboBoxOptionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/ComboBoxOptionPersist.java @@ -1,53 +1,103 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.specification.Specification; +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; + +import java.util.Arrays; +import java.util.List; public class ComboBoxOptionPersist { - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String label = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String value = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String source = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String uri = null; - public String getLabel() { - return label; - } + private String label = null; - public void setLabel(String label) { - this.label = label; - } + public static final String _label = "label"; - public String getValue() { - return value; - } + private String value = null; - public void setValue(String value) { - this.value = value; - } + public static final String _value = "value"; - public String getSource() { - return source; - } + private String source = null; - public void setSource(String source) { - this.source = source; - } + public static final String _source = "source"; - public String getUri() { - return uri; - } + private String uri = null; - public void setUri(String uri) { - this.uri = uri; - } + public static final String _uri = "uri"; + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } + + public String getUri() { + return uri; + } + + public void setUri(String uri) { + this.uri = uri; + } + + @Component(ComboBoxOptionPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class ComboBoxOptionPersistValidator extends BaseValidator { + + public static final String ValidatorName = "DescriptionTemplate.ComboBoxOptionPersistValidator"; + + private final MessageSource messageSource; + + protected ComboBoxOptionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return ComboBoxOptionPersist.class; + } + + @Override + protected List specifications(ComboBoxOptionPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isEmpty(item.getLabel())) + .failOn(ComboBoxOptionPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{ComboBoxOptionPersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getValue())) + .failOn(ComboBoxOptionPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{ComboBoxOptionPersist._value}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getSource())) + .failOn(ComboBoxOptionPersist._source).failWith(messageSource.getMessage("Validation_Required", new Object[]{ComboBoxOptionPersist._source}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getUri())) + .failOn(ComboBoxOptionPersist._uri).failWith(messageSource.getMessage("Validation_Required", new Object[]{ComboBoxOptionPersist._uri}, LocaleContextHolder.getLocale())) + ); + } + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/DatasetAutoCompleteDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/DatasetAutoCompleteDataPersist.java index 13003c3c9..e47c47812 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/DatasetAutoCompleteDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/DatasetAutoCompleteDataPersist.java @@ -1,15 +1,55 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.specification.Specification; +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; + +import java.util.List; public class DatasetAutoCompleteDataPersist extends BaseFieldDataPersist { - @NotNull(message = "{validation.empty}") - private Boolean multiAutoComplete = null; - public Boolean getMultiAutoComplete() { - return multiAutoComplete; - } - public void setMultiAutoComplete(Boolean multiAutoComplete) { - this.multiAutoComplete = multiAutoComplete; - } + private Boolean multiAutoComplete = null; + + public static final String _multiAutoComplete = "multiAutoComplete"; + + public Boolean getMultiAutoComplete() { + return multiAutoComplete; + } + + public void setMultiAutoComplete(Boolean multiAutoComplete) { + this.multiAutoComplete = multiAutoComplete; + } + + @Component(DatasetAutoCompleteDataPersist.DatasetAutoCompleteDataPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class DatasetAutoCompleteDataPersistValidator extends BaseFieldDataPersistValidator { + + public static final String ValidatorName = "DescriptionTemplate.DatasetAutoCompleteDataPersistValidator"; + + protected DatasetAutoCompleteDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors, messageSource); + } + + @Override + protected Class modelClass() { + return DatasetAutoCompleteDataPersist.class; + } + + @Override + protected List specifications(DatasetAutoCompleteDataPersist item) { + List specifications = getBaseSpecifications(item); + specifications.add( + this.spec() + .must(() -> !this.isNull(item.getMultiAutoComplete())) + .failOn(DatasetAutoCompleteDataPersist._multiAutoComplete).failWith(messageSource.getMessage("Validation_Required", new Object[]{DatasetAutoCompleteDataPersist._multiAutoComplete}, LocaleContextHolder.getLocale())) + ); + return specifications; + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/DatePickerDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/DatePickerDataPersist.java index 1e3b4ddfb..4e38e4d54 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/DatePickerDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/DatePickerDataPersist.java @@ -1,4 +1,40 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; +import eu.eudat.commons.validation.ValidatorFactory; +import eu.eudat.commons.validation.specification.Specification; +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.stereotype.Component; + +import java.util.List; + public class DatePickerDataPersist extends BaseFieldDataPersist { + + @Component(DatePickerDataPersist.DatePickerDataPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class DatePickerDataPersistValidator extends BaseFieldDataPersistValidator { + + public static final String ValidatorName = "DescriptionTemplate.DatePickerDataPersistValidator"; + + private final ValidatorFactory validatorFactory; + + protected DatePickerDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors, messageSource); + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return DatePickerDataPersist.class; + } + + @Override + protected List specifications(DatePickerDataPersist item) { + return getBaseSpecifications(item); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/DmpAutoCompleteDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/DmpAutoCompleteDataPersist.java index c7cec3ea4..ca19f633a 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/DmpAutoCompleteDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/DmpAutoCompleteDataPersist.java @@ -1,16 +1,55 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.specification.Specification; +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; + +import java.util.List; public class DmpAutoCompleteDataPersist extends BaseFieldDataPersist { - @NotNull(message = "{validation.empty}") - private Boolean multiAutoComplete = null; + private Boolean multiAutoComplete = null; + + public static final String _multiAutoComplete = "multiAutoComplete"; + + public Boolean getMultiAutoComplete() { + return multiAutoComplete; + } + + public void setMultiAutoComplete(Boolean multiAutoComplete) { + this.multiAutoComplete = multiAutoComplete; + } + + @Component(DmpAutoCompleteDataPersist.DmpAutoCompleteDataPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class DmpAutoCompleteDataPersistValidator extends BaseFieldDataPersistValidator { + + public static final String ValidatorName = "DescriptionTemplate.DmpAutoCompleteDataPersistValidator"; + + protected DmpAutoCompleteDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors, messageSource); + } + + @Override + protected Class modelClass() { + return DmpAutoCompleteDataPersist.class; + } + + @Override + protected List specifications(DmpAutoCompleteDataPersist item) { + List specifications = getBaseSpecifications(item); + specifications.add( + this.spec() + .must(() -> !this.isNull(item.getMultiAutoComplete())) + .failOn(DmpAutoCompleteDataPersist._multiAutoComplete).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpAutoCompleteDataPersist._multiAutoComplete}, LocaleContextHolder.getLocale())) + ); + return specifications; + } + } - public Boolean getMultiAutoComplete() { - return multiAutoComplete; - } - public void setMultiAutoComplete(Boolean multiAutoComplete) { - this.multiAutoComplete = multiAutoComplete; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/ExternalDatasetDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/ExternalDatasetDataPersist.java index 6ade782c9..001686c1d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/ExternalDatasetDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/ExternalDatasetDataPersist.java @@ -1,16 +1,28 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; - import eu.eudat.commons.enums.FieldDataExternalDatasetType; -import eu.eudat.commons.validation.old.ValidEnum; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.specification.Specification; +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; + +import java.util.Arrays; +import java.util.List; public class ExternalDatasetDataPersist extends BaseFieldDataPersist { - @NotNull(message = "{validation.empty}") + private Boolean multiAutoComplete = null; - @ValidEnum(message = "{validation.empty}") + + public static final String _multiAutoComplete = "multiAutoComplete"; + private FieldDataExternalDatasetType type; + public static final String _type = "type"; + public Boolean getMultiAutoComplete() { return multiAutoComplete; } @@ -26,4 +38,36 @@ public class ExternalDatasetDataPersist extends BaseFieldDataPersist { public void setType(FieldDataExternalDatasetType type) { this.type = type; } + + @Component(ExternalDatasetDataPersist.ExternalDatasetDataPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class ExternalDatasetDataPersistValidator extends BaseFieldDataPersistValidator { + + public static final String ValidatorName = "DescriptionTemplate.ExternalDatasetDataPersistValidator"; + + protected ExternalDatasetDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors, messageSource); + } + + @Override + protected Class modelClass() { + return ExternalDatasetDataPersist.class; + } + + @Override + protected List specifications(ExternalDatasetDataPersist item) { + List specifications = getBaseSpecifications(item); + specifications.addAll(Arrays.asList( + this.spec() + .must(() -> !this.isNull(item.getMultiAutoComplete())) + .failOn(ExternalDatasetDataPersist._multiAutoComplete).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalDatasetDataPersist._multiAutoComplete}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getType())) + .failOn(ExternalDatasetDataPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalDatasetDataPersist._type}, LocaleContextHolder.getLocale())) + + )); + return specifications; + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/FreeTextDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/FreeTextDataPersist.java index caf84f8af..31896b639 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/FreeTextDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/FreeTextDataPersist.java @@ -1,4 +1,36 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; +import eu.eudat.commons.validation.specification.Specification; +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.stereotype.Component; + +import java.util.List; + public class FreeTextDataPersist extends BaseFieldDataPersist { + + @Component(FreeTextDataPersist.FreeTextDataPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class FreeTextDataPersistValidator extends BaseFieldDataPersistValidator { + + public static final String ValidatorName = "DescriptionTemplate.FreeTextDataPersistValidator"; + + protected FreeTextDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors, messageSource); + } + + @Override + protected Class modelClass() { + return FreeTextDataPersist.class; + } + + @Override + protected List specifications(FreeTextDataPersist item) { + return getBaseSpecifications(item); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/LicenseDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/LicenseDataPersist.java index 2d33a5f18..954d45e15 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/LicenseDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/LicenseDataPersist.java @@ -1,11 +1,22 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.specification.Specification; +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; + +import java.util.List; public class LicenseDataPersist extends BaseFieldDataPersist { - @NotNull(message = "{validation.empty}") + private Boolean multiAutoComplete = null; + public static final String _multiAutoComplete = "multiAutoComplete"; + public Boolean getMultiAutoComplete() { return multiAutoComplete; } @@ -14,4 +25,31 @@ public class LicenseDataPersist extends BaseFieldDataPersist { this.multiAutoComplete = multiAutoComplete; } + @Component(LicenseDataPersist.LicenseDataPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class LicenseDataPersistValidator extends BaseFieldDataPersistValidator { + + public static final String ValidatorName = "DescriptionTemplate.LicenseDataPersistValidator"; + + protected LicenseDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors, messageSource); + } + + @Override + protected Class modelClass() { + return LicenseDataPersist.class; + } + + @Override + protected List specifications(LicenseDataPersist item) { + List specifications = getBaseSpecifications(item); + specifications.add( + this.spec() + .must(() -> !this.isNull(item.getMultiAutoComplete())) + .failOn(LicenseDataPersist._multiAutoComplete).failWith(messageSource.getMessage("Validation_Required", new Object[]{LicenseDataPersist._multiAutoComplete}, LocaleContextHolder.getLocale())) + ); + return specifications; + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/OrganizationDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/OrganizationDataPersist.java index fc5cde675..6055bff29 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/OrganizationDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/OrganizationDataPersist.java @@ -1,11 +1,22 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.specification.Specification; +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; + +import java.util.List; public class OrganizationDataPersist extends BaseFieldDataPersist { - @NotNull(message = "{validation.empty}") + private Boolean multiAutoComplete = null; + public static final String _multiAutoComplete = "multiAutoComplete"; + public Boolean getMultiAutoComplete() { return multiAutoComplete; } @@ -14,4 +25,31 @@ public class OrganizationDataPersist extends BaseFieldDataPersist { this.multiAutoComplete = multiAutoComplete; } + @Component(OrganizationDataPersist.OrganizationDataPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class OrganizationDataPersistValidator extends BaseFieldDataPersistValidator { + + public static final String ValidatorName = "DescriptionTemplate.OrganizationDataPersistValidator"; + + protected OrganizationDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors, messageSource); + } + + @Override + protected Class modelClass() { + return OrganizationDataPersist.class; + } + + @Override + protected List specifications(OrganizationDataPersist item) { + List specifications = getBaseSpecifications(item); + specifications.add( + this.spec() + .must(() -> !this.isNull(item.getMultiAutoComplete())) + .failOn(OrganizationDataPersist._multiAutoComplete).failWith(messageSource.getMessage("Validation_Required", new Object[]{OrganizationDataPersist._multiAutoComplete}, LocaleContextHolder.getLocale())) + ); + return specifications; + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/PublicationDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/PublicationDataPersist.java index db1854960..9ea264215 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/PublicationDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/PublicationDataPersist.java @@ -1,12 +1,22 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; +import eu.eudat.commons.validation.specification.Specification; +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; -import jakarta.validation.constraints.NotNull; +import java.util.List; public class PublicationDataPersist extends BaseFieldDataPersist { - @NotNull(message = "{validation.empty}") + private Boolean multiAutoComplete; + public static final String _multiAutoComplete = "multiAutoComplete"; + public Boolean getMultiAutoComplete() { return multiAutoComplete; } @@ -15,4 +25,31 @@ public class PublicationDataPersist extends BaseFieldDataPersist { this.multiAutoComplete = multiAutoComplete; } + @Component(PublicationDataPersist.PublicationDataPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class PublicationDataPersistValidator extends BaseFieldDataPersistValidator { + + public static final String ValidatorName = "DescriptionTemplate.PublicationDataPersistValidator"; + + protected PublicationDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors, messageSource); + } + + @Override + protected Class modelClass() { + return PublicationDataPersist.class; + } + + @Override + protected List specifications(PublicationDataPersist item) { + List specifications = getBaseSpecifications(item); + specifications.add( + this.spec() + .must(() -> !this.isNull(item.getMultiAutoComplete())) + .failOn(PublicationDataPersist._multiAutoComplete).failWith(messageSource.getMessage("Validation_Required", new Object[]{PublicationDataPersist._multiAutoComplete}, LocaleContextHolder.getLocale())) + ); + return specifications; + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/RadioBoxDataPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/RadioBoxDataPersist.java index c50714189..63e48a63e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/RadioBoxDataPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/RadioBoxDataPersist.java @@ -1,16 +1,24 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; +import eu.eudat.commons.validation.ValidatorFactory; +import eu.eudat.commons.validation.specification.Specification; +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; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotNull; - +import java.util.Arrays; import java.util.List; public class RadioBoxDataPersist extends BaseFieldDataPersist { - @NotNull(message = "{validation.empty}") - @Valid + private List options = null; + public static final String _options = "options"; + public List getOptions() { return options; } @@ -18,4 +26,38 @@ public class RadioBoxDataPersist extends BaseFieldDataPersist { public void setOptions(List options) { this.options = options; } + + @Component(RadioBoxDataPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class RadioBoxDataPersistValidator extends BaseFieldDataPersistValidator { + + public static final String ValidatorName = "DescriptionTemplate.RadioBoxDataPersistValidator"; + + private final ValidatorFactory validatorFactory; + + protected RadioBoxDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors, messageSource); + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return RadioBoxDataPersist.class; + } + + @Override + protected List specifications(RadioBoxDataPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isNull(item.getOptions())) + .failOn(RadioBoxDataPersist._options).failWith(messageSource.getMessage("Validation_Required", new Object[]{RadioBoxDataPersist._options}, LocaleContextHolder.getLocale())), + this.navSpec() + .iff(() -> !this.isNull(item.getOptions())) + .on(RadioBoxDataPersist._options) + .over(item.getOptions()) + .using(() -> this.validatorFactory.validator(RadioBoxOptionPersist.RadioBoxOptionPersistValidator.class)) + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/RadioBoxOptionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/RadioBoxOptionPersist.java index 5fcd6fd47..fc70ea54d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/RadioBoxOptionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptiontemplatedefinition/fielddata/RadioBoxOptionPersist.java @@ -1,29 +1,73 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.specification.Specification; +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; + +import java.util.Arrays; +import java.util.List; public class RadioBoxOptionPersist { - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String label = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String value = null; - public String getLabel() { - return label; - } + private String label = null; - public void setLabel(String label) { - this.label = label; - } + public static final String _label = "label"; - public String getValue() { - return value; - } + private String value = null; + + public static final String _value = "value"; + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @Component(RadioBoxOptionPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class RadioBoxOptionPersistValidator extends BaseValidator { + + public static final String ValidatorName = "DescriptionTemplate.RadioBoxOptionPersistValidator"; + + private final MessageSource messageSource; + + protected RadioBoxOptionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return RadioBoxOptionPersist.class; + } + + @Override + protected List specifications(RadioBoxOptionPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isEmpty(item.getLabel())) + .failOn(RadioBoxOptionPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{RadioBoxOptionPersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getValue())) + .failOn(RadioBoxOptionPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{RadioBoxOptionPersist._value}, LocaleContextHolder.getLocale())) + ); + } + } - public void setValue(String value) { - this.value = value; - } } 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 60c8c6881..e5a48e32a 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 @@ -1,21 +1,71 @@ package eu.eudat.model.persist.referencedefinition; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.ValidatorFactory; +import eu.eudat.commons.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; +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; +import java.util.Arrays; import java.util.List; public class DefinitionPersist { - @NotNull(message = "{validation.empty}") - @Valid - private List fields = null; + @NotNull(message = "{validation.empty}") + @Valid + private List fields = null; - public List getFields() { - return fields; - } + public static final String _fields = "fields"; + + public List getFields() { + return fields; + } + + public void setFields(List fields) { + this.fields = fields; + } + + @Component(DefinitionPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class DefinitionPersistValidator extends BaseValidator { + + public static final String ValidatorName = "Reference.DefinitionPersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + protected DefinitionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return DefinitionPersist.class; + } + + @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())) + .on(DefinitionPersist._fields) + .over(item.getFields()) + .using(() -> this.validatorFactory.validator(FieldPersist.FieldPersistValidator.class)) + ); + } + } - public void setFields(List fields) { - this.fields = fields; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencedefinition/FieldPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencedefinition/FieldPersist.java index 5acd9eb51..655bf5a79 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencedefinition/FieldPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencedefinition/FieldPersist.java @@ -1,24 +1,38 @@ package eu.eudat.model.persist.referencedefinition; import eu.eudat.commons.enums.ReferenceFieldDataType; +import eu.eudat.commons.validation.BaseValidator; import eu.eudat.commons.validation.old.ValidEnum; +import eu.eudat.commons.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; +import eu.eudat.model.persist.DescriptionTemplateTypePersist; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; +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; + +import java.util.Arrays; +import java.util.List; public class FieldPersist { - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") private String code = null; - @ValidEnum(message = "{validation.empty}") + public static final String _code = "code"; + private ReferenceFieldDataType dataType; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") + public static final String _dataType = "dataType"; + private String value = null; + public static final String _value = "value"; + public String getCode() { return code; } @@ -42,6 +56,41 @@ public class FieldPersist { public void setValue(String value) { this.value = value; } + + @Component(FieldPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class FieldPersistValidator extends BaseValidator { + + public static final String ValidatorName = "Reference.FieldPersistValidator"; + + private final MessageSource messageSource; + + protected FieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return FieldPersist.class; + } + + @Override + protected List specifications(FieldPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isEmpty(item.getCode())) + .failOn(FieldPersist._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._code}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getDataType())) + .failOn(FieldPersist._dataType).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._dataType}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getValue())) + .failOn(FieldPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._value}, LocaleContextHolder.getLocale())) + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java index f48ccb161..63d8da359 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java @@ -15,6 +15,7 @@ import eu.eudat.commons.types.dmp.DmpPropertiesEntity; import eu.eudat.commons.types.notification.*; import eu.eudat.commons.types.reference.DefinitionEntity; import eu.eudat.commons.types.reference.FieldEntity; +import eu.eudat.commons.validation.ValidatorFactory; import eu.eudat.configurations.notification.NotificationProperties; import eu.eudat.convention.ConventionService; import eu.eudat.data.*; @@ -114,6 +115,8 @@ public class DmpServiceImpl implements DmpService { private final ActionConfirmationService actionConfirmationService; + private final ValidatorFactory validatorFactory; + @Autowired public DmpServiceImpl( EntityManager entityManager, @@ -126,7 +129,7 @@ public class DmpServiceImpl implements DmpService { MessageSource messageSource, XmlHandlingService xmlHandlingService, JsonHandlingService jsonHandlingService, - UserScope userScope, EventBroker eventBroker, DescriptionService descriptionService, NotificationIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, ActionConfirmationService actionConfirmationService, FileTransformerService fileTransformerService) { + UserScope userScope, EventBroker eventBroker, DescriptionService descriptionService, NotificationIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, ActionConfirmationService actionConfirmationService, FileTransformerService fileTransformerService, ValidatorFactory validatorFactory) { this.entityManager = entityManager; this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; @@ -144,6 +147,7 @@ public class DmpServiceImpl implements DmpService { this.eventHandler = eventHandler; this.notificationProperties = notificationProperties; this.actionConfirmationService = actionConfirmationService; + this.validatorFactory = validatorFactory; } public Dmp persist(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException { @@ -763,6 +767,7 @@ public class DmpServiceImpl implements DmpService { persist.setDmpInvitation(new DmpInvitationPersist(email, dmp.getId(), role)); persist.setCreatedById(this.userScope.getUserIdSafe()); persist.setExpiresAt(Instant.now().plusSeconds(Long.parseLong(this.notificationProperties.getEmailExpirationTimeSeconds()))); + validatorFactory.validator(ActionConfirmationPersist.ActionConfirmationPersistValidator.class).validateForce(persist); this.actionConfirmationService.persist(persist, null); return persist.getToken(); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/user/UserServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/user/UserServiceImpl.java index 15951d035..33c7a69e3 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/user/UserServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/user/UserServiceImpl.java @@ -15,6 +15,7 @@ import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.types.actionconfirmation.EmailConfirmationEntity; import eu.eudat.commons.types.notification.*; import eu.eudat.commons.types.user.AdditionalInfoEntity; +import eu.eudat.commons.validation.ValidatorFactory; import eu.eudat.configurations.notification.NotificationProperties; import eu.eudat.convention.ConventionService; import eu.eudat.data.*; @@ -98,6 +99,8 @@ public class UserServiceImpl implements UserService { private final NotificationProperties notificationProperties; private final NotificationIntegrationEventHandler eventHandler; + private final ValidatorFactory validatorFactory; + @Autowired public UserServiceImpl( EntityManager entityManager, @@ -110,7 +113,7 @@ public class UserServiceImpl implements UserService { EventBroker eventBroker, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService, QueryFactory queryFactory, - UserScope userScope, KeycloakService keycloakService, ActionConfirmationService actionConfirmationService, NotificationProperties notificationProperties, NotificationIntegrationEventHandler eventHandler) { + UserScope userScope, KeycloakService keycloakService, ActionConfirmationService actionConfirmationService, NotificationProperties notificationProperties, NotificationIntegrationEventHandler eventHandler, ValidatorFactory validatorFactory) { this.entityManager = entityManager; this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; @@ -127,6 +130,7 @@ public class UserServiceImpl implements UserService { this.actionConfirmationService = actionConfirmationService; this.notificationProperties = notificationProperties; this.eventHandler = eventHandler; + this.validatorFactory = validatorFactory; } //region persist @@ -401,6 +405,7 @@ public class UserServiceImpl implements UserService { persist.setEmailConfirmation(new EmailConfirmationPersist(email)); persist.setCreatedById(this.userScope.getUserIdSafe()); persist.setExpiresAt(Instant.now().plusSeconds(Long.parseLong(this.notificationProperties.getEmailExpirationTimeSeconds()))); + validatorFactory.validator(ActionConfirmationPersist.ActionConfirmationPersistValidator.class).validateForce(persist); this.actionConfirmationService.persist(persist, null); return persist.getToken(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/controllerhandler/ValidatorRequestBodyAdvice.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/controllerhandler/ValidatorRequestBodyAdvice.java index b8be7a9e9..703127b3d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/controllerhandler/ValidatorRequestBodyAdvice.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/controllerhandler/ValidatorRequestBodyAdvice.java @@ -4,6 +4,7 @@ import eu.eudat.commons.validation.Validator; import eu.eudat.commons.validation.ValidatorFactory; import eu.eudat.commons.validation.ValidationFilterAnnotation; import gr.cite.tools.exception.MyApplicationException; +import org.jetbrains.annotations.NotNull; import org.springframework.core.MethodParameter; import org.springframework.http.HttpInputMessage; import org.springframework.http.converter.HttpMessageConverter; @@ -25,8 +26,8 @@ public class ValidatorRequestBodyAdvice implements RequestBodyAdvice { } @Override - public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, - Class> converterType) { + public @NotNull Object afterBodyRead(@NotNull Object body, @NotNull HttpInputMessage inputMessage, MethodParameter parameter, @NotNull Type targetType, + @NotNull Class> converterType) { if (parameter.getMethod() != null) { ValidationFilterAnnotation[] annotations = parameter.getMethod().getAnnotationsByType((ValidationFilterAnnotation.class)); @@ -44,17 +45,17 @@ public class ValidatorRequestBodyAdvice implements RequestBodyAdvice { } @Override - public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class> converterType) { + public Object handleEmptyBody(Object body, @NotNull HttpInputMessage inputMessage, @NotNull MethodParameter parameter, @NotNull Type targetType, @NotNull Class> converterType) { return body; } @Override - public boolean supports(MethodParameter parameter, Type targetType, Class> converterType) { + public boolean supports(MethodParameter parameter, @NotNull Type targetType, @NotNull Class> converterType) { return parameter.getMethod() != null && parameter.getMethod().isAnnotationPresent((ValidationFilterAnnotation.class)); } @Override - public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class> converterType) throws IOException { + public @NotNull HttpInputMessage beforeBodyRead(@NotNull HttpInputMessage inputMessage, @NotNull MethodParameter parameter, @NotNull Type targetType, @NotNull Class> converterType) throws IOException { return inputMessage; } } \ No newline at end of file diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionController.java index 37b3705c4..434374a42 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionController.java @@ -6,6 +6,7 @@ import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.commons.enums.DmpAccessType; import eu.eudat.commons.enums.DmpStatus; import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.validation.ValidationFilterAnnotation; import eu.eudat.file.transformer.model.file.FileFormat; import eu.eudat.model.Description; import eu.eudat.model.Dmp; @@ -153,6 +154,7 @@ public class DescriptionController { @PostMapping("persist") @Transactional + @ValidationFilterAnnotation(validator = DescriptionPersist.DescriptionPersistValidator.ValidatorName, argumentName = "model") public Description persist(@MyValidate @RequestBody DescriptionPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException { logger.debug(new MapLogEntry("persisting" + Description.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); Description persisted = this.descriptionService.persist(model, fieldSet); @@ -167,6 +169,7 @@ public class DescriptionController { @PostMapping("persist-status") @Transactional + @ValidationFilterAnnotation(validator = DescriptionStatusPersist.DescriptionStatusPersistValidator.ValidatorName, argumentName = "model") public Description persistStatus(@MyValidate @RequestBody DescriptionStatusPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException { logger.debug(new MapLogEntry("persisting" + Description.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); Description persisted = this.descriptionService.persistStatus(model, fieldSet); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DmpController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DmpController.java index 019ae50ba..316cd4678 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DmpController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DmpController.java @@ -3,6 +3,7 @@ package eu.eudat.controllers.v2; import com.fasterxml.jackson.core.JsonProcessingException; import eu.eudat.audit.AuditableAction; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.validation.ValidationFilterAnnotation; import eu.eudat.data.DmpEntity; import eu.eudat.file.transformer.model.file.FileFormat; import eu.eudat.model.Dmp; @@ -143,7 +144,9 @@ public class DmpController { } @PostMapping("clone") - public Dmp buildClone(@MyValidate @RequestBody CloneDmpPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException { + @Transactional + @ValidationFilterAnnotation(validator = CloneDmpPersist.CloneDmpPersistValidator.ValidatorName, argumentName = "model") + public Dmp buildClone(@RequestBody CloneDmpPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException { logger.debug(new MapLogEntry("clone" + Dmp.class.getSimpleName()).And("model", model).And("fields", fieldSet)); this.censorFactory.censor(DmpCensor.class).censor(fieldSet, null);