Merge branch 'dmp-refactoring' of code-repo.d4science.org:MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Efstratios Giannopoulos 2024-01-03 18:22:41 +02:00
commit 503fe2c3dc
39 changed files with 1593 additions and 444 deletions

View File

@ -70,7 +70,11 @@ public abstract class AbstractValidator<T> 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

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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() {

View File

@ -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<UserDescriptionTemplatePersist> 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()))

View File

@ -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<DmpUserInviteTypePersist> users;
@ValidEnum(message = "{validation.empty}")
public static final String _users = "users";
private DmpUserRole role;
public static final String _role = "role";
public List<DmpUserInviteTypePersist> 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<DmpUserInvitePersist> {
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<DmpUserInvitePersist> modelClass() {
return DmpUserInvitePersist.class;
}
@Override
protected List<Specification> 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))
);
}
}
}

View File

@ -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<DmpUserInviteTypePersist> {
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<DmpUserInviteTypePersist> modelClass() {
return DmpUserInviteTypePersist.class;
}
@Override
protected List<Specification> 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()))
);
}
}
}

View File

@ -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<DmpUserPersist> {
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<DmpUserPersist> modelClass() {
return DmpUserPersist.class;
}
@Override
protected List<Specification> 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()))
);
}
}
}

View File

@ -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<DmpUserRemovePersist> {
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<DmpUserRemovePersist> modelClass() {
return DmpUserRemovePersist.class;
}
@Override
protected List<Specification> 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()))
);
}
}
}

View File

@ -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<EntityDoiPersist> {
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<EntityDoiPersist> modelClass() {
return EntityDoiPersist.class;
}
@Override
protected List<Specification> 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()))
);
}
}
}

View File

@ -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<LanguagePersist> {
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<LanguagePersist> modelClass() {
return LanguagePersist.class;
}
@Override
protected List<Specification> 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;
}
}

View File

@ -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<LockPersist> {
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<LockPersist> modelClass() {
return LockPersist.class;
}
@Override
protected List<Specification> 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()))
);
}
}
}

View File

@ -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<UserDescriptionTemplatePersist> 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<UserDescriptionTemplatePersist> users) {
this.users = users;
}
@Component(NewVersionDescriptionTemplatePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class NewVersionDescriptionTemplatePersistValidator extends BaseValidator<NewVersionDescriptionTemplatePersist> {
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<NewVersionDescriptionTemplatePersist> modelClass() {
return NewVersionDescriptionTemplatePersist.class;
}
@Override
protected List<Specification> 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))
);
}
}
}

View File

@ -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<UUID> 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<NewVersionDmpPersist> {
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<NewVersionDmpPersist> modelClass() {
return NewVersionDmpPersist.class;
}
@Override
protected List<Specification> 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()))
);
}
}
}

View File

@ -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()))

View File

@ -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<ReferenceTypePersist> {
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<ReferenceTypePersist> modelClass() {
return ReferenceTypePersist.class;
}
@Override
protected List<Specification> 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))
);
}
}
}

View File

