Implementing validators for Description related persist models, action confirmation and dmp clone persist (in progress)

This commit is contained in:
Thomas Georgios Giannos 2023-12-21 18:45:49 +02:00
parent 62970ebd35
commit 63ffeabe62
16 changed files with 755 additions and 156 deletions

View File

@ -35,6 +35,14 @@ public abstract class BaseValidator<T> extends AbstractValidator<T> {
protected Boolean isEmpty(String value) { protected Boolean isEmpty(String value) {
return this.conventionService.isNullOrEmpty(value); return this.conventionService.isNullOrEmpty(value);
} }
protected Boolean isNull(Object value) {
return value == null;
}
protected Boolean isNull(Collection<?> value) {
return value == null;
}
protected Boolean lessEqual(String value, int size) { protected Boolean lessEqual(String value, int size) {
return value.length() <= size; return value.length() <= size;
} }

View File

@ -2,49 +2,60 @@ package eu.eudat.model.persist;
import eu.eudat.commons.enums.ActionConfirmationStatus; import eu.eudat.commons.enums.ActionConfirmationStatus;
import eu.eudat.commons.enums.ActionConfirmationType; import eu.eudat.commons.enums.ActionConfirmationType;
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.old.ValidEnum; import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.commons.validation.old.ValidId; import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.persist.actionconfirmation.DmpInvitationPersist; import eu.eudat.model.persist.actionconfirmation.DmpInvitationPersist;
import eu.eudat.model.persist.actionconfirmation.EmailConfirmationPersist; import eu.eudat.model.persist.actionconfirmation.EmailConfirmationPersist;
import jakarta.validation.Valid; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import jakarta.validation.constraints.NotEmpty; import org.springframework.context.MessageSource;
import jakarta.validation.constraints.NotNull; import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.time.Instant; import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.UUID; import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class ActionConfirmationPersist { public class ActionConfirmationPersist {
@ValidId(message = "{validation.invalidid}")
private UUID id; private UUID id;
@ValidEnum(message = "{validation.empty}")
private ActionConfirmationType type; private ActionConfirmationType type;
@ValidEnum(message = "{validation.empty}") private static final String _type = "type";
private ActionConfirmationStatus status; private ActionConfirmationStatus status;
@NotNull(message = "{validation.empty}") private static final String _status = "status";
@NotEmpty(message = "{validation.empty}")
private String token; private String token;
@Valid private static final String _token = "token";
private DmpInvitationPersist dmpInvitation; private DmpInvitationPersist dmpInvitation;
@Valid private static final String _dmpInvitation = "dmpInvitation";
private EmailConfirmationPersist emailConfirmation; private EmailConfirmationPersist emailConfirmation;
@NotNull(message = "{validation.empty}") private static final String _emailConfirmation = "emailConfirmation";
@Valid
private Instant expiresAt; private Instant expiresAt;
@NotNull(message = "{validation.empty}") private static final String _expiresAt = "expiresAt";
@Valid
private UUID createdById; private UUID createdById;
private static final String _createdById = "createdById";
private String hash; private String hash;
private static final String _hash = "hash";
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -116,6 +127,70 @@ public class ActionConfirmationPersist {
public void setHash(String hash) { public void setHash(String hash) {
this.hash = hash; this.hash = hash;
} }
@Component(ActionConfirmationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ActionConfirmationPersistValidator extends BaseValidator<ActionConfirmationPersist> {
public static final String ValidatorName = "ActionConfirmationPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
public ActionConfirmationPersistValidator(MessageSource messageSource, ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<ActionConfirmationPersist> modelClass() {
return ActionConfirmationPersist.class;
}
@Override
protected List<Specification> specifications(ActionConfirmationPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(ActionConfirmationPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{ActionConfirmationPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(ActionConfirmationPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getType()))
.failOn(ActionConfirmationPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ActionConfirmationPersist._type}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getStatus()))
.failOn(ActionConfirmationPersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{ActionConfirmationPersist._status}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getToken()))
.failOn(ActionConfirmationPersist._token).failWith(messageSource.getMessage("Validation_Required", new Object[]{ActionConfirmationPersist._token}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getExpiresAt()))
.failOn(ActionConfirmationPersist._expiresAt).failWith(messageSource.getMessage("Validation_Required", new Object[]{ActionConfirmationPersist._expiresAt}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getCreatedById()))
.failOn(ActionConfirmationPersist._createdById).failWith(messageSource.getMessage("Validation_Required", new Object[]{ActionConfirmationPersist._createdById}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getDmpInvitation()))
.on(ActionConfirmationPersist._dmpInvitation)
.over(item.getDmpInvitation())
.using(() -> this.validatorFactory.validator(DmpInvitationPersist.DmpInvitationPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getEmailConfirmation()))
.on(ActionConfirmationPersist._emailConfirmation)
.over(item.getEmailConfirmation())
.using(() -> this.validatorFactory.validator(EmailConfirmationPersist.EmailConfirmationPersistValidator.class))
);
}
}
} }

View File

@ -1,30 +1,38 @@
package eu.eudat.model.persist; package eu.eudat.model.persist;
import eu.eudat.commons.validation.old.ValidId; import eu.eudat.commons.validation.BaseValidator;
import jakarta.validation.constraints.NotEmpty; import eu.eudat.commons.validation.specification.Specification;
import jakarta.validation.constraints.NotNull; import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.apache.commons.compress.utils.Lists; import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
public class CloneDmpPersist { public class CloneDmpPersist {
@NotNull(message = "{validation.empty}")
@ValidId(message = "{validation.invalidid}")
private UUID id = null; private UUID id = null;
@NotNull(message = "{validation.empty}") public static final String _id = "id";
@NotEmpty(message = "{validation.empty}")
private String label = null; private String label = null;
@NotNull(message = "{validation.empty}") public static final String _label = "label";
@NotEmpty(message = "{validation.empty}")
private String description = null; private String description = null;
@NotNull(message = "{validation.empty}") public static final String _description = "description";
private List<UUID> descriptions = Lists.newArrayList(); private List<UUID> descriptions = Lists.newArrayList();
public static final String _descriptions = "descriptions";
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -56,4 +64,42 @@ public class CloneDmpPersist {
public void setDescriptions(List<UUID> descriptions) { public void setDescriptions(List<UUID> descriptions) {
this.descriptions = descriptions; this.descriptions = descriptions;
} }
@Component(CloneDmpPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class CloneDmpPersistValidator extends BaseValidator<CloneDmpPersist> {
public static final String ValidatorName = "CloneDmpPersistValidator";
private final MessageSource messageSource;
protected CloneDmpPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<CloneDmpPersist> modelClass() {
return CloneDmpPersist.class;
}
@Override
protected List<Specification> specifications(CloneDmpPersist item) {
return Arrays.asList(
this.spec()
.must(() -> this.isValidGuid(item.getId()))
.failOn(CloneDmpPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{CloneDmpPersist._id}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> this.isEmpty(item.getLabel()))
.failOn(CloneDmpPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{CloneDmpPersist._label}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> this.isEmpty(item.getDescription()))
.failOn(CloneDmpPersist._description).failWith(messageSource.getMessage("Validation_Required", new Object[]{CloneDmpPersist._description}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> this.isNull(item.getDescriptions()))
.failOn(CloneDmpPersist._descriptions).failWith(messageSource.getMessage("Validation_Required", new Object[]{CloneDmpPersist._descriptions}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,61 +1,70 @@
package eu.eudat.model.persist; package eu.eudat.model.persist;
import eu.eudat.commons.enums.DescriptionStatus; import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
import eu.eudat.commons.validation.old.ValidEnum; import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.commons.validation.old.ValidId; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionEntity; import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist; import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull; 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.List;
import java.util.UUID; import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}") @FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class DescriptionPersist { public class DescriptionPersist {
@ValidId(message = "{validation.invalidid}")
private UUID id; private UUID id;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = DescriptionEntity._labelLength, message = "{validation.largerthanmax}")
private String label; private String label;
@NotNull(message = "{validation.empty}") public static final String _label = "label";
@ValidId(message = "{validation.invalidid}")
public static final int _labelLength = 250;
private UUID dmpId; private UUID dmpId;
@NotNull(message = "{validation.empty}") public static final String _dmpId = "dmpId";
@ValidId(message = "{validation.invalidid}")
private UUID dmpDescriptionTemplateId; private UUID dmpDescriptionTemplateId;
@NotNull(message = "{validation.empty}") public static final String _dmpDescriptionTemplateId = "dmpDescriptionTemplateId";
@ValidId(message = "{validation.invalidid}")
private UUID descriptionTemplateId; private UUID descriptionTemplateId;
@ValidEnum(message = "{validation.empty}") public static final String _descriptionTemplateId = "descriptionTemplateId";
private DescriptionStatus status; private DescriptionStatus status;
public static final String _status = "status";
private String description; private String description;
@NotNull(message = "{validation.empty}")
@Valid
private PropertyDefinitionPersist properties; private PropertyDefinitionPersist properties;
@NotNull(message = "{validation.empty}") public static final String _properties = "properties";
@Valid
private List<String> tags; private List<String> tags;
@NotNull(message = "{validation.empty}") public static final String _tags = "tags";
@Valid
private List<DescriptionReferencePersist> references; private List<DescriptionReferencePersist> references;
public static final String _references = "references";
private String hash; private String hash;
public static final String _hash = "hash";
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -143,4 +152,80 @@ public class DescriptionPersist {
public void setDescriptionTemplateId(UUID descriptionTemplateId) { public void setDescriptionTemplateId(UUID descriptionTemplateId) {
this.descriptionTemplateId = descriptionTemplateId; this.descriptionTemplateId = descriptionTemplateId;
} }
@Component(DescriptionPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DescriptionPersistValidator extends BaseValidator<DescriptionPersist> {
public static final String ValidatorName = "DescriptionPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected DescriptionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<DescriptionPersist> modelClass() {
return DescriptionPersist.class;
}
@Override
protected List<Specification> specifications(DescriptionPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(DescriptionPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(DescriptionPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getLabel()))
.failOn(DescriptionPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._label}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getLabel()))
.must(() -> this.lessEqual(item.getLabel(), DescriptionPersist._labelLength))
.failOn(DescriptionPersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DescriptionPersist._label}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> this.isValidGuid(item.getDmpId()))
.failOn(DescriptionPersist._dmpId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._dmpId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> this.isValidGuid(item.getDescriptionTemplateId()))
.failOn(DescriptionPersist._descriptionTemplateId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._descriptionTemplateId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> this.isValidGuid(item.getDmpDescriptionTemplateId()))
.failOn(DescriptionPersist._dmpDescriptionTemplateId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._dmpDescriptionTemplateId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getStatus()))
.failOn(DescriptionPersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._status}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getTags()))
.failOn(DescriptionPersist._tags).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._tags}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getProperties()))
.failOn(DescriptionPersist._properties).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._properties}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getProperties()))
.on(DescriptionPersist._properties)
.over(item.getProperties())
.using(() -> this.validatorFactory.validator(PropertyDefinitionPersist.PropertyDefinitionPersistValidator.class)),
this.spec()
.must(() -> !this.isNull(item.getReferences()))
.failOn(DescriptionPersist._references).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._references}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getReferences()))
.on(DescriptionPersist._references)
.over(item.getReferences())
.using(() -> this.validatorFactory.validator(DescriptionReferencePersist.DescriptionReferencePersistValidator.class))
);
}
}
} }

