From e5410f39fcae289f2bcd13824f2332ba20123752 Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Wed, 3 Jan 2024 16:45:57 +0200 Subject: [PATCH] Implementing validators for Reference persist models (not completed) --- .../commons/validation/AbstractValidator.java | 6 +- .../java/eu/eudat/data/LanguageEntity.java | 3 +- .../java/eu/eudat/data/ReferenceEntity.java | 34 ++- .../eu/eudat/data/ReferenceTypeEntity.java | 15 +- .../persist/DescriptionTemplatePersist.java | 10 +- .../model/persist/DmpUserInvitePersist.java | 64 +++++- .../persist/DmpUserInviteTypePersist.java | 54 ++++- .../eudat/model/persist/DmpUserPersist.java | 47 ++++ .../model/persist/DmpUserRemovePersist.java | 60 ++++- .../eudat/model/persist/EntityDoiPersist.java | 66 +++++- .../eudat/model/persist/LanguagePersist.java | 142 ++++++++---- .../eu/eudat/model/persist/LockPersist.java | 69 +++++- .../NewVersionDescriptionTemplatePersist.java | 123 ++++++++--- .../model/persist/NewVersionDmpPersist.java | 75 +++++-- .../eudat/model/persist/ReferencePersist.java | 22 +- .../model/persist/ReferenceTypePersist.java | 97 ++++++-- .../ReferenceTypeDefinitionPersist.java | 101 +++++++-- .../ReferenceTypeFieldPersist.java | 24 ++ ...nceTypeSourceBaseConfigurationPersist.java | 70 +++++- ...erenceTypeSourceBaseDependencyPersist.java | 50 ++++- ...SourceExternalApiConfigurationPersist.java | 29 ++- ...ourceStaticOptionConfigurationPersist.java | 23 ++ .../v2/DescriptionTemplateController.java | 31 ++- .../eudat/controllers/v2/DmpController.java | 16 +- .../controllers/v2/EntityDoiController.java | 6 +- .../controllers/v2/LanguageV2Controller.java | 29 ++- .../eudat/controllers/v2/LockController.java | 209 +++++++++--------- .../controllers/v2/ReferenceController.java | 24 +- 28 files changed, 1146 insertions(+), 353 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/validation/AbstractValidator.java b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/AbstractValidator.java index c45e7d282..e2f3e81b1 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/validation/AbstractValidator.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/validation/AbstractValidator.java @@ -70,7 +70,11 @@ public abstract class AbstractValidator implements Validator { @Override public void validate(Object target){ this.bindingResult = new BeanPropertyBindingResult(target, target.getClass().getName()); - this.validate(target, this.bindingResult); + if (target instanceof Collection) { + ((Collection) target).forEach(x -> this.validate(x, this.bindingResult)); + } else { + this.validate(target, this.bindingResult); + } } @Override diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/LanguageEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/LanguageEntity.java index f3b7476e2..3a8292ae3 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/LanguageEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/LanguageEntity.java @@ -17,9 +17,10 @@ public class LanguageEntity extends TenantScopedBaseEntity { private UUID id; public static final String _id = "id"; - @Column(name = "code", length = 20, nullable = false) + @Column(name = "code", length = _codeLength, nullable = false) private String code; public static final String _code = "code"; + public static final int _codeLength = 20; @Column(name = "payload") private String payload; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/ReferenceEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/ReferenceEntity.java index 6a920497f..efb80df9f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/ReferenceEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/ReferenceEntity.java @@ -1,11 +1,11 @@ package eu.eudat.data; -import eu.eudat.commons.enums.ReferenceType; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.ReferenceSourceType; +import eu.eudat.commons.enums.ReferenceType; +import eu.eudat.data.converters.enums.IsActiveConverter; import eu.eudat.data.converters.enums.ReferenceSourceTypeConverter; import eu.eudat.data.converters.enums.ReferenceTypeConverter; -import eu.eudat.data.converters.enums.IsActiveConverter; import eu.eudat.data.tenant.TenantScopedBaseEntity; import jakarta.persistence.*; @@ -19,57 +19,78 @@ public class ReferenceEntity extends TenantScopedBaseEntity { @Id @Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false) private UUID id; + public static final String _id = "id"; - @Column(name = "label", length = 500, nullable = false) + @Column(name = "label", length = _labelLength, nullable = false) private String label; + public static final String _label = "label"; + public static final int _labelLength = 500; + @Column(name = "type", nullable = false) @Convert(converter = ReferenceTypeConverter.class) private ReferenceType type; + public static final String _type = "type"; @Column(name = "description") private String description; + public static final String _description = "description"; @Column(name = "definition") private String definition; + public static final String _definition = "definition"; - @Column(name = "reference", length = 1024, nullable = false) + @Column(name = "reference", length = _referenceLength, nullable = false) private String reference; + public static final String _reference = "reference"; - @Column(name = "abbreviation", length = 50) + public static final int _referenceLength = 1024; + + @Column(name = "abbreviation", length = _abbreviationLength) private String abbreviation; + public static final String _abbreviation = "abbreviation"; - @Column(name = "source", length = 1024) + public static final int _abbreviationLength = 50; + + @Column(name = "source", length = _sourceLength) private String source; + public static final String _source = "source"; + public static final int _sourceLength = 1024; + @Column(name = "source_type", nullable = false) @Convert(converter = ReferenceSourceTypeConverter.class) private ReferenceSourceType sourceType; + public static final String _sourceType = "sourceType"; @Column(name = "is_active", nullable = false) @Convert(converter = IsActiveConverter.class) private IsActive isActive; + public static final String _isActive = "isActive"; @Column(name = "created_at", nullable = false) private Instant createdAt; + public static final String _createdAt = "createdAt"; @Column(name = "updated_at", nullable = false) private Instant updatedAt; + public static final String _updatedAt = "updatedAt"; @Column(name = "created_by", columnDefinition = "uuid") private UUID createdById; + public static final String _createdById = "createdBy"; public UUID getId() { @@ -175,4 +196,5 @@ public class ReferenceEntity extends TenantScopedBaseEntity { public void setCreatedById(UUID createdById) { this.createdById = createdById; } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/ReferenceTypeEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/ReferenceTypeEntity.java index 2f358fe3c..ebc5dc00e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/ReferenceTypeEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/ReferenceTypeEntity.java @@ -15,31 +15,42 @@ public class ReferenceTypeEntity extends TenantScopedBaseEntity { @Id @Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false) private UUID id; + public static final String _id = "id"; - @Column(name = "name", length = 250, nullable = false) + @Column(name = "name", length = _nameLength, nullable = false) private String name; + public static final String _name = "name"; - @Column(name = "code", length = 100, nullable = false) + public static final int _nameLength = 250; + + @Column(name = "code", length = _codeLength, nullable = false) private String code; + public static final String _code = "code"; + public static final int _codeLength = 100; + @Column(name = "definition") private String definition; + public static final String _definition = "definition"; @Column(name = "is_active", nullable = false) @Convert(converter = IsActiveConverter.class) private IsActive isActive; + public static final String _isActive = "isActive"; @Column(name = "created_at", nullable = false) private Instant createdAt; + public static final String _createdAt = "createdAt"; @Column(name = "updated_at", nullable = false) private Instant updatedAt; + public static final String _updatedAt = "updatedAt"; public UUID getId() { 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 286074b1e..53fa225c3 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 @@ -5,10 +5,9 @@ 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.data.DescriptionTemplateEntity; import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.model.persist.descriptiontemplatedefinition.DefinitionPersist; -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; @@ -27,8 +26,6 @@ public class DescriptionTemplatePersist { public static final String _label = "label"; - public static final int _labelLength = 250; - private String description = null; public static final String _description = "description"; @@ -45,13 +42,10 @@ public class DescriptionTemplatePersist { 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"; @@ -169,7 +163,7 @@ public class DescriptionTemplatePersist { .failOn(DescriptionTemplatePersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._label}, LocaleContextHolder.getLocale())), this.spec() .iff(() -> !this.isEmpty(item.getLabel())) - .must(() -> this.lessEqualLength(item.getLabel(), DescriptionTemplatePersist._labelLength)) + .must(() -> this.lessEqualLength(item.getLabel(), DescriptionTemplateEntity._labelLength)) .failOn(DescriptionTemplatePersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DescriptionTemplatePersist._label}, LocaleContextHolder.getLocale())), this.spec() .must(() -> !this.isEmpty(item.getDescription())) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpUserInvitePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpUserInvitePersist.java index 1b9a34e75..bc5a1b341 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpUserInvitePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpUserInvitePersist.java @@ -1,23 +1,30 @@ package eu.eudat.model.persist; 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.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 DmpUserInvitePersist { - @Valid - @NotNull - @NotEmpty private List users; - @ValidEnum(message = "{validation.empty}") + public static final String _users = "users"; + private DmpUserRole role; + public static final String _role = "role"; + public List getUsers() { return users; } @@ -33,4 +40,45 @@ public class DmpUserInvitePersist { public void setRole(DmpUserRole role) { this.role = role; } + + @Component(DmpUserInvitePersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class DmpUserInvitePersistValidator extends BaseValidator { + + public static final String ValidatorName = "DmpUserInvitePersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + protected DmpUserInvitePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return DmpUserInvitePersist.class; + } + + @Override + protected List specifications(DmpUserInvitePersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isNull(item.getRole())) + .failOn(DmpUserInvitePersist._role).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserInvitePersist._role}, LocaleContextHolder.getLocale())), + + this.spec() + .must(() -> !this.isNull(item.getUsers())) + .failOn(DmpUserInvitePersist._users).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserInvitePersist._users}, LocaleContextHolder.getLocale())), + this.navSpec() + .iff(() -> !this.isNull(item.getUsers())) + .on(DmpUserInvitePersist._users) + .over(item.getUsers()) + .using(() -> this.validatorFactory.validator(DmpUserInviteTypePersist.DmpUserInviteTypePersistValidator.class)) + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpUserInviteTypePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpUserInviteTypePersist.java index ee01ad183..e12202db2 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpUserInviteTypePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpUserInviteTypePersist.java @@ -1,16 +1,29 @@ package eu.eudat.model.persist; -import eu.eudat.commons.validation.old.RequiredOneField; +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; -@RequiredOneField(fieldNames={"userId","email"}) public class DmpUserInviteTypePersist { - + private UUID userId; + public static final String _userId = "userId"; + private String email; + public static final String _email = "email"; + public UUID getUserId() { return userId; } @@ -26,4 +39,39 @@ public class DmpUserInviteTypePersist { public void setEmail(String email) { this.email = email; } + + @Component(DmpUserInviteTypePersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class DmpUserInviteTypePersistValidator extends BaseValidator { + + public static final String ValidatorName = "DmpUserInviteTypePersistValidator"; + + private final MessageSource messageSource; + + protected DmpUserInviteTypePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return DmpUserInviteTypePersist.class; + } + + @Override + protected List specifications(DmpUserInviteTypePersist item) { + return Arrays.asList( + this.spec() + .iff(() -> this.isEmpty(item.getEmail())) + .must(() -> !this.isValidGuid(item.getUserId())) + .failOn(DmpUserInviteTypePersist._userId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserInviteTypePersist._userId}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isValidGuid(item.getUserId())) + .must(() -> !this.isEmpty(item.getEmail())) + .failOn(DmpUserInviteTypePersist._email).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserInviteTypePersist._email}, LocaleContextHolder.getLocale())) + ); + } + + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpUserPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpUserPersist.java index 821a136e6..e1816ec3b 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpUserPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpUserPersist.java @@ -1,15 +1,30 @@ package eu.eudat.model.persist; import eu.eudat.commons.enums.DmpUserRole; +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 DmpUserPersist { private UUID user; + public static final String _user = "user"; + private DmpUserRole role; + public static final String _role = "role"; + public UUID getUser() { return user; } @@ -25,4 +40,36 @@ public class DmpUserPersist { public void setRole(DmpUserRole role) { this.role = role; } + + @Component(DmpUserPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class DmpUserPersistValidator extends BaseValidator { + + public static final String ValidatorName = "DmpUserPersistValidator"; + + private final MessageSource messageSource; + + protected DmpUserPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return DmpUserPersist.class; + } + + @Override + protected List specifications(DmpUserPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isValidGuid(item.getUser())) + .failOn(DmpUserPersist._user).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserPersist._user}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getRole())) + .failOn(DmpUserPersist._role).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserPersist._role}, LocaleContextHolder.getLocale())) + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpUserRemovePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpUserRemovePersist.java index 11673e474..0832dac56 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpUserRemovePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpUserRemovePersist.java @@ -1,27 +1,34 @@ package eu.eudat.model.persist; import eu.eudat.commons.enums.DmpUserRole; -import eu.eudat.commons.validation.old.ValidEnum; -import eu.eudat.commons.validation.old.ValidId; -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 DmpUserRemovePersist { - @NotNull(message = "{validation.empty}") - @ValidId(message = "{validation.invalidid}") private UUID id; - @NotNull(message = "{validation.empty}") - @ValidId(message = "{validation.invalidid}") + public static final String _id = "id"; + private UUID dmpId; + public static final String _dmpId = "dmpId"; - @NotNull(message = "{validation.empty}") - @ValidEnum(message = "{validation.empty}") private DmpUserRole role; + public static final String _role = "role"; + public UUID getId() { return id; } @@ -45,4 +52,39 @@ public class DmpUserRemovePersist { public void setRole(DmpUserRole role) { this.role = role; } + + @Component(DmpUserRemovePersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class DmpUserRemovePersistValidator extends BaseValidator { + + public static final String ValidatorName = "DmpUserRemovePersistValidator"; + + private final MessageSource messageSource; + + protected DmpUserRemovePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return DmpUserRemovePersist.class; + } + + @Override + protected List specifications(DmpUserRemovePersist item) { + return Arrays.asList( + this.spec() + .must(() -> this.isValidGuid(item.getId())) + .failOn(DmpUserRemovePersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserRemovePersist._id}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> this.isValidGuid(item.getDmpId())) + .failOn(DmpUserRemovePersist._dmpId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserRemovePersist._dmpId}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getRole())) + .failOn(DmpUserRemovePersist._role).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserRemovePersist._role}, LocaleContextHolder.getLocale())) + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/EntityDoiPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/EntityDoiPersist.java index 1db790df3..8feea9eb5 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/EntityDoiPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/EntityDoiPersist.java @@ -1,24 +1,39 @@ package eu.eudat.model.persist; -import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; -import eu.eudat.commons.validation.old.ValidId; +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 EntityDoiPersist { - @ValidId(message = "{validation.invalidid}") private UUID id; private UUID entityId; + public static final String _entityId = "entityId"; + private String repositoryId; + public static final String _repositoryId = "repositoryId"; + private String doi; + public static final String _doi = "doi"; + private String hash; + public static final String _hash = "hash"; + public UUID getId() { return id; } @@ -58,4 +73,47 @@ public class EntityDoiPersist { public void setHash(String hash) { this.hash = hash; } + + @Component(EntityDoiPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class EntityDoiPersistValidator extends BaseValidator { + + public static final String ValidatorName = "EntityDoiPersistValidator"; + + private final MessageSource messageSource; + + protected EntityDoiPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return EntityDoiPersist.class; + } + + @Override + protected List specifications(EntityDoiPersist item) { + return Arrays.asList( + this.spec() + .iff(() -> this.isValidGuid(item.getId())) + .must(() -> this.isValidHash(item.getHash())) + .failOn(EntityDoiPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{EntityDoiPersist._hash}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isValidGuid(item.getId())) + .must(() -> !this.isValidHash(item.getHash())) + .failOn(EntityDoiPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> this.isValidGuid(item.getEntityId())) + .failOn(EntityDoiPersist._entityId).failWith(messageSource.getMessage("Validation_Required", new Object[]{EntityDoiPersist._entityId}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getRepositoryId())) + .failOn(EntityDoiPersist._repositoryId).failWith(messageSource.getMessage("Validation_Required", new Object[]{EntityDoiPersist._repositoryId}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getDoi())) + .failOn(EntityDoiPersist._doi).failWith(messageSource.getMessage("Validation_Required", new Object[]{EntityDoiPersist._doi}, LocaleContextHolder.getLocale())) + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/LanguagePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/LanguagePersist.java index 81d21f039..86da94b5d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/LanguagePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/LanguagePersist.java @@ -1,65 +1,119 @@ package eu.eudat.model.persist; -import eu.eudat.commons.validation.old.ValidId; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.LanguageEntity; +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 LanguagePersist { - @ValidId(message = "{validation.invalidid}") - private UUID id; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - @Size(max = 20, message = "{validation.largerthanmax}") - private String code; + private UUID id; - private String payload; + private String code; - @NotNull(message = "{validation.empty}") - private Integer ordinal; + public static final String _code = "code"; - private String hash; + private String payload; - public UUID getId() { - return id; - } + private Integer ordinal; - public void setId(UUID id) { - this.id = id; - } + public static final String _ordinal = "ordinal"; - public String getCode() { - return code; - } + private String hash; - public void setCode(String code) { - this.code = code; - } + public static final String _hash = "hash"; - public String getPayload() { - return payload; - } + public UUID getId() { + return id; + } - public void setPayload(String payload) { - this.payload = payload; - } + public void setId(UUID id) { + this.id = id; + } - public Integer getOrdinal() { - return ordinal; - } + public String getCode() { + return code; + } - public void setOrdinal(Integer ordinal) { - this.ordinal = ordinal; - } + public void setCode(String code) { + this.code = code; + } - public String getHash() { - return hash; - } + public String getPayload() { + return payload; + } + + public void setPayload(String payload) { + this.payload = payload; + } + + public Integer getOrdinal() { + return ordinal; + } + + public void setOrdinal(Integer ordinal) { + this.ordinal = ordinal; + } + + public String getHash() { + return hash; + } + + public void setHash(String hash) { + this.hash = hash; + } + + @Component(LanguagePersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class LanguagePersistValidator extends BaseValidator { + + public static final String ValidatorName = "LanguagePersistValidator"; + + private final MessageSource messageSource; + + protected LanguagePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return LanguagePersist.class; + } + + @Override + protected List specifications(LanguagePersist item) { + return Arrays.asList( + this.spec() + .iff(() -> this.isValidGuid(item.getId())) + .must(() -> this.isValidHash(item.getHash())) + .failOn(LanguagePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{LanguagePersist._hash}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isValidGuid(item.getId())) + .must(() -> !this.isValidHash(item.getHash())) + .failOn(LanguagePersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getCode())) + .failOn(LanguagePersist._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{LanguagePersist._code}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isEmpty(item.getCode())) + .must(() -> this.lessEqualLength(item.getCode(), LanguageEntity._codeLength)) + .failOn(LanguagePersist._code).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{LanguagePersist._code}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getOrdinal())) + .failOn(LanguagePersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{LanguagePersist._ordinal}, LocaleContextHolder.getLocale())) + ); + } + } - public void setHash(String hash) { - this.hash = hash; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/LockPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/LockPersist.java index b62060408..e8feedad0 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/LockPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/LockPersist.java @@ -1,29 +1,35 @@ package eu.eudat.model.persist; import eu.eudat.commons.enums.LockTargetType; -import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; -import eu.eudat.commons.validation.old.ValidEnum; -import eu.eudat.commons.validation.old.ValidId; -import jakarta.validation.Valid; +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 LockPersist { - @ValidId(message = "{validation.invalidid}") private UUID id; - @Valid private UUID target; - @ValidEnum(message = "{validation.empty}") + public static final String _target = "target"; + private LockTargetType targetType; - @Valid + public static final String _targetType = "targetType"; + private UUID lockedBy; - public static final String _touchedAt = "touchedAt"; + public static final String _lockedBy = "lockedBy"; private String hash; @@ -68,4 +74,47 @@ public class LockPersist { public void setHash(String hash) { this.hash = hash; } + + @Component(LockPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class LockPersistValidator extends BaseValidator { + + public static final String ValidatorName = "LockPersistValidator"; + + private final MessageSource messageSource; + + protected LockPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return LockPersist.class; + } + + @Override + protected List specifications(LockPersist item) { + return Arrays.asList( + this.spec() + .iff(() -> this.isValidGuid(item.getId())) + .must(() -> this.isValidHash(item.getHash())) + .failOn(LockPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{LockPersist._hash}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isValidGuid(item.getId())) + .must(() -> !this.isValidHash(item.getHash())) + .failOn(LockPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> this.isValidGuid(item.getTarget())) + .failOn(LockPersist._target).failWith(messageSource.getMessage("Validation_Required", new Object[]{LockPersist._target}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getTargetType())) + .failOn(LockPersist._targetType).failWith(messageSource.getMessage("Validation_Required", new Object[]{LockPersist._targetType}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> this.isValidGuid(item.getLockedBy())) + .failOn(LockPersist._lockedBy).failWith(messageSource.getMessage("Validation_Required", new Object[]{LockPersist._lockedBy}, LocaleContextHolder.getLocale())) + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/NewVersionDescriptionTemplatePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/NewVersionDescriptionTemplatePersist.java index c9adf070c..d7a4c8b26 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/NewVersionDescriptionTemplatePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/NewVersionDescriptionTemplatePersist.java @@ -1,55 +1,59 @@ 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.commons.validation.BaseValidator; +import eu.eudat.commons.validation.ValidatorFactory; +import eu.eudat.commons.validation.specification.Specification; +import eu.eudat.convention.ConventionService; import eu.eudat.data.DescriptionTemplateEntity; +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 NewVersionDescriptionTemplatePersist { - @NotNull(message = "{validation.empty}") - @ValidId(message = "{validation.invalidid}") + private UUID id = null; - @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"; + 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; - @NotNull(message = "{validation.empty}") - @Valid + public static final String _status = "status"; + private DefinitionPersist definition = null; - @Valid + public static final String _definition = "definition"; + 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,5 +125,74 @@ public class NewVersionDescriptionTemplatePersist { public void setUsers(List users) { this.users = users; } + + @Component(NewVersionDescriptionTemplatePersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class NewVersionDescriptionTemplatePersistValidator extends BaseValidator { + + public static final String ValidatorName = "NewVersionDescriptionTemplatePersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + protected NewVersionDescriptionTemplatePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return NewVersionDescriptionTemplatePersist.class; + } + + @Override + protected List specifications(NewVersionDescriptionTemplatePersist item) { + return Arrays.asList( + this.spec() + .iff(() -> this.isValidGuid(item.getId())) + .must(() -> this.isValidHash(item.getHash())) + .failOn(NewVersionDescriptionTemplatePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDescriptionTemplatePersist._hash}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getLabel())) + .failOn(NewVersionDescriptionTemplatePersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDescriptionTemplatePersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isEmpty(item.getLabel())) + .must(() -> this.lessEqualLength(item.getLabel(), DescriptionTemplateEntity._labelLength)) + .failOn(NewVersionDescriptionTemplatePersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{NewVersionDescriptionTemplatePersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getDescription())) + .failOn(NewVersionDescriptionTemplatePersist._description).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDescriptionTemplatePersist._description}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getLanguage())) + .failOn(NewVersionDescriptionTemplatePersist._language).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDescriptionTemplatePersist._language}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getType())) + .failOn(NewVersionDescriptionTemplatePersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDescriptionTemplatePersist._type}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getStatus())) + .failOn(NewVersionDescriptionTemplatePersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDescriptionTemplatePersist._status}, LocaleContextHolder.getLocale())), + + this.spec() + .must(() -> !this.isNull(item.getDefinition())) + .failOn(NewVersionDescriptionTemplatePersist._definition).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDescriptionTemplatePersist._definition}, LocaleContextHolder.getLocale())), + this.refSpec() + .iff(() -> !this.isNull(item.getDefinition())) + .on(NewVersionDescriptionTemplatePersist._definition) + .over(item.getDefinition()) + .using(() -> this.validatorFactory.validator(DefinitionPersist.DefinitionPersistValidator.class)), + this.spec() + .must(() -> !this.isNull(item.getUsers())) + .failOn(NewVersionDescriptionTemplatePersist._users).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDescriptionTemplatePersist._users}, LocaleContextHolder.getLocale())), + this.navSpec() + .iff(() -> !this.isNull(item.getUsers())) + .on(NewVersionDescriptionTemplatePersist._users) + .over(item.getUsers()) + .using(() -> this.validatorFactory.validator(UserDescriptionTemplatePersist.UserDescriptionTemplatePersistValidator.class)) + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/NewVersionDmpPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/NewVersionDmpPersist.java index d0b375a8f..c2b3c04f1 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/NewVersionDmpPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/NewVersionDmpPersist.java @@ -1,38 +1,42 @@ package eu.eudat.model.persist; -import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; -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.data.DmpEntity; +import eu.eudat.errorcode.ErrorThesaurusProperties; import org.apache.commons.compress.utils.Lists; +import org.springframework.context.MessageSource; +import org.springframework.context.i18n.LocaleContextHolder; +import java.util.Arrays; import java.util.List; import java.util.UUID; -@FieldNotNullIfOtherSet(message = "{validation.hashempty}") public class NewVersionDmpPersist { - @NotNull(message = "{validation.empty}") - @ValidId(message = "{validation.invalidid}") private UUID id = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") 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}") - @ValidId(message = "{validation.invalidid}") + public static final String _description = "description"; + private UUID blueprintId = null; - @NotNull(message = "{validation.empty}") + public static final String _blueprintId = "blueprintId"; + private List descriptions = Lists.newArrayList(); + public static final String _descriptions = "descriptions"; + private String hash; + public static final String _hash = "hash"; + public UUID getId() { return id; } @@ -81,4 +85,47 @@ public class NewVersionDmpPersist { this.hash = hash; } + public static class NewVersionDmpPersistValidator extends BaseValidator { + + public static final String ValidatorName = "NewVersionDmpPersistValidator"; + + private final MessageSource messageSource; + + protected NewVersionDmpPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return NewVersionDmpPersist.class; + } + + @Override + protected List specifications(NewVersionDmpPersist item) { + return Arrays.asList( + this.spec() + .iff(() -> this.isValidGuid(item.getId())) + .must(() -> this.isValidHash(item.getHash())) + .failOn(NewVersionDmpPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDmpPersist._hash}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getLabel())) + .failOn(NewVersionDmpPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDmpPersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isEmpty(item.getLabel())) + .must(() -> this.lessEqualLength(item.getLabel(), DmpEntity._labelLength)) + .failOn(NewVersionDmpPersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{NewVersionDmpPersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getDescription())) + .failOn(NewVersionDmpPersist._description).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDmpPersist._description}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isValidGuid(item.getBlueprintId())) + .failOn(NewVersionDmpPersist._blueprintId).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDmpPersist._blueprintId}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getDescriptions())) + .failOn(NewVersionDmpPersist._descriptions).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDmpPersist._descriptions}, LocaleContextHolder.getLocale())) + ); + } + } + } 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 cff67cae7..978cdc09b 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 @@ -4,12 +4,11 @@ import eu.eudat.commons.enums.ReferenceSourceType; 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.specification.Specification; import eu.eudat.convention.ConventionService; +import eu.eudat.data.ReferenceEntity; import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.model.persist.referencedefinition.DefinitionPersist; -import jakarta.validation.constraints.Size; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Scope; @@ -28,8 +27,6 @@ public class ReferencePersist { public static final String _label = "label"; - public static final int _labelLength = 250; - private ReferenceType type; public static final String _type = "type"; @@ -44,23 +41,14 @@ public class ReferencePersist { 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"; @@ -186,7 +174,7 @@ public class ReferencePersist { .failOn(ReferencePersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._label}, LocaleContextHolder.getLocale())), this.spec() .iff(() -> !this.isEmpty(item.getLabel())) - .must(() -> this.lessEqualLength(item.getLabel(), ReferencePersist._labelLength)) + .must(() -> this.lessEqualLength(item.getLabel(), ReferenceEntity._labelLength)) .failOn(ReferencePersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._label}, LocaleContextHolder.getLocale())), this.spec() .must(() -> !this.isNull(item.getType())) @@ -196,21 +184,21 @@ public class ReferencePersist { .failOn(ReferencePersist._reference).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._reference}, LocaleContextHolder.getLocale())), this.spec() .iff(() -> !this.isEmpty(item.getReference())) - .must(() -> this.lessEqualLength(item.getReference(), ReferencePersist._referenceLength)) + .must(() -> this.lessEqualLength(item.getReference(), ReferenceEntity._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.lessEqualLength(item.getAbbreviation(), ReferencePersist._abbreviationLength)) + .must(() -> this.lessEqualLength(item.getAbbreviation(), ReferenceEntity._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.lessEqualLength(item.getSource(), ReferencePersist._sourceLength)) + .must(() -> this.lessEqualLength(item.getSource(), ReferenceEntity._sourceLength)) .failOn(ReferencePersist._source).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._source}, LocaleContextHolder.getLocale())), this.spec() .must(() -> !this.isNull(item.getSourceType())) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/ReferenceTypePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/ReferenceTypePersist.java index 0c65a0fe5..c1d7d6dec 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/ReferenceTypePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/ReferenceTypePersist.java @@ -1,37 +1,42 @@ package eu.eudat.model.persist; -import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; -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.data.ReferenceTypeEntity; +import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.model.persist.referencetypedefinition.ReferenceTypeDefinitionPersist; -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 ReferenceTypePersist { - @ValidId(message = "{validation.invalidid}") private UUID id; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - @Size(max = 250, message = "{validation.largerthanmax}") private String name; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - @Size(max = 100, message = "{validation.largerthanmax}") + public static final String _name = "name"; + private String code; - @NotNull(message = "{validation.empty}") - @Valid + public static final String _code = "code"; + private ReferenceTypeDefinitionPersist definition; + public static final String _definition = "definition"; + private String hash; + public static final String _hash = "hash"; + public UUID getId() { return id; } @@ -71,4 +76,64 @@ public class ReferenceTypePersist { public void setHash(String hash) { this.hash = hash; } + + @Component(ReferenceTypePersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class ReferenceTypePersistValidator extends BaseValidator { + + public static final String ValidatorName = "ReferenceTypePersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + protected ReferenceTypePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return ReferenceTypePersist.class; + } + + @Override + protected List specifications(ReferenceTypePersist item) { + return Arrays.asList( + this.spec() + .iff(() -> this.isValidGuid(item.getId())) + .must(() -> this.isValidHash(item.getHash())) + .failOn(ReferenceTypePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypePersist._hash}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isValidGuid(item.getId())) + .must(() -> !this.isValidHash(item.getHash())) + .failOn(ReferenceTypePersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getName())) + .failOn(ReferenceTypePersist._name).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypePersist._name}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isEmpty(item.getName())) + .must(() -> this.lessEqualLength(item.getName(), ReferenceTypeEntity._nameLength)) + .failOn(ReferenceTypePersist._name).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferenceTypePersist._name}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getCode())) + .failOn(ReferenceTypePersist._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypePersist._code}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isEmpty(item.getCode())) + .must(() -> this.lessEqualLength(item.getCode(), ReferenceTypeEntity._codeLength)) + .failOn(ReferenceTypePersist._code).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferenceTypePersist._code}, LocaleContextHolder.getLocale())), + + this.spec() + .must(() -> !this.isNull(item.getDefinition())) + .failOn(ReferenceTypePersist._definition).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypePersist._definition}, LocaleContextHolder.getLocale())), + this.refSpec() + .iff(() -> !this.isNull(item.getDefinition())) + .on(ReferenceTypePersist._definition) + .over(item.getDefinition()) + .using(() -> this.validatorFactory.validator(ReferenceTypeDefinitionPersist.ReferenceTypeDefinitionPersistValidator.class)) + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeDefinitionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeDefinitionPersist.java index 1d9e36f73..18a53a72c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeDefinitionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeDefinitionPersist.java @@ -1,32 +1,95 @@ package eu.eudat.model.persist.referencetypedefinition; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotNull; +import eu.eudat.commons.enums.ReferenceTypeSourceType; +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.DescriptionPersist; +import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist; +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 ReferenceTypeDefinitionPersist { - @Valid - private List fields = null; + private List fields = null; - @NotNull(message = "{validation.empty}") - @Valid - private List sources = null; + public static final String _fields = "fields"; - public List getFields() { - return fields; - } + private List sources = null; - public void setFields(List fields) { - this.fields = fields; - } + public static final String _sources = "sources"; - public List getSources() { - return sources; - } + public List getFields() { + return fields; + } + + public void setFields(List fields) { + this.fields = fields; + } + + public List getSources() { + return sources; + } + + public void setSources(List sources) { + this.sources = sources; + } + + @Component(ReferenceTypeDefinitionPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class ReferenceTypeDefinitionPersistValidator extends BaseValidator { + + public static final String ValidatorName = "ReferenceTypeDefinitionPersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + protected ReferenceTypeDefinitionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return ReferenceTypeDefinitionPersist.class; + } + + @Override + protected List specifications(ReferenceTypeDefinitionPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isNull(item.getFields())) + .failOn(ReferenceTypeDefinitionPersist._fields).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeDefinitionPersist._fields}, LocaleContextHolder.getLocale())), + this.navSpec() + .iff(() -> !this.isNull(item.getFields())) + .on(ReferenceTypeDefinitionPersist._fields) + .over(item.getFields()) + .using(() -> this.validatorFactory.validator(ReferenceTypeFieldPersist.ReferenceTypeFieldPersistValidator.class)), + this.spec() + .must(() -> !this.isNull(item.getSources())) + .failOn(ReferenceTypeDefinitionPersist._sources).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeDefinitionPersist._sources}, LocaleContextHolder.getLocale())), + this.navSpec() + .iff(() -> !this.isNull(item.getSources())) + .on(ReferenceTypeDefinitionPersist._sources) + .over(item.getSources().stream().filter(x -> x.getType() == ReferenceTypeSourceType.API).toList()) + .using(() -> this.validatorFactory.validator(ReferenceTypeSourceExternalApiConfigurationPersist.ReferenceTypeSourceExternalApiConfigurationPersistValidator.class)), + this.navSpec() + .iff(() -> !this.isNull(item.getSources())) + .on(ReferenceTypeDefinitionPersist._sources) + .over(item.getSources().stream().filter(x -> x.getType() == ReferenceTypeSourceType.STATIC).toList()) + .using(() -> this.validatorFactory.validator(ReferenceTypeSourceStaticOptionConfigurationPersist.ReferenceTypeSourceStaticOptionConfigurationPersistValidator.class)) + ); + } + } - public void setSources(List sources) { - this.sources = sources; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeFieldPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeFieldPersist.java index 8dfff57d4..1b26cf6a9 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeFieldPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeFieldPersist.java @@ -1,10 +1,16 @@ package eu.eudat.model.persist.referencetypedefinition; 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 jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; +import java.util.List; + public class ReferenceTypeFieldPersist { @NotNull(message = "{validation.empty}") @@ -53,6 +59,24 @@ public class ReferenceTypeFieldPersist { public void setDataType(ReferenceFieldDataType dataType) { this.dataType = dataType; } + + public static class ReferenceTypeFieldPersistValidator extends BaseValidator { + + protected ReferenceTypeFieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors) { + super(conventionService, errors); + } + + @Override + protected Class modelClass() { + return ReferenceTypeFieldPersist.class; + } + + @Override + protected List specifications(ReferenceTypeFieldPersist item) { + return null; + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseConfigurationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseConfigurationPersist.java index 8cba296cc..1b6e7a131 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseConfigurationPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseConfigurationPersist.java @@ -3,11 +3,15 @@ package eu.eudat.model.persist.referencetypedefinition; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; import eu.eudat.commons.enums.ReferenceTypeSourceType; -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.context.MessageSource; +import org.springframework.context.i18n.LocaleContextHolder; +import java.util.Arrays; import java.util.List; @JsonTypeInfo( @@ -21,23 +25,26 @@ import java.util.List; }) public abstract class ReferenceTypeSourceBaseConfigurationPersist { - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") private String key = null; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") + public static final String _key = "key"; + private String label = null; - @NotNull(message = "{validation.empty}") + public static final String _label = "label"; + private Integer ordinal = null; - @ValidEnum(message = "{validation.empty}") + public static final String _ordinal = "ordinal"; + private ReferenceTypeSourceType type; - @Valid + public static final String _type = "type"; + private List dependencies; + public static final String _dependencies = "dependencies"; + public String getKey() { return key; } @@ -77,4 +84,45 @@ public abstract class ReferenceTypeSourceBaseConfigurationPersist { public void setDependencies(List dependencies) { this.dependencies = dependencies; } + + public static abstract class ReferenceTypeSourceBaseConfigurationPersistValidator extends BaseValidator { + + protected final MessageSource messageSource; + + protected final ValidatorFactory validatorFactory; + + protected ReferenceTypeSourceBaseConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + protected List getBaseSpecifications(T item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isEmpty(item.getKey())) + .failOn(ReferenceTypeSourceBaseConfigurationPersist._key).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getLabel())) + .failOn(ReferenceTypeSourceBaseConfigurationPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getOrdinal())) + .failOn(ReferenceTypeSourceBaseConfigurationPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._label}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getType())) + .failOn(ReferenceTypeSourceBaseConfigurationPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._label}, LocaleContextHolder.getLocale())), + + this.spec() + .must(() -> !this.isNull(item.getDependencies())) + .failOn(ReferenceTypeSourceBaseConfigurationPersist._dependencies).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._dependencies}, LocaleContextHolder.getLocale())), + this.navSpec() + .iff(() -> !this.isNull(item.getDependencies())) + .on(ReferenceTypeSourceBaseConfigurationPersist._dependencies) + .over(item.getDependencies()) + .using(() -> this.validatorFactory.validator(ReferenceTypeSourceBaseDependencyPersist.ReferenceTypeSourceBaseDependencyPersistValidator.class)) + ); + } + + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseDependencyPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseDependencyPersist.java index f1a88bf8f..8e4cfaf64 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseDependencyPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseDependencyPersist.java @@ -1,28 +1,37 @@ package eu.eudat.model.persist.referencetypedefinition; +import eu.eudat.commons.validation.BaseValidator; +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.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.stereotype.Component; +import java.util.Arrays; import java.util.List; public class ReferenceTypeSourceBaseDependencyPersist { - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") private String referenceTypeCode; - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") + public static final String _referenceTypeCode = "referenceTypeCode"; + private String key; - @NotNull(message = "{validation.empty}") + public static final String _key = "key"; + private Boolean required; - @NotNull(message = "{validation.empty}") - @Valid + public static final String _required = "required"; + private List properties; + public static final String _properties = "properties"; public String getReferenceTypeCode() { return referenceTypeCode; @@ -55,4 +64,31 @@ public class ReferenceTypeSourceBaseDependencyPersist { public void setProperties(List properties) { this.properties = properties; } + + @Component(ReferenceTypeSourceBaseDependencyPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class ReferenceTypeSourceBaseDependencyPersistValidator extends BaseValidator { + + public static final String ValidatorName = "ReferenceTypeSourceBaseDependencyPersistValidator"; + + private final MessageSource messageSource; + + protected ReferenceTypeSourceBaseDependencyPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return ReferenceTypeSourceBaseDependencyPersist.class; + } + + @Override + protected List specifications(ReferenceTypeSourceBaseDependencyPersist item) { + return Arrays.asList( + + ); + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceExternalApiConfigurationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceExternalApiConfigurationPersist.java index 07b5cb5bf..351f95969 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceExternalApiConfigurationPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceExternalApiConfigurationPersist.java @@ -1,14 +1,19 @@ package eu.eudat.model.persist.referencetypedefinition; import eu.eudat.commons.enums.ReferenceTypeExternalApiHTTPMethodType; +import eu.eudat.commons.validation.ValidatorFactory; 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 jakarta.validation.Valid; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; +import org.springframework.context.MessageSource; import java.util.List; -public class ReferenceTypeSourceExternalApiConfigurationPersist extends ReferenceTypeSourceBaseConfigurationPersist{ +public class ReferenceTypeSourceExternalApiConfigurationPersist extends ReferenceTypeSourceBaseConfigurationPersist { @NotNull(message = "{validation.empty}") @NotEmpty(message = "{validation.empty}") @@ -31,7 +36,9 @@ public class ReferenceTypeSourceExternalApiConfigurationPersist extends Referenc @ValidEnum(message = "{validation.empty}") private ReferenceTypeExternalApiHTTPMethodType httpMethod; + private String requestBody = ""; + private String filterType = "remote"; @Valid @@ -56,7 +63,6 @@ public class ReferenceTypeSourceExternalApiConfigurationPersist extends Referenc this.results = results; } - public String getPaginationPath() { return paginationPath; } @@ -73,7 +79,6 @@ public class ReferenceTypeSourceExternalApiConfigurationPersist extends Referenc this.contentType = contentType; } - public String getFirstPage() { return firstPage; } @@ -121,4 +126,22 @@ public class ReferenceTypeSourceExternalApiConfigurationPersist extends Referenc public void setQueries(List queries) { this.queries = queries; } + + public static class ReferenceTypeSourceExternalApiConfigurationPersistValidator extends ReferenceTypeSourceBaseConfigurationPersistValidator { + + protected ReferenceTypeSourceExternalApiConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors, messageSource, validatorFactory); + } + + @Override + protected Class modelClass() { + return ReferenceTypeSourceExternalApiConfigurationPersist.class; + } + + @Override + protected List specifications(ReferenceTypeSourceExternalApiConfigurationPersist item) { + return null; + } + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceStaticOptionConfigurationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceStaticOptionConfigurationPersist.java index f315dbfb3..36777d1c7 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceStaticOptionConfigurationPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceStaticOptionConfigurationPersist.java @@ -1,7 +1,12 @@ package eu.eudat.model.persist.referencetypedefinition; +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 org.springframework.context.MessageSource; import java.util.List; @@ -17,4 +22,22 @@ public class ReferenceTypeSourceStaticOptionConfigurationPersist extends Referen public void setOptions(List options) { this.options = options; } + + public static class ReferenceTypeSourceStaticOptionConfigurationPersistValidator extends ReferenceTypeSourceBaseConfigurationPersistValidator { + + protected ReferenceTypeSourceStaticOptionConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors, messageSource, validatorFactory); + } + + @Override + protected Class modelClass() { + return ReferenceTypeSourceStaticOptionConfigurationPersist.class; + } + + @Override + protected List specifications(ReferenceTypeSourceStaticOptionConfigurationPersist item) { + return null; + } + } + } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateController.java index 0b3877439..5ed8c5326 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateController.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.DescriptionTemplateEntity; import eu.eudat.model.DescriptionTemplate; import eu.eudat.model.DmpBlueprint; @@ -31,8 +32,8 @@ import org.slf4j.LoggerFactory; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import org.xml.sax.SAXException; @@ -40,7 +41,10 @@ import javax.management.InvalidApplicationException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import java.io.IOException; -import java.util.*; +import java.util.AbstractMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; @RestController @RequestMapping(path = "api/description-template") @@ -88,7 +92,6 @@ public class DescriptionTemplateController { long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.DescriptionTemplate_Query, "lookup", lookup); - //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); return new QueryResult<>(models, count); } @@ -108,14 +111,14 @@ public class DescriptionTemplateController { new AbstractMap.SimpleEntry("id", id), new AbstractMap.SimpleEntry("fields", fieldSet) )); - //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); return model; } @PostMapping("persist") @Transactional - public DescriptionTemplate persist(@MyValidate @RequestBody DescriptionTemplatePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException { + @ValidationFilterAnnotation(validator = DescriptionTemplatePersist.DescriptionTemplatePersistValidator.ValidatorName, argumentName = "model") + public DescriptionTemplate persist(@RequestBody DescriptionTemplatePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException { logger.debug(new MapLogEntry("persisting" + DescriptionTemplate.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); DescriptionTemplate persisted = this.descriptionTemplateTypeService.persist(model, fieldSet); @@ -123,7 +126,7 @@ public class DescriptionTemplateController { new AbstractMap.SimpleEntry("model", model), new AbstractMap.SimpleEntry("fields", fieldSet) )); - //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); + return persisted; } @@ -135,7 +138,6 @@ public class DescriptionTemplateController { this.descriptionTemplateTypeService.deleteAndSave(id); this.auditService.track(AuditableAction.DescriptionTemplate_Delete, "id", id); - //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); } @GetMapping("clone/{id}") @@ -150,14 +152,14 @@ public class DescriptionTemplateController { new AbstractMap.SimpleEntry("id", id), new AbstractMap.SimpleEntry("fields", fieldSet) )); - //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); return model; } @PostMapping("new-version") @Transactional - public DescriptionTemplate createNewVersion(@MyValidate @RequestBody NewVersionDescriptionTemplatePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException { + @ValidationFilterAnnotation(validator = NewVersionDescriptionTemplatePersist.NewVersionDescriptionTemplatePersistValidator.ValidatorName, argumentName = "model") + public DescriptionTemplate createNewVersion(@RequestBody NewVersionDescriptionTemplatePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException { logger.debug(new MapLogEntry("persisting" + NewVersionDescriptionTemplatePersist.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); DescriptionTemplate persisted = this.descriptionTemplateTypeService.createNewVersion(model, fieldSet); @@ -165,21 +167,20 @@ public class DescriptionTemplateController { new AbstractMap.SimpleEntry("model", model), new AbstractMap.SimpleEntry("fields", fieldSet) )); - //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); + return persisted; } - - @RequestMapping(method = RequestMethod.GET, value = {"/xml/export/{id}"}, produces = "application/xml") - public @ResponseBody ResponseEntity getXml(@PathVariable UUID id) throws JAXBException, ParserConfigurationException, IOException, TransformerException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException { + public @ResponseBody ResponseEntity getXml(@PathVariable UUID id) throws JAXBException, ParserConfigurationException, IOException, TransformerException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException { logger.debug(new MapLogEntry("export" + DescriptionTemplate.class.getSimpleName()).And("id", id)); - ResponseEntity response = this.descriptionTemplateTypeService.exportXml(id); + ResponseEntity response = this.descriptionTemplateTypeService.exportXml(id); this.auditService.track(AuditableAction.DescriptionTemplate_GetXml, Map.ofEntries( new AbstractMap.SimpleEntry("id", id) )); + return response; } @@ -196,7 +197,6 @@ public class DescriptionTemplateController { new AbstractMap.SimpleEntry("id", id), new AbstractMap.SimpleEntry("fields", fieldSet) )); - //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); return model; } @@ -210,7 +210,6 @@ public class DescriptionTemplateController { this.auditService.track(AuditableAction.DescriptionTemplate_GetSemantics, Map.ofEntries( new AbstractMap.SimpleEntry("query", query) )); - //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); return semantics; } 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 19a0ac613..4dd444d65 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 @@ -121,7 +121,7 @@ public class DmpController { @PostMapping("persist") @Transactional @ValidationFilterAnnotation(validator = DmpPersist.DmpPersistValidator.ValidatorName, argumentName = "model") - public Dmp Persist(@MyValidate @RequestBody DmpPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException { + public Dmp Persist(@RequestBody DmpPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException { logger.debug(new MapLogEntry("persisting" + Dmp.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); Dmp persisted = this.dmpService.persist(model, fieldSet); @@ -164,7 +164,8 @@ public class DmpController { @PostMapping("new-version") @Transactional - public Dmp createNewVersion(@MyValidate @RequestBody NewVersionDmpPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, JAXBException, JsonProcessingException, TransformerException, InvalidApplicationException, ParserConfigurationException { + @ValidationFilterAnnotation(validator = NewVersionDmpPersist.NewVersionDmpPersistValidator.ValidatorName, argumentName = "model") + public Dmp createNewVersion(@RequestBody NewVersionDmpPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, JAXBException, JsonProcessingException, TransformerException, InvalidApplicationException, ParserConfigurationException { logger.debug(new MapLogEntry("persisting" + NewVersionDmpPersist.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); Dmp persisted = this.dmpService.createNewVersion(model, fieldSet); @@ -179,7 +180,8 @@ public class DmpController { @PostMapping("{id}/assign-users") @Transactional - public QueryResult assignUsers(@PathVariable("id") UUID id, @MyValidate @RequestBody List model, FieldSet fieldSet) throws InvalidApplicationException { + @ValidationFilterAnnotation(validator = DmpUserPersist.DmpUserPersistValidator.ValidatorName, argumentName = "model") + public QueryResult assignUsers(@PathVariable("id") UUID id, @RequestBody List model, FieldSet fieldSet) throws InvalidApplicationException { logger.debug(new MapLogEntry("assigning users to dmp").And("model", model).And("fieldSet", fieldSet)); List persisted = this.dmpService.assignUsers(id, model, fieldSet); @@ -194,7 +196,8 @@ public class DmpController { @PostMapping("remove-user") @Transactional - public QueryResult removeUser(@MyValidate @RequestBody DmpUserRemovePersist model, FieldSet fieldSet) throws InvalidApplicationException { + @ValidationFilterAnnotation(validator = DmpUserRemovePersist.DmpUserRemovePersistValidator.ValidatorName, argumentName = "model") + public QueryResult removeUser(@RequestBody DmpUserRemovePersist model, FieldSet fieldSet) throws InvalidApplicationException { logger.debug(new MapLogEntry("remove user from dmp").And("model", model).And("fieldSet", fieldSet)); Dmp persisted = this.dmpService.removeUser(model, fieldSet); @@ -216,7 +219,8 @@ public class DmpController { @PostMapping("{id}/invite-users") @Transactional - public ResponseEntity inviteUsers(@PathVariable("id") UUID id, @MyValidate @RequestBody DmpUserInvitePersist model) throws InvalidApplicationException, JAXBException { + @ValidationFilterAnnotation(validator = DmpUserInvitePersist.DmpUserInvitePersistValidator.ValidatorName, argumentName = "model") + public ResponseEntity> inviteUsers(@PathVariable("id") UUID id,@RequestBody DmpUserInvitePersist model) throws InvalidApplicationException, JAXBException { logger.debug(new MapLogEntry("inviting users to dmp").And("model", model)); this.dmpService.inviteUsers(id, model); @@ -230,7 +234,7 @@ public class DmpController { @GetMapping("{id}/token/{token}/invite-accept") @Transactional - public ResponseEntity acceptInvitation(@PathVariable("id") UUID id, @PathVariable("token") String token) throws InvalidApplicationException, JAXBException { + public ResponseEntity> acceptInvitation(@PathVariable("id") UUID id, @PathVariable("token") String token) throws InvalidApplicationException, JAXBException { logger.debug(new MapLogEntry("inviting users to dmp").And("id", id)); this.dmpService.dmpInvitationAccept(token); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/EntityDoiController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/EntityDoiController.java index ac8e8b1ea..1de7e164a 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/EntityDoiController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/EntityDoiController.java @@ -2,6 +2,7 @@ package eu.eudat.controllers.v2; import eu.eudat.audit.AuditableAction; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.validation.ValidationFilterAnnotation; import eu.eudat.data.EntityDoiEntity; import eu.eudat.model.DescriptionTemplateType; import eu.eudat.model.EntityDoi; @@ -23,7 +24,6 @@ import gr.cite.tools.exception.MyNotFoundException; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; -import gr.cite.tools.validation.MyValidate; import org.slf4j.LoggerFactory; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; @@ -44,6 +44,7 @@ public class EntityDoiController { private final AuditService auditService; private final EntityDoiService entityDoiService; + private final DepositService repositoryDepositService; private final CensorFactory censorFactory; @@ -106,7 +107,8 @@ public class EntityDoiController { @PostMapping("persist") @Transactional - public EntityDoi Persist(@MyValidate @RequestBody EntityDoiPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException { + @ValidationFilterAnnotation(validator = EntityDoiPersist.EntityDoiPersistValidator.ValidatorName, argumentName = "model") + public EntityDoi Persist(@RequestBody EntityDoiPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException { logger.debug(new MapLogEntry("persisting" + DescriptionTemplateType.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); EntityDoi persisted = this.entityDoiService.persist(model, fieldSet); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/LanguageV2Controller.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/LanguageV2Controller.java index ca361c401..065bbe603 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/LanguageV2Controller.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/LanguageV2Controller.java @@ -3,7 +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.authorization.Permission; +import eu.eudat.commons.validation.ValidationFilterAnnotation; import eu.eudat.data.LanguageEntity; import eu.eudat.model.Language; import eu.eudat.model.builder.LanguageBuilder; @@ -24,20 +24,20 @@ import gr.cite.tools.exception.MyNotFoundException; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; -import gr.cite.tools.validation.MyValidate; import jakarta.transaction.Transactional; import jakarta.xml.bind.JAXBException; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import javax.management.InvalidApplicationException; import java.io.IOException; -import java.util.*; +import java.util.AbstractMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; import java.util.stream.Collectors; @RestController @@ -45,13 +45,21 @@ import java.util.stream.Collectors; public class LanguageV2Controller { private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(LanguageV2Controller.class)); + private final BuilderFactory builderFactory; + private final AuditService auditService; + private final CensorFactory censorFactory; + private final QueryFactory queryFactory; + private final MessageSource messageSource; + private final AuthorizationService authorizationService; + private final LanguageService languageService; + @Autowired public LanguageV2Controller( BuilderFactory builderFactory, @@ -82,7 +90,7 @@ public class LanguageV2Controller { this.auditService.track(AuditableAction.Language_Query, "lookup", lookup); - return new QueryResult(models, count); + return new QueryResult<>(models, count); } @GetMapping("{id}") @@ -116,7 +124,7 @@ public class LanguageV2Controller { if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{code, Language.class.getSimpleName()}, LocaleContextHolder.getLocale())); - if (model.getPayload() == null){ + if (model.getPayload() == null) { model.setPayload(this.languageService.getPayload(code)); } this.auditService.track(AuditableAction.Language_Lookup, Map.ofEntries( @@ -139,12 +147,13 @@ public class LanguageV2Controller { long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); - return new QueryResult<>(models.stream().map(x -> x.getCode()).collect(Collectors.toList()), count); + return new QueryResult<>(models.stream().map(Language::getCode).collect(Collectors.toList()), count); } @PostMapping("persist") @Transactional - public Language persist(@MyValidate @RequestBody LanguagePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, JsonProcessingException, InvalidApplicationException { + @ValidationFilterAnnotation(validator = LanguagePersist.LanguagePersistValidator.ValidatorName, argumentName = "model") + public Language persist(@RequestBody LanguagePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, JsonProcessingException, InvalidApplicationException { logger.debug(new MapLogEntry("persisting" + Language.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); this.censorFactory.censor(LanguageCensor.class).censor(fieldSet, null); @@ -161,7 +170,7 @@ public class LanguageV2Controller { @DeleteMapping("{id}") @Transactional public void delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException { - logger.debug(new MapLogEntry("retrieving" + Language.class.getSimpleName()).And("id", id)); + logger.debug(new MapLogEntry("retrieving" + Language.class.getSimpleName()).And("id", id)); this.languageService.deleteAndSave(id); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/LockController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/LockController.java index 930259423..69a66b93f 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/LockController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/LockController.java @@ -3,6 +3,7 @@ package eu.eudat.controllers.v2; import eu.eudat.audit.AuditableAction; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.Permission; +import eu.eudat.commons.validation.ValidationFilterAnnotation; import eu.eudat.data.LockEntity; import eu.eudat.model.Lock; import eu.eudat.model.builder.LockBuilder; @@ -47,140 +48,142 @@ import java.util.UUID; @RequestMapping(path = {"api/lock"}) public class LockController { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(LockController.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(LockController.class)); - private final BuilderFactory builderFactory; + private final BuilderFactory builderFactory; - private final AuditService auditService; + private final AuditService auditService; - private final LockService lockService; + private final LockService lockService; - private final CensorFactory censorFactory; + private final CensorFactory censorFactory; - private final QueryFactory queryFactory; + private final QueryFactory queryFactory; - private final MessageSource messageSource; - private final AuthorizationService authService; + private final MessageSource messageSource; - @Autowired - public LockController(BuilderFactory builderFactory, - AuditService auditService, - LockService lockService, - CensorFactory censorFactory, - QueryFactory queryFactory, - MessageSource messageSource, AuthorizationService authService) { - this.builderFactory = builderFactory; - this.auditService = auditService; - this.lockService = lockService; - this.censorFactory = censorFactory; - this.queryFactory = queryFactory; - this.messageSource = messageSource; - this.authService = authService; - } + private final AuthorizationService authService; - @PostMapping("query") - public QueryResult query(@RequestBody LockLookup lookup) throws MyApplicationException, MyForbiddenException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { - logger.debug("querying {}", Lock.class.getSimpleName()); + @Autowired + public LockController(BuilderFactory builderFactory, + AuditService auditService, + LockService lockService, + CensorFactory censorFactory, + QueryFactory queryFactory, + MessageSource messageSource, AuthorizationService authService) { + this.builderFactory = builderFactory; + this.auditService = auditService; + this.lockService = lockService; + this.censorFactory = censorFactory; + this.queryFactory = queryFactory; + this.messageSource = messageSource; + this.authService = authService; + } - this.censorFactory.censor(LockCensor.class).censor(lookup.getProject(), null); + @PostMapping("query") + public QueryResult query(@RequestBody LockLookup lookup) throws MyApplicationException, MyForbiddenException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { + logger.debug("querying {}", Lock.class.getSimpleName()); - LockQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); - List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(LockBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); - long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); + this.censorFactory.censor(LockCensor.class).censor(lookup.getProject(), null); - this.auditService.track(AuditableAction.Lock_Query, "lookup", lookup); + LockQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + List data = query.collectAs(lookup.getProject()); + List models = this.builderFactory.builder(LockBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); - return new QueryResult<>(models, count); - } + this.auditService.track(AuditableAction.Lock_Query, "lookup", lookup); - @GetMapping("{id}") - public Lock get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException { - logger.debug(new MapLogEntry("retrieving" + Lock.class.getSimpleName()).And("id", id).And("fields", fieldSet)); + return new QueryResult<>(models, count); + } - this.censorFactory.censor(LockCensor.class).censor(fieldSet, null); + @GetMapping("{id}") + public Lock get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException { + logger.debug(new MapLogEntry("retrieving" + Lock.class.getSimpleName()).And("id", id).And("fields", fieldSet)); - LockQuery query = this.queryFactory.query(LockQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - Lock model = this.builderFactory.builder(LockBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); - if (model == null) - throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Lock.class.getSimpleName()}, LocaleContextHolder.getLocale())); + this.censorFactory.censor(LockCensor.class).censor(fieldSet, null); - this.auditService.track(AuditableAction.Lock_Lookup, Map.ofEntries( - new AbstractMap.SimpleEntry("id", id), - new AbstractMap.SimpleEntry("fields", fieldSet) - )); + LockQuery query = this.queryFactory.query(LockQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); + Lock model = this.builderFactory.builder(LockBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + if (model == null) + throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Lock.class.getSimpleName()}, LocaleContextHolder.getLocale())); - return model; - } + this.auditService.track(AuditableAction.Lock_Lookup, Map.ofEntries( + new AbstractMap.SimpleEntry("id", id), + new AbstractMap.SimpleEntry("fields", fieldSet) + )); - @PostMapping("persist") - @Transactional - public Lock persist(@MyValidate @RequestBody LockPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException { - logger.debug(new MapLogEntry("persisting" + Lock.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); - this.censorFactory.censor(LockCensor.class).censor(fieldSet, null); + return model; + } - Lock persisted = this.lockService.persist(model, fieldSet); + @PostMapping("persist") + @Transactional + @ValidationFilterAnnotation(validator = LockPersist.LockPersistValidator.ValidatorName, argumentName = "model") + public Lock persist(@MyValidate @RequestBody LockPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException { + logger.debug(new MapLogEntry("persisting" + Lock.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); + this.censorFactory.censor(LockCensor.class).censor(fieldSet, null); - this.auditService.track(AuditableAction.Lock_Persist, Map.ofEntries( - new AbstractMap.SimpleEntry("model", model), - new AbstractMap.SimpleEntry("fields", fieldSet) - )); + Lock persisted = this.lockService.persist(model, fieldSet); - return persisted; - } + this.auditService.track(AuditableAction.Lock_Persist, Map.ofEntries( + new AbstractMap.SimpleEntry("model", model), + new AbstractMap.SimpleEntry("fields", fieldSet) + )); - @GetMapping("target/{id}") - public Lock getWithTarget(@PathVariable("id") UUID targetId, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException { - logger.debug(new MapLogEntry("retrieving" + Lock.class.getSimpleName()).And("targetId", targetId).And("fields", fieldSet)); + return persisted; + } - this.censorFactory.censor(LockCensor.class).censor(fieldSet, null); + @GetMapping("target/{id}") + public Lock getWithTarget(@PathVariable("id") UUID targetId, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException { + logger.debug(new MapLogEntry("retrieving" + Lock.class.getSimpleName()).And("targetId", targetId).And("fields", fieldSet)); - LockQuery query = this.queryFactory.query(LockQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).targetIds(targetId); - Lock model = this.builderFactory.builder(LockBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); - if (model == null) - throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{targetId, Lock.class.getSimpleName()}, LocaleContextHolder.getLocale())); + this.censorFactory.censor(LockCensor.class).censor(fieldSet, null); - this.auditService.track(AuditableAction.Lock_Lookup, Map.ofEntries( - new AbstractMap.SimpleEntry("targetId", targetId), - new AbstractMap.SimpleEntry("fields", fieldSet) - )); + LockQuery query = this.queryFactory.query(LockQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).targetIds(targetId); + Lock model = this.builderFactory.builder(LockBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + if (model == null) + throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{targetId, Lock.class.getSimpleName()}, LocaleContextHolder.getLocale())); - return model; - } + this.auditService.track(AuditableAction.Lock_Lookup, Map.ofEntries( + new AbstractMap.SimpleEntry("targetId", targetId), + new AbstractMap.SimpleEntry("fields", fieldSet) + )); - @Transactional - @GetMapping("target/status/{id}") - public Boolean getLocked(@PathVariable("id") UUID targetId) throws Exception { - logger.debug(new MapLogEntry("is locked" + Lock.class.getSimpleName()).And("targetId", targetId)); - this.authService.authorizeForce(Permission.BrowseLock); + return model; + } - Boolean isLocked = this.lockService.isLocked(targetId); - this.auditService.track(AuditableAction.Lock_IsLocked, Map.ofEntries( - new AbstractMap.SimpleEntry("targetId", targetId) - )); - return isLocked; - } + @Transactional + @GetMapping("target/status/{id}") + public Boolean getLocked(@PathVariable("id") UUID targetId) throws Exception { + logger.debug(new MapLogEntry("is locked" + Lock.class.getSimpleName()).And("targetId", targetId)); + this.authService.authorizeForce(Permission.BrowseLock); - @Transactional - @DeleteMapping("target/unlock/{id}") - public boolean unlock(@PathVariable("id") UUID targetId) throws Exception { - logger.debug(new MapLogEntry("unlock" + Lock.class.getSimpleName()).And("targetId", targetId)); - this.authService.authorizeForce(Permission.BrowseLock); + Boolean isLocked = this.lockService.isLocked(targetId); + this.auditService.track(AuditableAction.Lock_IsLocked, Map.ofEntries( + new AbstractMap.SimpleEntry("targetId", targetId) + )); + return isLocked; + } - this.lockService.unlock(targetId); - this.auditService.track(AuditableAction.Lock_UnLocked, Map.ofEntries( - new AbstractMap.SimpleEntry("targetId", targetId) - )); - return true; - } + @Transactional + @DeleteMapping("target/unlock/{id}") + public boolean unlock(@PathVariable("id") UUID targetId) throws Exception { + logger.debug(new MapLogEntry("unlock" + Lock.class.getSimpleName()).And("targetId", targetId)); + this.authService.authorizeForce(Permission.BrowseLock); - @DeleteMapping("{id}") - @Transactional - public void delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException { - logger.debug(new MapLogEntry("retrieving" + Lock.class.getSimpleName()).And("id", id)); + this.lockService.unlock(targetId); + this.auditService.track(AuditableAction.Lock_UnLocked, Map.ofEntries( + new AbstractMap.SimpleEntry("targetId", targetId) + )); + return true; + } - this.lockService.deleteAndSave(id); + @DeleteMapping("{id}") + @Transactional + public void delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException { + logger.debug(new MapLogEntry("retrieving" + Lock.class.getSimpleName()).And("id", id)); - this.auditService.track(AuditableAction.Lock_Delete, "id", id); - } + this.lockService.deleteAndSave(id); + + this.auditService.track(AuditableAction.Lock_Delete, "id", id); + } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ReferenceController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ReferenceController.java index b37a8afda..a2152352b 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ReferenceController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ReferenceController.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import eu.eudat.audit.AuditableAction; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.Permission; +import eu.eudat.commons.validation.ValidationFilterAnnotation; import eu.eudat.controllers.BaseController; import eu.eudat.data.ReferenceEntity; import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; @@ -32,7 +33,6 @@ import gr.cite.tools.exception.MyNotFoundException; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; -import gr.cite.tools.validation.MyValidate; import jakarta.transaction.Transactional; import jakarta.xml.bind.JAXBException; import org.slf4j.LoggerFactory; @@ -56,12 +56,19 @@ import java.util.UUID; public class ReferenceController extends BaseController { private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceController.class)); + private final BuilderFactory builderFactory; + private final AuditService auditService; + private final ReferenceService referenceService; + private final CensorFactory censorFactory; + private final QueryFactory queryFactory; + private final MessageSource messageSource; + private final AuthorizationService authorizationService; @Autowired @@ -96,19 +103,19 @@ public class ReferenceController extends BaseController { this.auditService.track(AuditableAction.Reference_Query, "lookup", lookup); - return new QueryResult(models, count); + return new QueryResult<>(models, count); } @PostMapping("search") public @ResponseBody ResponseEntity>> searchReference(@RequestBody ReferenceSearchLookup lookup) throws HugeResultSet, NoURLFound, InvalidApplicationException { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); - // ReferenceType referenceType = ReferenceType.of((short) externalType); + // ReferenceType referenceType = ReferenceType.of((short) externalType); - if (lookup.getType() != null){ + if (lookup.getType() != null) { List references = this.referenceService.searchReference(lookup); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(references)); } - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE)); } @PostMapping("search-with-db-definition") @@ -140,7 +147,8 @@ public class ReferenceController extends BaseController { @PostMapping("persist") @Transactional - public Reference persist(@MyValidate @RequestBody ReferencePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException { + @ValidationFilterAnnotation(validator = ReferencePersist.ReferencePersistValidator.ValidatorName, argumentName = "model") + public Reference persist(@RequestBody ReferencePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException { logger.debug(new MapLogEntry("persisting" + Reference.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); this.censorFactory.censor(ReferenceCensor.class).censor(fieldSet, null); @@ -150,7 +158,7 @@ public class ReferenceController extends BaseController { new AbstractMap.SimpleEntry("model", model), new AbstractMap.SimpleEntry("fields", fieldSet) )); - //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); + return persisted; } @@ -169,7 +177,7 @@ public class ReferenceController extends BaseController { @DeleteMapping("{id}") @Transactional public void delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException { - logger.debug(new MapLogEntry("retrieving" + Reference.class.getSimpleName()).And("id", id)); + logger.debug(new MapLogEntry("retrieving" + Reference.class.getSimpleName()).And("id", id)); this.referenceService.deleteAndSave(id);