@ -1,26 +1,44 @@
package eu.eudat.model.persist.referencetypedefinition;
import eu.eudat.commons.enums.ReferenceTypeExternalApiHTTPMethodType;
import eu.eudat.commons.validation.old.ValidEnum;
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.stereotype.Component;
import java.util.Arrays;
import java.util.List;
public class AuthenticationConfigurationPersist {
@NotNull(message = "{validation.empty}")
private Boolean enabled;
@NotNull(message = "{validation.empty}")
public static final String _enabled = "enabled";
private String authUrl;
@ValidEnum(message = "{validation.empty}")
public static final String _authUrl = "authUrl";
private ReferenceTypeExternalApiHTTPMethodType authMethod;
@NotNull(message = "{validation.empty}")
private String authTokenPath ;
@NotNull(message = "{validation.empty}")
public static final String _authMethod = "authMethod";
private String authTokenPath;
public static final String _authTokenPath = "authTokenPath";
private String authRequestBody;
@NotNull(message = "{validation.empty}")
public static final String _authRequestBody = "authRequestBody";
private String type;
public static final String _type = "type";
public Boolean getEnabled() {
return enabled;
}
@ -68,4 +86,31 @@ public class AuthenticationConfigurationPersist {
public void setType(String type) {
this.type = type;
}
@Component(AuthenticationConfigurationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class AuthenticationConfigurationPersistValidator extends BaseValidator<AuthenticationConfigurationPersist> {
public static final String ValidatorName = "AuthenticationConfigurationPersistValidator";
private final MessageSource messageSource;
protected AuthenticationConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<AuthenticationConfigurationPersist> modelClass() {
return AuthenticationConfigurationPersist.class;
}
@Override
protected List<Specification> specifications(AuthenticationConfigurationPersist item) {
return Arrays.asList(
);
}
}
}

View File

@ -1,22 +1,32 @@
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 org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;
public class DependencyPropertyPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String code;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
public static final String _code = "code";
private String target;
@NotNull(message = "{validation.empty}")
public static final String _target = "target";
private Boolean required;
public static final String _required = "required";
public String getCode() {
return code;
}
@ -40,4 +50,39 @@ public class DependencyPropertyPersist {
public void setRequired(Boolean required) {
this.required = required;
}
@Component(DependencyPropertyPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DependencyPropertyPersistValidator extends BaseValidator<DependencyPropertyPersist> {
public static final String ValidatorName = "DependencyPropertyPersistValidator";
private final MessageSource messageSource;
protected DependencyPropertyPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<DependencyPropertyPersist> modelClass() {
return DependencyPropertyPersist.class;
}
@Override
protected List<Specification> specifications(DependencyPropertyPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getCode()))
.failOn(DependencyPropertyPersist._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{DependencyPropertyPersist._code}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getTarget()))
.failOn(DependencyPropertyPersist._target).failWith(messageSource.getMessage("Validation_Required", new Object[]{DependencyPropertyPersist._target}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getRequired()))
.failOn(DependencyPropertyPersist._required).failWith(messageSource.getMessage("Validation_Required", new Object[]{DependencyPropertyPersist._required}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -1,14 +1,26 @@
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.xml.bind.annotation.XmlElement;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
public class QueryConfigPersist {
private String condition;
private String separator;
private String value;
private Integer ordinal;
private String separator;
private String value;
private Integer ordinal;
public String getCondition() {
return condition;
@ -45,4 +57,26 @@ public class QueryConfigPersist {
public void setOrdinal(Integer ordinal) {
this.ordinal = ordinal;
}
@Component(QueryConfigPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class QueryConfigPersistValidator extends BaseValidator<QueryConfigPersist> {
public static final String ValidatorName = "QueryConfigPersistValidator";
protected QueryConfigPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors) {
super(conventionService, errors);
}
@Override
protected Class<QueryConfigPersist> modelClass() {
return QueryConfigPersist.class;
}
@Override
protected List<Specification> specifications(QueryConfigPersist item) {
return new ArrayList<>();
}
}
}

View File

@ -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<ReferenceTypeFieldPersist> fields = null;
private List<ReferenceTypeFieldPersist> fields = null;
@NotNull(message = "{validation.empty}")
@Valid
private List<ReferenceTypeSourceBaseConfigurationPersist> sources = null;
public static final String _fields = "fields";
public List<ReferenceTypeFieldPersist> getFields() {
return fields;
}
private List<ReferenceTypeSourceBaseConfigurationPersist> sources = null;
public void setFields(List<ReferenceTypeFieldPersist> fields) {
this.fields = fields;
}
public static final String _sources = "sources";
public List<ReferenceTypeSourceBaseConfigurationPersist> getSources() {
return sources;
}
public List<ReferenceTypeFieldPersist> getFields() {
return fields;
}
public void setFields(List<ReferenceTypeFieldPersist> fields) {
this.fields = fields;
}
public List<ReferenceTypeSourceBaseConfigurationPersist> getSources() {
return sources;
}
public void setSources(List<ReferenceTypeSourceBaseConfigurationPersist> sources) {
this.sources = sources;
}
@Component(ReferenceTypeDefinitionPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ReferenceTypeDefinitionPersistValidator extends BaseValidator<ReferenceTypeDefinitionPersist> {
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<ReferenceTypeDefinitionPersist> modelClass() {
return ReferenceTypeDefinitionPersist.class;
}
@Override
protected List<Specification> specifications(ReferenceTypeDefinitionPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getFields()))
.failOn(ReferenceTypeDefinitionPersist._fields).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeDefinitionPersist._fields}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getFields()))
.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<ReferenceTypeSourceBaseConfigurationPersist> sources) {
this.sources = sources;
}
}

View File

@ -1,26 +1,35 @@
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 org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
public class ReferenceTypeFieldPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String code = null;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
public static final String _code = "code";
private String label = null;
public static final String _label = "label";
private String description;
@ValidEnum(message = "{validation.empty}")
private ReferenceFieldDataType dataType;
public static final String _dataType = "dataType";
public String getCode() {
return code;
@ -53,6 +62,30 @@ public class ReferenceTypeFieldPersist {
public void setDataType(ReferenceFieldDataType dataType) {
this.dataType = dataType;
}
@Component(ReferenceTypeFieldPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ReferenceTypeFieldPersistValidator extends BaseValidator<ReferenceTypeFieldPersist> {
public static final String ValidatorName = "ReferenceTypeFieldPersistValidator";
protected ReferenceTypeFieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors) {
super(conventionService, errors);
}
@Override
protected Class<ReferenceTypeFieldPersist> modelClass() {
return ReferenceTypeFieldPersist.class;
}
@Override
protected List<Specification> specifications(ReferenceTypeFieldPersist item) {
return Arrays.asList(
);
}
}
}

View File

@ -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<ReferenceTypeSourceBaseDependencyPersist> dependencies;
public static final String _dependencies = "dependencies";
public String getKey() {
return key;
}
@ -77,4 +84,45 @@ public abstract class ReferenceTypeSourceBaseConfigurationPersist {
public void setDependencies(List<ReferenceTypeSourceBaseDependencyPersist> dependencies) {
this.dependencies = dependencies;
}
public static abstract class ReferenceTypeSourceBaseConfigurationPersistValidator<T extends ReferenceTypeSourceBaseConfigurationPersist> extends BaseValidator<T> {
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<Specification> 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))
);
}
}
}