View File

@ -1,24 +1,32 @@
package eu.eudat.model.persist; package eu.eudat.model.persist;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; import java.util.Arrays;
import eu.eudat.commons.validation.old.ValidId; import java.util.List;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.util.UUID; import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class DescriptionReferencePersist { public class DescriptionReferencePersist {
@ValidId(message = "{validation.invalidid}")
private UUID id; private UUID id;
@NotNull(message = "{validation.empty}")
@Valid
private ReferencePersist reference = null; private ReferencePersist reference = null;
public static final String _reference = "reference";
private String hash; private String hash;
public static final String _hash = "hash";
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -42,6 +50,52 @@ public class DescriptionReferencePersist {
public void setHash(String hash) { public void setHash(String hash) {
this.hash = hash; this.hash = hash;
} }
@Component(DescriptionReferencePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DescriptionReferencePersistValidator extends BaseValidator<DescriptionReferencePersist> {
public static final String ValidatorName = "DescriptionReferencePersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected DescriptionReferencePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<DescriptionReferencePersist> modelClass() {
return DescriptionReferencePersist.class;
}
@Override
protected List<Specification> specifications(DescriptionReferencePersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(DescriptionReferencePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferencePersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(DescriptionReferencePersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getReference()))
.failOn(DescriptionReferencePersist._reference).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferencePersist._reference}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getReference()))
.on(DescriptionReferencePersist._reference)
.over(item.getReference())
.using(() -> this.validatorFactory.validator(ReferencePersist.ReferencePersistValidator.class))
);
}
}
} }