View File

@ -1,28 +1,36 @@
package eu.eudat.model.persist.referencetypedefinition;
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 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<DependencyPropertyPersist> properties;
public static final String _properties = "properties";
public String getReferenceTypeCode() {
return referenceTypeCode;
@ -55,4 +63,51 @@ public class ReferenceTypeSourceBaseDependencyPersist {
public void setProperties(List<DependencyPropertyPersist> properties) {
this.properties = properties;
}
@Component(ReferenceTypeSourceBaseDependencyPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ReferenceTypeSourceBaseDependencyPersistValidator extends BaseValidator<ReferenceTypeSourceBaseDependencyPersist> {
public static final String ValidatorName = "ReferenceTypeSourceBaseDependencyPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected ReferenceTypeSourceBaseDependencyPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<ReferenceTypeSourceBaseDependencyPersist> modelClass() {
return ReferenceTypeSourceBaseDependencyPersist.class;
}
@Override
protected List<Specification> specifications(ReferenceTypeSourceBaseDependencyPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getReferenceTypeCode()))
.failOn(ReferenceTypeSourceBaseDependencyPersist._referenceTypeCode).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseDependencyPersist._referenceTypeCode}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getKey()))
.failOn(ReferenceTypeSourceBaseDependencyPersist._key).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseDependencyPersist._key}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getRequired()))
.failOn(ReferenceTypeSourceBaseDependencyPersist._required).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseDependencyPersist._required}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getProperties()))
.failOn(ReferenceTypeSourceBaseDependencyPersist._properties).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseDependencyPersist._properties}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getProperties()))
.on(ReferenceTypeSourceBaseDependencyPersist._properties)
.over(item.getProperties())
.using(() -> this.validatorFactory.validator(DependencyPropertyPersist.DependencyPropertyPersistValidator.class))
);
}
}
}

View File

@ -1,45 +1,60 @@
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.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 ReferenceTypeSourceExternalApiConfigurationPersist extends ReferenceTypeSourceBaseConfigurationPersist{
public class ReferenceTypeSourceExternalApiConfigurationPersist extends ReferenceTypeSourceBaseConfigurationPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String url;
@Valid
public static final String _uri = "uri";
private ResultsConfigurationPersist results;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
public static final String _results = "results";
private String paginationPath;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
public static final String _paginationPath = "paginationPath";
private String contentType;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
public static final String _contentType = "contentType";
private String firstPage;
@ValidEnum(message = "{validation.empty}")
public static final String _firstPage = "firstPage";
private ReferenceTypeExternalApiHTTPMethodType httpMethod;
public static final String _httpMethod = "httpMethod";
private String requestBody = "";
private String filterType = "remote";
@Valid
private AuthenticationConfigurationPersist auth;
@Valid
public static final String _auth = "auth";
private List<QueryConfigPersist> queries;
public static final String _queries = "queries";
public String getUrl() {
return url;
}
@ -56,7 +71,6 @@ public class ReferenceTypeSourceExternalApiConfigurationPersist extends Referenc
this.results = results;
}
public String getPaginationPath() {
return paginationPath;
}
@ -73,7 +87,6 @@ public class ReferenceTypeSourceExternalApiConfigurationPersist extends Referenc
this.contentType = contentType;
}
public String getFirstPage() {
return firstPage;
}
@ -121,4 +134,30 @@ public class ReferenceTypeSourceExternalApiConfigurationPersist extends Referenc
public void setQueries(List<QueryConfigPersist> queries) {
this.queries = queries;
}
@Component(ReferenceTypeSourceExternalApiConfigurationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ReferenceTypeSourceExternalApiConfigurationPersistValidator extends ReferenceTypeSourceBaseConfigurationPersistValidator<ReferenceTypeSourceExternalApiConfigurationPersist> {
public static final String ValidatorName = "ReferenceTypeSourceExternalApiConfigurationPersistValidator";
protected ReferenceTypeSourceExternalApiConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors, messageSource, validatorFactory);
}
@Override
protected Class<ReferenceTypeSourceExternalApiConfigurationPersist> modelClass() {
return ReferenceTypeSourceExternalApiConfigurationPersist.class;
}
@Override
protected List<Specification> specifications(ReferenceTypeSourceExternalApiConfigurationPersist item) {
List<Specification> specifications = getBaseSpecifications(item);
specifications.addAll(Arrays.asList(
));
return specifications;
}
}
}

View File

@ -1,15 +1,22 @@
package eu.eudat.model.persist.referencetypedefinition;
import jakarta.validation.Valid;
import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.List;
public class ReferenceTypeSourceStaticOptionConfigurationPersist extends ReferenceTypeSourceBaseConfigurationPersist{
public class ReferenceTypeSourceStaticOptionConfigurationPersist extends ReferenceTypeSourceBaseConfigurationPersist {
@Valid
List<ReferenceTypeStaticOptionPersist> options;
public static final String _options = "options";
public List<ReferenceTypeStaticOptionPersist> getOptions() {
return options;
}
@ -17,4 +24,34 @@ public class ReferenceTypeSourceStaticOptionConfigurationPersist extends Referen
public void setOptions(List<ReferenceTypeStaticOptionPersist> options) {
this.options = options;
}
@Component(ReferenceTypeSourceStaticOptionConfigurationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ReferenceTypeSourceStaticOptionConfigurationPersistValidator extends ReferenceTypeSourceBaseConfigurationPersistValidator<ReferenceTypeSourceStaticOptionConfigurationPersist> {
public static final String ValidatorName = "ReferenceTypeSourceStaticOptionConfigurationPersistValidator";
protected ReferenceTypeSourceStaticOptionConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors, messageSource, validatorFactory);
}
@Override
protected Class<ReferenceTypeSourceStaticOptionConfigurationPersist> modelClass() {
return ReferenceTypeSourceStaticOptionConfigurationPersist.class;
}
@Override
protected List<Specification> specifications(ReferenceTypeSourceStaticOptionConfigurationPersist item) {
List<Specification> specifications = getBaseSpecifications(item);
specifications.add(
this.refSpec()
.iff(() -> !this.isNull(item.getOptions()))
.on(ReferenceTypeSourceStaticOptionConfigurationPersist._options)
.over(item.getOptions())
.using(() -> this.validatorFactory.validator(ReferenceTypeStaticOptionPersist.ReferenceTypeStaticOptionPersistValidator.class))
);
return specifications;
}
}
}

View File

@ -1,18 +1,28 @@
package eu.eudat.model.persist.referencetypedefinition;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
public class ReferenceTypeStaticOptionPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String code;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
public static final String _code = "code";
private String value;
public static final String _value = "value";
public String getCode() {
return code;
}
@ -28,4 +38,36 @@ public class ReferenceTypeStaticOptionPersist {
public void setValue(String value) {
this.value = value;
}
@Component(ReferenceTypeStaticOptionPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ReferenceTypeStaticOptionPersistValidator extends BaseValidator<ReferenceTypeStaticOptionPersist> {
public static final String ValidatorName = "ReferenceTypeStaticOptionPersistValidator";
private final MessageSource messageSource;
protected ReferenceTypeStaticOptionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<ReferenceTypeStaticOptionPersist> modelClass() {
return ReferenceTypeStaticOptionPersist.class;
}
@Override
protected List<Specification> specifications(ReferenceTypeStaticOptionPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getCode()))
.failOn(ReferenceTypeStaticOptionPersist._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeStaticOptionPersist._code}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getValue()))
.failOn(ReferenceTypeStaticOptionPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeStaticOptionPersist._value}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -1,18 +1,26 @@
package eu.eudat.model.persist.referencetypedefinition;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
public class ResultFieldsMappingConfigurationPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String code;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
public static final String _code = "code";
private String responsePath;
public static final String _responsePath = "responsePath";
public String getCode() {
return code;
}
@ -28,4 +36,28 @@ public class ResultFieldsMappingConfigurationPersist {
public void setResponsePath(String responsePath) {
this.responsePath = responsePath;
}
@Component(ResultFieldsMappingConfigurationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ResultFieldsMappingConfigurationPersistValidator extends BaseValidator<ResultFieldsMappingConfigurationPersist> {
public static final String ValidatorName = "ResultFieldsMappingConfigurationPersistValidator";
protected ResultFieldsMappingConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors) {
super(conventionService, errors);
}
@Override
protected Class<ResultFieldsMappingConfigurationPersist> modelClass() {
return ResultFieldsMappingConfigurationPersist.class;
}
@Override
protected List<Specification> specifications(ResultFieldsMappingConfigurationPersist item) {
return Arrays.asList(
);
}
}
}