View File

@ -1,53 +1,74 @@
package eu.eudat.model.persist; package eu.eudat.model.persist;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.commons.enums.ReferenceSourceType; import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.commons.validation.old.ValidEnum; import eu.eudat.commons.validation.old.ValidEnum;
import eu.eudat.commons.validation.old.ValidId; import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.persist.referencedefinition.DefinitionPersist; import eu.eudat.model.persist.referencedefinition.DefinitionPersist;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size; import 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; import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class ReferencePersist { public class ReferencePersist {
@ValidId(message = "{validation.invalidid}")
private UUID id; private UUID id;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = 250, message = "{validation.largerthanmax}")
private String label; private String label;
@ValidEnum(message = "{validation.empty}") public static final String _label = "label";
public static final int _labelLength = 250;
private ReferenceType type; private ReferenceType type;
public static final String _type = "type";
private String description; private String description;
@Valid
private DefinitionPersist definition; private DefinitionPersist definition;
@NotNull(message = "{validation.empty}") public static final String _definition = "definition";
@NotEmpty(message = "{validation.empty}")
@Size(max = 1024, message = "{validation.largerthanmax}")
private String reference; private String reference;
public static final String _reference = "reference";
public static final int _referenceLength = 1024;
@Size(max = 50, message = "{validation.largerthanmax}") @Size(max = 50, message = "{validation.largerthanmax}")
private String abbreviation; private String abbreviation;
public static final String _abbreviation = "abbreviation";
public static final int _abbreviationLength = 50;
@Size(max = 1024, message = "{validation.largerthanmax}") @Size(max = 1024, message = "{validation.largerthanmax}")
private String source; private String source;
public static final String _source = "source";
public static final int _sourceLength = 1024;
@ValidEnum(message = "{validation.empty}") @ValidEnum(message = "{validation.empty}")
private ReferenceSourceType sourceType; private ReferenceSourceType sourceType;
public static final String _sourceType = "sourceType";
private String hash; private String hash;
public static final String _hash = "hash";
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -127,4 +148,84 @@ public class ReferencePersist {
public void setHash(String hash) { public void setHash(String hash) {
this.hash = hash; this.hash = hash;
} }
@Component(ReferencePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ReferencePersistValidator extends BaseValidator<ReferencePersist> {
public static final String ValidatorName = "ReferencePersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected ReferencePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<ReferencePersist> modelClass() {
return ReferencePersist.class;
}
@Override
protected List<Specification> specifications(ReferencePersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(ReferencePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(ReferencePersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getLabel()))
.failOn(ReferencePersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._label}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getLabel()))
.must(() -> this.lessEqual(item.getLabel(), ReferencePersist._labelLength))
.failOn(ReferencePersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._label}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getType()))
.failOn(ReferencePersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._type}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getReference()))
.failOn(ReferencePersist._reference).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._reference}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getReference()))
.must(() -> this.lessEqual(item.getReference(), ReferencePersist._referenceLength))
.failOn(ReferencePersist._reference).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._reference}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getAbbreviation()))
.failOn(ReferencePersist._abbreviation).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._abbreviation}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getAbbreviation()))
.must(() -> this.lessEqual(item.getAbbreviation(), ReferencePersist._abbreviationLength))
.failOn(ReferencePersist._abbreviation).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._abbreviation}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getSource()))
.failOn(ReferencePersist._source).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._source}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getSource()))
.must(() -> this.lessEqual(item.getSource(), ReferencePersist._sourceLength))
.failOn(ReferencePersist._source).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._source}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getSourceType()))
.failOn(ReferencePersist._sourceType).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._sourceType}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getDefinition()))
.failOn(ReferencePersist._definition).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._definition}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getDefinition()))
.on(ReferencePersist._definition)
.over(item.getDefinition())
.using(() -> this.validatorFactory.validator(DefinitionPersist.DefinitionPersistValidator.class))
);
}
}
} }