View File

@ -1,21 +1,27 @@
package eu.eudat.model.persist.referencetypedefinition;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
public class ResultsConfigurationPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String resultsArrayPath;
@NotNull(message = "{validation.empty}")
@Valid
public static final String _resultsArrayPath = "resultsArrayPath";
private List<ResultFieldsMappingConfigurationPersist> fieldsMapping;
public static final String _fieldsMapping = "fieldsMapping";
public String getResultsArrayPath() {
return resultsArrayPath;
}
@ -31,4 +37,31 @@ public class ResultsConfigurationPersist {
public void setFieldsMapping(List<ResultFieldsMappingConfigurationPersist> fieldsMapping) {
this.fieldsMapping = fieldsMapping;
}
@Component(ResultsConfigurationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ResultsConfigurationPersistValidator extends BaseValidator<ResultsConfigurationPersist> {
public static final String ValidatorName = "ResultsConfigurationPersistValidator";
private final MessageSource messageSource;
protected ResultsConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<ResultsConfigurationPersist> modelClass() {
return ResultsConfigurationPersist.class;
}
@Override
protected List<Specification> specifications(ResultsConfigurationPersist item) {
return Arrays.asList(
);
}
}
}

View File

@ -80,15 +80,16 @@ public class EmailMessageBuilder extends MessageBuilderBase implements MessageBu
String bodyTemplate = null;
ReplaceResult bodyResult = null;
// fallback
if (template != null && template.getValue() != null){
if (!StringUtils.isNullOrEmpty(template.getValue().getSubjectKey())) subjectTemplate = messageInfo.getFields().stream().filter(fieldInfo -> fieldInfo.getKey().equals(template.getValue().getSubjectKey())).findFirst().orElse(new FieldInfo()).getValue();
if (StringUtils.isNullOrEmpty(subjectTemplate)) subjectTemplate = template.getValue().getSubjectText();
//TODO add formatting function with db fields
subjectResult = this.buildTemplate(notification.getId(), subjectTemplate, messageInfo, template.getValue().getSubjectFieldOptions(), null, cipherFields.get(notification.getType()));
FieldFormatting subjectFormatting = this.buildFieldFormatting(template.getValue().getSubjectFieldOptions());
subjectResult = this.buildTemplate(notification.getId(), subjectTemplate, messageInfo, template.getValue().getSubjectFieldOptions(), subjectFormatting, cipherFields.get(notification.getType()));
if(!StringUtils.isNullOrEmpty(template.getValue().getBodyKey())) bodyTemplate = messageInfo.getFields().stream().filter(fieldInfo -> fieldInfo.getKey().equals(template.getValue().getBodyKey())).findFirst().orElse(new FieldInfo()).getValue();
if (StringUtils.isNullOrEmpty(bodyTemplate)) bodyTemplate = template.getValue().getBodyText();
FieldFormatting bodyFormatting = this.buildFieldFormatting(flow.getBodyFieldOptions());
FieldFormatting bodyFormatting = this.buildFieldFormatting(template.getValue().getBodyFieldOptions());
bodyResult = this.buildTemplate(notification.getId(), bodyTemplate, messageInfo, template.getValue().getBodyFieldOptions(), bodyFormatting, cipherFields.get(notification.getType()));
}else {
if(!StringUtils.isNullOrEmpty(flow.getSubjectKey())) subjectTemplate = messageInfo.getFields().stream().filter(fieldInfo -> fieldInfo.getKey().equals(flow.getSubjectKey())).findFirst().orElse(new FieldInfo()).getValue();

View File

@ -154,6 +154,17 @@ public abstract class MessageBuilderBase {
return formatting;
}
protected FieldFormatting buildFieldFormatting(FieldOptions options) {
FieldFormatting formatting = new FieldFormatting();
if (options == null || options.getFormatting() == null) return formatting;
for (Map.Entry<String, String> pair : options.getFormatting().entrySet()) {
if (StringUtils.isNullOrEmpty(pair.getValue())) continue;
formatting.put(pair.getKey(), pair.getValue());
}
return formatting;
}
//TODO: Here check with a language accepted list and fallback to default
protected String lookupOrReadLocalizedFile(NotificationProperties.Template.TemplateCache templateCache, String path, String language) {
String filename = path.replace("{language}", language);

View File

@ -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<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("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<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("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<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("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<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("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<byte[]> 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<byte[]> response = this.descriptionTemplateTypeService.exportXml(id);
this.auditService.track(AuditableAction.DescriptionTemplate_GetXml, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id)
));
return response;
}
@ -196,7 +197,6 @@ public class DescriptionTemplateController {
new AbstractMap.SimpleEntry<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("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<String, Object>("query", query)
));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return semantics;
}

View File

@ -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<DmpUser> assignUsers(@PathVariable("id") UUID id, @MyValidate @RequestBody List<DmpUserPersist> model, FieldSet fieldSet) throws InvalidApplicationException {
@ValidationFilterAnnotation(validator = DmpUserPersist.DmpUserPersistValidator.ValidatorName, argumentName = "model")
public QueryResult<DmpUser> assignUsers(@PathVariable("id") UUID id, @RequestBody List<DmpUserPersist> model, FieldSet fieldSet) throws InvalidApplicationException {
logger.debug(new MapLogEntry("assigning users to dmp").And("model", model).And("fieldSet", fieldSet));
List<DmpUser> persisted = this.dmpService.assignUsers(id, model, fieldSet);
@ -194,7 +196,8 @@ public class DmpController {
@PostMapping("remove-user")
@Transactional
public QueryResult<Dmp> removeUser(@MyValidate @RequestBody DmpUserRemovePersist model, FieldSet fieldSet) throws InvalidApplicationException {
@ValidationFilterAnnotation(validator = DmpUserRemovePersist.DmpUserRemovePersistValidator.ValidatorName, argumentName = "model")
public QueryResult<Dmp> 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<ResponseItem<String>> 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<ResponseItem<String>> 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);

View File

@ -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);

View File

@ -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);

View File

@ -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<Lock> 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<Lock> 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<LockEntity> data = query.collectAs(lookup.getProject());
List<Lock> 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<LockEntity> data = query.collectAs(lookup.getProject());
List<Lock> 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<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("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<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("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<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
Lock persisted = this.lockService.persist(model, fieldSet);
return persisted;
}
this.auditService.track(AuditableAction.Lock_Persist, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("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<String, Object>("targetId", targetId),
new AbstractMap.SimpleEntry<String, Object>("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<String, Object>("targetId", targetId),
new AbstractMap.SimpleEntry<String, Object>("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<String, Object>("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<String, Object>("targetId", targetId)
));
return isLocked;
}
this.lockService.unlock(targetId);
this.auditService.track(AuditableAction.Lock_UnLocked, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("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<String, Object>("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);
}
}

View File

@ -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.commons.exceptions.HugeResultSetException;
@ -31,7 +32,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;
@ -55,12 +55,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
@ -95,19 +102,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<ResponseItem<List<Reference>>> searchReference(@RequestBody ReferenceSearchLookup lookup) throws HugeResultSetException, MyNotFoundException, 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<Reference> references = this.referenceService.searchReference(lookup);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Reference>>().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<List<Reference>>().status(ApiMessageCode.NO_MESSAGE));
}
@PostMapping("search-with-db-definition")
@ -139,7 +146,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);
@ -149,7 +157,7 @@ public class ReferenceController extends BaseController {
new AbstractMap.SimpleEntry<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return persisted;
}
@ -168,7 +176,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);