View File

@ -1,26 +1,34 @@
package eu.eudat.model.persist.actionconfirmation; package eu.eudat.model.persist.actionconfirmation;
import eu.eudat.commons.enums.DmpUserRole; import eu.eudat.commons.enums.DmpUserRole;
import eu.eudat.commons.validation.old.ValidEnum; import eu.eudat.commons.validation.BaseValidator;
import jakarta.validation.Valid; import eu.eudat.commons.validation.specification.Specification;
import jakarta.validation.constraints.NotEmpty; import eu.eudat.convention.ConventionService;
import jakarta.validation.constraints.NotNull; 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; import java.util.UUID;
public class DmpInvitationPersist { public class DmpInvitationPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String email; private String email;
@NotNull(message = "{validation.empty}") public static final String _email = "email";
@Valid
private UUID dmpId; private UUID dmpId;
@ValidEnum(message = "{validation.empty}") public static final String _dmpId = "dmpId";
private DmpUserRole role; private DmpUserRole role;
public static final String _role = "role";
public DmpInvitationPersist(String email, UUID dmpId, DmpUserRole role) { public DmpInvitationPersist(String email, UUID dmpId, DmpUserRole role) {
this.email = email; this.email = email;
this.dmpId = dmpId; this.dmpId = dmpId;
@ -50,4 +58,39 @@ public class DmpInvitationPersist {
public void setRole(DmpUserRole role) { public void setRole(DmpUserRole role) {
this.role = role; this.role = role;
} }
@Component(DmpInvitationPersistValidator.ValidatorName)
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DmpInvitationPersistValidator extends BaseValidator<DmpInvitationPersist> {
public static final String ValidatorName = "DmpInvitationPersistValidator";
private final MessageSource messageSource;
protected DmpInvitationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<DmpInvitationPersist> modelClass() {
return DmpInvitationPersist.class;
}
@Override
protected List<Specification> specifications(DmpInvitationPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getEmail()))
.failOn(DmpInvitationPersist._email).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpInvitationPersist._email}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getDmpId()))
.failOn(DmpInvitationPersist._dmpId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpInvitationPersist._dmpId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getRole()))
.failOn(DmpInvitationPersist._role).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpInvitationPersist._role}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,16 +1,23 @@
package eu.eudat.model.persist.actionconfirmation; package eu.eudat.model.persist.actionconfirmation;
import jakarta.validation.constraints.NotEmpty; import eu.eudat.commons.validation.BaseValidator;
import jakarta.validation.constraints.NotNull; import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.List;
public class EmailConfirmationPersist { public class EmailConfirmationPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String email; private String email;
public EmailConfirmationPersist() { public static final String _email = "email";
}
public EmailConfirmationPersist(String email) { public EmailConfirmationPersist(String email) {
this.email = email; this.email = email;
@ -23,4 +30,33 @@ public class EmailConfirmationPersist {
public void setEmail(String email) { public void setEmail(String email) {
this.email = email; this.email = email;
} }
@Component(EmailConfirmationPersistValidator.ValidatorName)
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class EmailConfirmationPersistValidator extends BaseValidator<EmailConfirmationPersist> {
public static final String ValidatorName = "EmailConfirmationPersistValidator";
private final MessageSource messageSource;
protected EmailConfirmationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<EmailConfirmationPersist> modelClass() {
return EmailConfirmationPersist.class;
}
@Override
protected List<Specification> specifications(EmailConfirmationPersist item) {
return Collections.singletonList(
this.spec()
.must(() -> !this.isEmpty(item.getEmail()))
.failOn(EmailConfirmationPersist._email).failWith(messageSource.getMessage("Validation_Required", new Object[]{EmailConfirmationPersist._email}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,19 +1,26 @@
package eu.eudat.model.persist.descriptionproperties; package eu.eudat.model.persist.descriptionproperties;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import jakarta.validation.constraints.NotEmpty; import java.util.Arrays;
import jakarta.validation.constraints.NotNull; import java.util.List;
public class FieldPersist { public class FieldPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String key; private String key;
public static final String _key = "key";
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String value; private String value;
public static final String _value = "value";
public String getKey() { public String getKey() {
return key; return key;
} }
@ -29,6 +36,37 @@ public class FieldPersist {
public void setValue(String value) { public void setValue(String value) {
this.value = value; this.value = value;
} }
@Component(FieldPersistValidator.ValidatorName)
public static class FieldPersistValidator extends BaseValidator<FieldPersist> {
public static final String ValidatorName = "Description.FieldPersistValidator";
private final MessageSource messageSource;
protected FieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<FieldPersist> modelClass() {
return FieldPersist.class;
}
@Override
protected List<Specification> specifications(FieldPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getKey()))
.failOn(FieldPersist._key).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._key}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getValue()))
.failOn(FieldPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._value}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,16 +1,25 @@
package eu.eudat.model.persist.descriptionproperties; package eu.eudat.model.persist.descriptionproperties;
import jakarta.validation.Valid; import eu.eudat.commons.validation.BaseValidator;
import jakarta.validation.constraints.NotNull; import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List; import java.util.List;
public class PropertyDefinitionPersist { public class PropertyDefinitionPersist {
@NotNull(message = "{validation.empty}")
@Valid
private List<FieldPersist> fields; private List<FieldPersist> fields;
public static final String _fields = "fields";
public List<FieldPersist> getFields() { public List<FieldPersist> getFields() {
return fields; return fields;
} }
@ -18,4 +27,41 @@ public class PropertyDefinitionPersist {
public void setFields(List<FieldPersist> fields) { public void setFields(List<FieldPersist> fields) {
this.fields = fields; this.fields = fields;
} }
@Component(PropertyDefinitionPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class PropertyDefinitionPersistValidator extends BaseValidator<PropertyDefinitionPersist> {
public static final String ValidatorName = "Description.PropertyDefinitionPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected PropertyDefinitionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<PropertyDefinitionPersist> modelClass() {
return PropertyDefinitionPersist.class;
}
@Override
protected List<Specification> specifications(PropertyDefinitionPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getFields()))
.failOn(PropertyDefinitionPersist._fields).failWith(messageSource.getMessage("Validation_Required", new Object[]{PropertyDefinitionPersist._fields}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getFields()))
.on(PropertyDefinitionPersist._fields)
.over(item.getFields())
.using(() -> this.validatorFactory.validator(FieldPersist.FieldPersistValidator.class))
);
}
}
} }

View File

@ -1,8 +1,20 @@
package eu.eudat.model.persist.referencedefinition; package eu.eudat.model.persist.referencedefinition;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List; import java.util.List;
public class DefinitionPersist { public class DefinitionPersist {
@ -11,6 +23,8 @@ public class DefinitionPersist {
@Valid @Valid
private List<FieldPersist> fields = null; private List<FieldPersist> fields = null;
public static final String _fields = "fields";
public List<FieldPersist> getFields() { public List<FieldPersist> getFields() {
return fields; return fields;
} }
@ -18,4 +32,41 @@ public class DefinitionPersist {
public void setFields(List<FieldPersist> fields) { public void setFields(List<FieldPersist> fields) {
this.fields = fields; this.fields = fields;
} }
@Component(DefinitionPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DefinitionPersistValidator extends BaseValidator<DefinitionPersist> {
public static final String ValidatorName = "Reference.DefinitionPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected DefinitionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<DefinitionPersist> modelClass() {
return DefinitionPersist.class;
}
@Override
protected List<Specification> specifications(DefinitionPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getFields()))
.failOn(DefinitionPersist._fields).failWith(messageSource.getMessage("Validation_Required", new Object[]{DefinitionPersist._fields}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getFields()))
.on(DefinitionPersist._fields)
.over(item.getFields())
.using(() -> null) //TODO
);
}
}
} }

View File

@ -15,6 +15,7 @@ import eu.eudat.commons.types.dmp.DmpPropertiesEntity;
import eu.eudat.commons.types.notification.*; import eu.eudat.commons.types.notification.*;
import eu.eudat.commons.types.reference.DefinitionEntity; import eu.eudat.commons.types.reference.DefinitionEntity;
import eu.eudat.commons.types.reference.FieldEntity; import eu.eudat.commons.types.reference.FieldEntity;
import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.configurations.notification.NotificationProperties; import eu.eudat.configurations.notification.NotificationProperties;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.*; import eu.eudat.data.*;
@ -114,6 +115,8 @@ public class DmpServiceImpl implements DmpService {
private final ActionConfirmationService actionConfirmationService; private final ActionConfirmationService actionConfirmationService;
private final ValidatorFactory validatorFactory;
@Autowired @Autowired
public DmpServiceImpl( public DmpServiceImpl(
EntityManager entityManager, EntityManager entityManager,
@ -126,7 +129,7 @@ public class DmpServiceImpl implements DmpService {
MessageSource messageSource, MessageSource messageSource,
XmlHandlingService xmlHandlingService, XmlHandlingService xmlHandlingService,
JsonHandlingService jsonHandlingService, JsonHandlingService jsonHandlingService,
UserScope userScope, EventBroker eventBroker, DescriptionService descriptionService, NotificationIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, ActionConfirmationService actionConfirmationService, FileTransformerService fileTransformerService) { UserScope userScope, EventBroker eventBroker, DescriptionService descriptionService, NotificationIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, ActionConfirmationService actionConfirmationService, FileTransformerService fileTransformerService, ValidatorFactory validatorFactory) {
this.entityManager = entityManager; this.entityManager = entityManager;
this.authorizationService = authorizationService; this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory; this.deleterFactory = deleterFactory;
@ -144,6 +147,7 @@ public class DmpServiceImpl implements DmpService {
this.eventHandler = eventHandler; this.eventHandler = eventHandler;
this.notificationProperties = notificationProperties; this.notificationProperties = notificationProperties;
this.actionConfirmationService = actionConfirmationService; this.actionConfirmationService = actionConfirmationService;
this.validatorFactory = validatorFactory;
} }
public Dmp persist(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException { public Dmp persist(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException {
@ -763,6 +767,7 @@ public class DmpServiceImpl implements DmpService {
persist.setDmpInvitation(new DmpInvitationPersist(email, dmp.getId(), role)); persist.setDmpInvitation(new DmpInvitationPersist(email, dmp.getId(), role));
persist.setCreatedById(this.userScope.getUserIdSafe()); persist.setCreatedById(this.userScope.getUserIdSafe());
persist.setExpiresAt(Instant.now().plusSeconds(Long.parseLong(this.notificationProperties.getEmailExpirationTimeSeconds()))); persist.setExpiresAt(Instant.now().plusSeconds(Long.parseLong(this.notificationProperties.getEmailExpirationTimeSeconds())));
validatorFactory.validator(ActionConfirmationPersist.ActionConfirmationPersistValidator.class).validateForce(persist);
this.actionConfirmationService.persist(persist, null); this.actionConfirmationService.persist(persist, null);
return persist.getToken(); return persist.getToken();

View File

@ -15,6 +15,7 @@ import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.commons.types.actionconfirmation.EmailConfirmationEntity; import eu.eudat.commons.types.actionconfirmation.EmailConfirmationEntity;
import eu.eudat.commons.types.notification.*; import eu.eudat.commons.types.notification.*;
import eu.eudat.commons.types.user.AdditionalInfoEntity; import eu.eudat.commons.types.user.AdditionalInfoEntity;
import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.configurations.notification.NotificationProperties; import eu.eudat.configurations.notification.NotificationProperties;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.*; import eu.eudat.data.*;
@ -98,6 +99,8 @@ public class UserServiceImpl implements UserService {
private final NotificationProperties notificationProperties; private final NotificationProperties notificationProperties;
private final NotificationIntegrationEventHandler eventHandler; private final NotificationIntegrationEventHandler eventHandler;
private final ValidatorFactory validatorFactory;
@Autowired @Autowired
public UserServiceImpl( public UserServiceImpl(
EntityManager entityManager, EntityManager entityManager,
@ -110,7 +113,7 @@ public class UserServiceImpl implements UserService {
EventBroker eventBroker, EventBroker eventBroker,
JsonHandlingService jsonHandlingService, JsonHandlingService jsonHandlingService,
XmlHandlingService xmlHandlingService, QueryFactory queryFactory, XmlHandlingService xmlHandlingService, QueryFactory queryFactory,
UserScope userScope, KeycloakService keycloakService, ActionConfirmationService actionConfirmationService, NotificationProperties notificationProperties, NotificationIntegrationEventHandler eventHandler) { UserScope userScope, KeycloakService keycloakService, ActionConfirmationService actionConfirmationService, NotificationProperties notificationProperties, NotificationIntegrationEventHandler eventHandler, ValidatorFactory validatorFactory) {
this.entityManager = entityManager; this.entityManager = entityManager;
this.authorizationService = authorizationService; this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory; this.deleterFactory = deleterFactory;
@ -127,6 +130,7 @@ public class UserServiceImpl implements UserService {
this.actionConfirmationService = actionConfirmationService; this.actionConfirmationService = actionConfirmationService;
this.notificationProperties = notificationProperties; this.notificationProperties = notificationProperties;
this.eventHandler = eventHandler; this.eventHandler = eventHandler;
this.validatorFactory = validatorFactory;
} }
//region persist //region persist
@ -401,6 +405,7 @@ public class UserServiceImpl implements UserService {
persist.setEmailConfirmation(new EmailConfirmationPersist(email)); persist.setEmailConfirmation(new EmailConfirmationPersist(email));
persist.setCreatedById(this.userScope.getUserIdSafe()); persist.setCreatedById(this.userScope.getUserIdSafe());
persist.setExpiresAt(Instant.now().plusSeconds(Long.parseLong(this.notificationProperties.getEmailExpirationTimeSeconds()))); persist.setExpiresAt(Instant.now().plusSeconds(Long.parseLong(this.notificationProperties.getEmailExpirationTimeSeconds())));
validatorFactory.validator(ActionConfirmationPersist.ActionConfirmationPersistValidator.class).validateForce(persist);
this.actionConfirmationService.persist(persist, null); this.actionConfirmationService.persist(persist, null);
return persist.getToken(); return persist.getToken();

View File

@ -4,6 +4,7 @@ import eu.eudat.commons.validation.Validator;
import eu.eudat.commons.validation.ValidatorFactory; import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.commons.validation.ValidationFilterAnnotation; import eu.eudat.commons.validation.ValidationFilterAnnotation;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
import org.jetbrains.annotations.NotNull;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpInputMessage;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
@ -25,8 +26,8 @@ public class ValidatorRequestBodyAdvice implements RequestBodyAdvice {
} }
@Override @Override
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, public @NotNull Object afterBodyRead(@NotNull Object body, @NotNull HttpInputMessage inputMessage, MethodParameter parameter, @NotNull Type targetType,
Class<? extends HttpMessageConverter<?>> converterType) { @NotNull Class<? extends HttpMessageConverter<?>> converterType) {
if (parameter.getMethod() != null) { if (parameter.getMethod() != null) {
ValidationFilterAnnotation[] annotations = parameter.getMethod().getAnnotationsByType((ValidationFilterAnnotation.class)); ValidationFilterAnnotation[] annotations = parameter.getMethod().getAnnotationsByType((ValidationFilterAnnotation.class));
@ -44,17 +45,17 @@ public class ValidatorRequestBodyAdvice implements RequestBodyAdvice {
} }
@Override @Override
public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) { public Object handleEmptyBody(Object body, @NotNull HttpInputMessage inputMessage, @NotNull MethodParameter parameter, @NotNull Type targetType, @NotNull Class<? extends HttpMessageConverter<?>> converterType) {
return body; return body;
} }
@Override @Override
public boolean supports(MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) { public boolean supports(MethodParameter parameter, @NotNull Type targetType, @NotNull Class<? extends HttpMessageConverter<?>> converterType) {
return parameter.getMethod() != null && parameter.getMethod().isAnnotationPresent((ValidationFilterAnnotation.class)); return parameter.getMethod() != null && parameter.getMethod().isAnnotationPresent((ValidationFilterAnnotation.class));
} }
@Override @Override
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) throws IOException { public @NotNull HttpInputMessage beforeBodyRead(@NotNull HttpInputMessage inputMessage, @NotNull MethodParameter parameter, @NotNull Type targetType, @NotNull Class<? extends HttpMessageConverter<?>> converterType) throws IOException {
return inputMessage; return inputMessage;
} }
} }

View File

@ -6,6 +6,7 @@ import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.DmpAccessType; import eu.eudat.commons.enums.DmpAccessType;
import eu.eudat.commons.enums.DmpStatus; import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.validation.ValidationFilterAnnotation;
import eu.eudat.file.transformer.model.file.FileFormat; import eu.eudat.file.transformer.model.file.FileFormat;
import eu.eudat.model.Description; import eu.eudat.model.Description;
import eu.eudat.model.Dmp; import eu.eudat.model.Dmp;
@ -153,6 +154,7 @@ public class DescriptionController {
@PostMapping("persist") @PostMapping("persist")
@Transactional @Transactional
@ValidationFilterAnnotation(validator = DescriptionPersist.DescriptionPersistValidator.ValidatorName, argumentName = "model")
public Description persist(@MyValidate @RequestBody DescriptionPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException { public Description persist(@MyValidate @RequestBody DescriptionPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException {
logger.debug(new MapLogEntry("persisting" + Description.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); logger.debug(new MapLogEntry("persisting" + Description.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
Description persisted = this.descriptionService.persist(model, fieldSet); Description persisted = this.descriptionService.persist(model, fieldSet);

View File

@ -3,6 +3,7 @@ package eu.eudat.controllers.v2;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.audit.AuditableAction; import eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.validation.ValidationFilterAnnotation;
import eu.eudat.data.DmpEntity; import eu.eudat.data.DmpEntity;
import eu.eudat.file.transformer.model.file.FileFormat; import eu.eudat.file.transformer.model.file.FileFormat;
import eu.eudat.model.Dmp; import eu.eudat.model.Dmp;
@ -143,7 +144,9 @@ public class DmpController {
} }
@PostMapping("clone") @PostMapping("clone")
public Dmp buildClone(@MyValidate @RequestBody CloneDmpPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException { @Transactional
@ValidationFilterAnnotation(validator = CloneDmpPersist.CloneDmpPersistValidator.ValidatorName, argumentName = "model")
public Dmp buildClone(@RequestBody CloneDmpPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("clone" + Dmp.class.getSimpleName()).And("model", model).And("fields", fieldSet)); logger.debug(new MapLogEntry("clone" + Dmp.class.getSimpleName()).And("model", model).And("fields", fieldSet));
this.censorFactory.censor(DmpCensor.class).censor(fieldSet, null); this.censorFactory.censor(DmpCensor.class).censor(fieldSet, null);