View File

@ -134,7 +134,7 @@
<mat-error *ngIf="subjectOptions.get('value').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<div class="col-auto">
<button mat-icon-button (click)="removeOptionalItem(formGroup.get('value').get('subjectFieldOptions'),i)" [disabled]="formGroup.disabled">
<button mat-icon-button (click)="removeSubjectOptionalItem(i)" [disabled]="formGroup.disabled">
<mat-icon>remove</mat-icon>
</button>
</div>
@ -152,22 +152,22 @@
<div class="row" *ngFor="let item of formGroup.get('value').get('subjectFieldOptions').get('mandatory').value; let i = index">
<mat-form-field class="col-md-4">
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}}</mat-label>
<input matInput [value]="insertFormattingItem(item, null)" [disabled] = "true">
<input matInput [value]="item" [disabled] = "true">
</mat-form-field>
<mat-form-field class="col-md-4">
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}}</mat-label>
<input matInput>
<input matInput [value] ="subjectFormatting[item]" (change)="subjectFormattingValueChange($event, item)">
</mat-form-field>
</div>
<div class="row" *ngFor="let item of formGroup.get('value').get('subjectFieldOptions').get('optional')['controls']; let i = index">
<div *ngIf="item.valid">
<mat-form-field class="col-md-4">
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}}</mat-label>
<input matInput [value]="insertFormattingItem(item.value.key, null)" [disabled] = "true">
<input matInput [value]="item.value.key" [disabled] = "true">
</mat-form-field>
<mat-form-field class="col-md-4">
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}}</mat-label>
<input matInput>
<input matInput [value]="subjectFormatting[item]" (change)="subjectFormattingValueChange($event, item)">
</mat-form-field>
</div>
</div>
@ -261,7 +261,7 @@
<mat-error *ngIf="bodyOptions.get('value').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<div class="col-auto">
<button mat-icon-button (click)="removeOptionalItem(formGroup.get('value').get('bodyFieldOptions'),i)" [disabled]="formGroup.disabled">
<button mat-icon-button (click)="removeBodyOptionalItem(i)" [disabled]="formGroup.disabled">
<mat-icon>remove</mat-icon>
</button>
</div>
@ -275,25 +275,25 @@
</div>
</div>
<h4 class="col-md-12">{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.FORMATTING' | translate}}</h4>
<div class="row" *ngFor="let item of formGroup.get('value').get('subjectFieldOptions').get('mandatory').value; let i = index">
<div class="row" *ngFor="let item of formGroup.get('value').get('bodyFieldOptions').get('mandatory').value; let i = index">
<mat-form-field class="col-md-4">
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}}</mat-label>
<input matInput [value]="insertFormattingItem(item, null)" [disabled] = "true">
<input matInput [value]="item" [disabled] = "true">
</mat-form-field>
<mat-form-field class="col-md-4">
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}}</mat-label>
<input matInput>
<input matInput [value] ="bodyFormatting[item]" (change)="bodyFormattingValueChange($event, item)">
</mat-form-field>
</div>
<div class="row" *ngFor="let item of formGroup.get('value').get('subjectFieldOptions').get('optional')['controls']; let i = index">
<div class="row" *ngFor="let item of formGroup.get('value').get('bodyFieldOptions').get('optional')['controls']; let i = index">
<div *ngIf="item.valid">
<mat-form-field class="col-md-4">
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}}</mat-label>
<input matInput [value]="insertFormattingItem(item.value.key, null)" [disabled] = "true">
<input matInput [value]="item.value.key" [disabled] = "true">
</mat-form-field>
<mat-form-field class="col-md-4">
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}}</mat-label>
<input matInput>
<input matInput [value]="bodyFormatting[item]" (change)="bodyFormattingValueChange($event, item)">
</mat-form-field>
</div>
</div>

View File

@ -54,7 +54,8 @@ export class NotificationTemplateEditorComponent extends BaseEditor<Notification
bccValues: string[] = [];
extraDataKeys: string[] = [];
languageCode: string;
formatting: { [key: string]: string } = {};
subjectFormatting: { [key: string]: string } = {};
bodyFormatting: { [key: string]: string } = {};
public notificationTemplateKindEnum = this.enumUtils.getEnumValues(NotificationTemplateKind);
public notificationTemplateChannelEnum = this.enumUtils.getEnumValues(NotificationTemplateChannel);
public notificationDataTypeEnum = this.enumUtils.getEnumValues(NotificationDataType);
@ -96,11 +97,6 @@ export class NotificationTemplateEditorComponent extends BaseEditor<Notification
super(dialog, language, formService, router, uiNotificationService, httpErrorHandlingService, filterService, datePipe, route, queryParamsService);
}
// ngOnInit(): void {
// this.editorModel = new NotificationTemplateEditorModel().fromModel(this.notificationTemplate);
// this.formGroup = this.editorModel.buildForm(null, this.editorModel.kind === NotificationTemplateKind.Default ? true : !this.authService.permissionEnum.EditDescription);
// }
ngOnInit(): void {
this.matomoService.trackPageView('Admin: Notification Tempplates');
super.ngOnInit();
@ -133,6 +129,12 @@ export class NotificationTemplateEditorComponent extends BaseEditor<Notification
this.bodyFieldOptionsEnabled = true;
this.bodyMandatoryFields = data.value.bodyFieldOptions.mandatory;
}
if(data.value && data.value.subjectFieldOptions && data.value.subjectFieldOptions.formatting){
this.subjectFormatting = data.value.subjectFieldOptions.formatting;
}
if(data.value && data.value.bodyFieldOptions && data.value.bodyFieldOptions.formatting){
this.bodyFormatting = data.value.bodyFieldOptions.formatting;
}
this.ccValues = this.editorModel.value.cc;
this.bccValues = this.editorModel.value.bcc;
this.extraDataKeys = this.editorModel.value.extraDataKeys;
@ -181,6 +183,7 @@ export class NotificationTemplateEditorComponent extends BaseEditor<Notification
}
formSubmit(): void {
console.log(this.formGroup);
this.formService.touchAllFormFields(this.formGroup);
if (!this.isFormValid()) {
return;
@ -224,7 +227,6 @@ export class NotificationTemplateEditorComponent extends BaseEditor<Notification
.subscribe(
data => {
this.formGroup.get('languageId').patchValue(data.id);
console.log(this.formGroup);
}
);
}
@ -271,8 +273,10 @@ export class NotificationTemplateEditorComponent extends BaseEditor<Notification
this.extraDataKeys = this.edit(field, this.extraDataKeys, event);
}else if(type == "subject"){
this.subjectMandatoryFields = this.edit(field, this.subjectMandatoryFields, event);
this.editSubjectFormmattingKey(field, event.value.trim());
}else if(type == "body"){
this.bodyMandatoryFields = this.edit(field, this.bodyMandatoryFields, event);
this.editBodyFormmattingKey(field, event.value.trim());
}
}
@ -285,8 +289,10 @@ export class NotificationTemplateEditorComponent extends BaseEditor<Notification
this.extraDataKeys = this.remove(field, this.extraDataKeys);
}else if(type == "subject"){
this.subjectMandatoryFields = this.remove(field, this.subjectMandatoryFields);
this.deleteSubjectFormattingItem(field);
}else if(type == "body"){
this.bodyMandatoryFields = this.remove(field, this.bodyMandatoryFields);
this.deleteBodyFormattingItem(field);
}
}
@ -327,15 +333,64 @@ export class NotificationTemplateEditorComponent extends BaseEditor<Notification
(formGroup.get('optional') as FormArray).push(fieldInfo.buildForm());
}
removeOptionalItem(formGroup: UntypedFormGroup, optionalIndex: number): void {
(formGroup.get('optional') as FormArray).removeAt(optionalIndex);
removeSubjectOptionalItem(optionalIndex: number): void {
const key = (this.formGroup.get('value').get('subjectFieldOptions').get('optional') as FormArray).at(optionalIndex).get("key").value;
this.deleteSubjectFormattingItem(key);
(this.formGroup.get('value').get('subjectFieldOptions').get('optional') as FormArray).removeAt(optionalIndex);
}
removeBodyOptionalItem(optionalIndex: number): void {
const key = (this.formGroup.get('value').get('bodyFieldOptions').get('optional') as FormArray).at(optionalIndex).get("key").value;
this.deleteBodyFormattingItem(key);
(this.formGroup.get('value').get('bodyFieldOptions').get('optional') as FormArray).removeAt(optionalIndex);
}
insertFormattingItem(key: string, value: string){
this.formatting[key] = value;
// this.formGroup.get('value').get('subjectFieldOptions').get('formatting').patchValue(this.formatting); TODO
// subject formatting
insertSubjectFormattingItem(key: string, value: string){
this.subjectFormatting[key] = value;
this.formGroup.get('value').get('subjectFieldOptions').get('formatting').setValue(this.subjectFormatting);
}
return key;
subjectFormattingValueChange(event: Event, key: string){
this.bodyFormatting[key] = (event.target as HTMLInputElement).value;
this.formGroup.get('value').get('subjectFieldOptions').get('formatting').setValue(this.bodyFormatting);
}
editSubjectFormmattingKey(oldKey: string, newKey: string){
this.insertSubjectFormattingItem(newKey, this.subjectFormatting[oldKey]);
this.deleteSubjectFormattingItem(oldKey);
}
deleteSubjectFormattingItem(key:string){
if (key in this.subjectFormatting) {
delete this.subjectFormatting[key];
this.formGroup.get('value').get('subjectFieldOptions').get('formatting').setValue(this.subjectFormatting);
}
}
// body formatting
insertBodyFormattingItem(key: string, value: string){
this.bodyFormatting[key] = value;
this.formGroup.get('value').get('bodyFieldOptions').get('formatting').setValue(this.bodyFormatting);
}
bodyFormattingValueChange(event: Event, key: string){
this.bodyFormatting[key] = (event.target as HTMLInputElement).value;
this.formGroup.get('value').get('bodyFieldOptions').get('formatting').setValue(this.bodyFormatting);
}
editBodyFormmattingKey(oldKey: string, newKey: string){
this.insertBodyFormattingItem(newKey, this.bodyFormatting[oldKey]);
this.deleteBodyFormattingItem(oldKey);
}
deleteBodyFormattingItem(key:string){
if (key in this.bodyFormatting) {
delete this.bodyFormatting[key];
this.formGroup.get('value').get('bodyFieldOptions').get('formatting').setValue(this.bodyFormatting);
}
}
}

View File

@ -169,7 +169,7 @@ export class NotificationTemplateValueEditorModel implements NotificationTemplat
export class NotificationFieldOptionsEditorModel implements NotificationFieldOptionsPersist {
mandatory?: string[] = [];
optional?: NotificationFieldInfoEditorModel[] = [];
formatting?: { [key: string]: string };
formatting?: { [key: string]: string } = {};
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();