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

This commit is contained in:
Efstratios Giannopoulos 2024-01-04 12:56:23 +02:00
commit 73b0272672
24 changed files with 1004 additions and 332 deletions

View File

@ -24,9 +24,10 @@ public class SupportiveMaterialEntity extends TenantScopedBaseEntity {
private SupportiveMaterialFieldType type; private SupportiveMaterialFieldType type;
public static final String _type = "type"; public static final String _type = "type";
@Column(name = "language_code", length = 20, nullable = false) @Column(name = "language_code", length = _languageCodeLength, nullable = false)
private String languageCode; private String languageCode;
public static final String _languageCode = "languageCode"; public static final String _languageCode = "languageCode";
public static final int _languageCodeLength = 20;
@Column(name = "payload", nullable = false) @Column(name = "payload", nullable = false)
private String payload; private String payload;

View File

@ -17,13 +17,15 @@ public class TenantEntity {
private UUID id; private UUID id;
public final static String _id = "id"; public final static String _id = "id";
@Column(name = "code", length = 200, nullable = false) @Column(name = "code", length = _codeLength, nullable = false)
private String code; private String code;
public final static String _code = "code"; public final static String _code = "code";
public final static int _codeLength = 200;
@Column(name = "name", length = 500, nullable = false) @Column(name = "name", length = _nameLength, nullable = false)
private String name; private String name;
public final static String _name = "name"; public final static String _name = "name";
public final static int _nameLength = 500;
@Column(name = "description", nullable = false) @Column(name = "description", nullable = false)
private String description; private String description;

View File

@ -1,37 +1,40 @@
package eu.eudat.model.persist; package eu.eudat.model.persist;
import eu.eudat.commons.enums.StorageType; import eu.eudat.commons.enums.StorageType;
import eu.eudat.commons.validation.old.ValidEnum; import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.StorageFileEntity; import eu.eudat.data.StorageFileEntity;
import jakarta.validation.constraints.NotEmpty; import eu.eudat.errorcode.ErrorThesaurusProperties;
import jakarta.validation.constraints.NotNull; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import jakarta.validation.constraints.Size; import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.time.Duration; import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public class StorageFilePersist { public class StorageFilePersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = StorageFileEntity._nameLen, message = "{validation.largerthanmax}")
private String name; private String name;
@NotNull(message = "{validation.empty}") public static final String _name = "name";
@NotEmpty(message = "{validation.empty}")
@Size(max = StorageFileEntity._extensionLen, message = "{validation.largerthanmax}")
private String extension; private String extension;
public static final String _extension = "extension";
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = StorageFileEntity._mimeTypeLen, message = "{validation.largerthanmax}")
private String mimeType; private String mimeType;
@NotNull(message = "{validation.empty}") public static final String _mimeType = "mimeType";
@ValidEnum(message = "{validation.empty}")
private StorageType storageType; private StorageType storageType;
public static final String _storageType = "storageType";
private Duration lifetime; private Duration lifetime;
private UUID ownerId; private UUID ownerId;
@ -83,4 +86,54 @@ public class StorageFilePersist {
public void setLifetime(Duration lifetime) { public void setLifetime(Duration lifetime) {
this.lifetime = lifetime; this.lifetime = lifetime;
} }
@Component(StorageFilePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class StorageFilePersistValidator extends BaseValidator<StorageFilePersist> {
public static final String ValidatorName = "StorageFilePersistValidator";
private final MessageSource messageSource;
protected StorageFilePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<StorageFilePersist> modelClass() {
return StorageFilePersist.class;
}
@Override
protected List<Specification> specifications(StorageFilePersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getName()))
.failOn(StorageFilePersist._name).failWith(messageSource.getMessage("Validation_Required", new Object[]{StorageFilePersist._name}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getName()))
.must(() -> this.lessEqualLength(item.getName(), StorageFileEntity._nameLen))
.failOn(StorageFilePersist._name).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{StorageFilePersist._name}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getExtension()))
.failOn(StorageFilePersist._extension).failWith(messageSource.getMessage("Validation_Required", new Object[]{StorageFilePersist._extension}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getExtension()))
.must(() -> this.lessEqualLength(item.getExtension(), StorageFileEntity._extensionLen))
.failOn(StorageFilePersist._extension).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{StorageFilePersist._extension}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getMimeType()))
.failOn(StorageFilePersist._mimeType).failWith(messageSource.getMessage("Validation_Required", new Object[]{StorageFilePersist._mimeType}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getMimeType()))
.must(() -> this.lessEqualLength(item.getMimeType(), StorageFileEntity._mimeTypeLen))
.failOn(StorageFilePersist._mimeType).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{StorageFilePersist._mimeType}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getStorageType()))
.failOn(StorageFilePersist._storageType).failWith(messageSource.getMessage("Validation_Required", new Object[]{StorageFilePersist._storageType}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,69 +1,125 @@
package eu.eudat.model.persist; package eu.eudat.model.persist;
import eu.eudat.commons.enums.SupportiveMaterialFieldType; import eu.eudat.commons.enums.SupportiveMaterialFieldType;
import eu.eudat.commons.validation.old.ValidEnum; import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.old.ValidId; import eu.eudat.commons.validation.specification.Specification;
import jakarta.validation.constraints.NotEmpty; import eu.eudat.convention.ConventionService;
import jakarta.validation.constraints.NotNull; import eu.eudat.data.SupportiveMaterialEntity;
import jakarta.validation.constraints.Size; import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public class SupportiveMaterialPersist { public class SupportiveMaterialPersist {
@ValidId(message = "{validation.invalidid}")
private UUID id;
@ValidEnum(message = "{validation.empty}") private UUID id;
private SupportiveMaterialFieldType type;
@NotNull(message = "{validation.empty}") private SupportiveMaterialFieldType type;
@NotEmpty(message = "{validation.empty}")
@Size(max = 20, message = "{validation.largerthanmax}")
private String languageCode;
@NotNull(message = "{validation.empty}") public static final String _type = "type";
@NotEmpty(message = "{validation.empty}")
private String payload;
private String hash; private String languageCode;
public UUID getId() { public static final String _languageCode = "languageCode";
return id;
}
public void setId(UUID id) { private String payload;
this.id = id;
}
public SupportiveMaterialFieldType getType() { public static final String _payload = "payload";
return type;
}
public void setType(SupportiveMaterialFieldType type) { private String hash;
this.type = type;
}
public String getLanguageCode() { public static final String _hash = "hash";
return languageCode;
}
public void setLanguageCode(String languageCode) { public UUID getId() {
this.languageCode = languageCode; return id;
} }
public String getPayload() { public void setId(UUID id) {
return payload; this.id = id;
} }
public void setPayload(String payload) { public SupportiveMaterialFieldType getType() {
this.payload = payload; return type;
} }
public String getHash() { public void setType(SupportiveMaterialFieldType type) {
return hash; this.type = type;
} }
public String getLanguageCode() {
return languageCode;
}
public void setLanguageCode(String languageCode) {
this.languageCode = languageCode;
}
public String getPayload() {
return payload;
}
public void setPayload(String payload) {
this.payload = payload;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
@Component(SupportiveMaterialPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class SupportiveMaterialPersistValidator extends BaseValidator<SupportiveMaterialPersist> {
public static final String ValidatorName = "SupportiveMaterialPersistValidator";
private final MessageSource messageSource;
protected SupportiveMaterialPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<SupportiveMaterialPersist> modelClass() {
return SupportiveMaterialPersist.class;
}
@Override
protected List<Specification> specifications(SupportiveMaterialPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(SupportiveMaterialPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{SupportiveMaterialPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(SupportiveMaterialPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getType()))
.failOn(SupportiveMaterialPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{SupportiveMaterialPersist._type}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getLanguageCode()))
.failOn(SupportiveMaterialPersist._languageCode).failWith(messageSource.getMessage("Validation_Required", new Object[]{SupportiveMaterialPersist._languageCode}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getLanguageCode()))
.must(() -> this.lessEqualLength(item.getLanguageCode(), SupportiveMaterialEntity._languageCodeLength))
.failOn(SupportiveMaterialPersist._languageCode).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{SupportiveMaterialPersist._languageCode}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getPayload()))
.failOn(SupportiveMaterialPersist._payload).failWith(messageSource.getMessage("Validation_Required", new Object[]{SupportiveMaterialPersist._payload}, LocaleContextHolder.getLocale()))
);
}
}
public void setHash(String hash) {
this.hash = hash;
}
} }

View File

@ -1,36 +1,46 @@
package eu.eudat.model.persist; package eu.eudat.model.persist;
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.old.ValidId; import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.TenantEntity;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.persist.tenantconfig.TenantConfigPersist; import eu.eudat.model.persist.tenantconfig.TenantConfigPersist;
import jakarta.validation.constraints.*; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID; import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class TenantPersist { public class TenantPersist {
@ValidId(message = "{validation.invalidid}")
private UUID id; private UUID id;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max= 200, message = "{validation.largerthanmax}")
private String code; private String code;
@NotNull(message = "{validation.empty}") public static final String _code = "code";
@NotEmpty(message = "{validation.empty}")
@Size(max= 500, message = "{validation.largerthanmax}")
private String name; private String name;
@NotNull(message = "{validation.empty}") public static final String _name = "name";
@NotEmpty(message = "{validation.empty}")
private String description; private String description;
public static final String _description = "description";
private TenantConfigPersist config; private TenantConfigPersist config;
public static final String _config = "config";
private String hash; private String hash;
public static final String _hash = "hash";
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -78,4 +88,64 @@ public class TenantPersist {
public void setHash(String hash) { public void setHash(String hash) {
this.hash = hash; this.hash = hash;
} }
@Component(TenantPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class TenantPersistValidator extends BaseValidator<TenantPersist> {
public static final String ValidatorName = "TenantPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected TenantPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<TenantPersist> modelClass() {
return TenantPersist.class;
}
@Override
protected List<Specification> specifications(TenantPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(TenantPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(TenantPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getCode()))
.failOn(TenantPersist._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantPersist._code}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getCode()))
.must(() -> this.lessEqualLength(item.getCode(), TenantEntity._codeLength))
.failOn(TenantPersist._code).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{TenantPersist._code}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getName()))
.failOn(TenantPersist._name).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantPersist._name}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getName()))
.must(() -> this.lessEqualLength(item.getName(), TenantEntity._nameLength))
.failOn(TenantPersist._name).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{TenantPersist._name}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getDescription()))
.failOn(TenantPersist._description).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantPersist._description}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getConfig()))
.on(TenantPersist._config)
.over(item.getConfig())
.using(() -> this.validatorFactory.validator(TenantConfigPersist.TenantConfigPersistValidator.class))
);
}
}
} }

View File

@ -1,77 +1,124 @@
package eu.eudat.model.persist; package eu.eudat.model.persist;
import eu.eudat.commons.validation.old.ValidId; import eu.eudat.commons.validation.BaseValidator;
import jakarta.validation.constraints.NotEmpty; import eu.eudat.commons.validation.specification.Specification;
import jakarta.validation.constraints.NotNull; import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public class UserAdditionalInfoPersist { public class UserAdditionalInfoPersist {
private String avatarUrl; private String avatarUrl;
@NotNull(message = "{validation.empty}") private String timezone;
@NotEmpty(message = "{validation.empty}")
private String timezone;
@NotNull(message = "{validation.empty}") public static final String _timezone = "timezone";
@NotEmpty(message = "{validation.empty}")
private String culture;
@NotNull(message = "{validation.empty}") private String culture;
@NotEmpty(message = "{validation.empty}")
private String language;
private String roleOrganization;
@ValidId(message = "{validation.invalidid}") public static final String _culture = "culture";
private UUID organizationId;
public String getAvatarUrl() { private String language;
return avatarUrl;
}
public void setAvatarUrl(String avatarUrl) { public static final String _language = "language";
this.avatarUrl = avatarUrl;
}
public String getTimezone() { private String roleOrganization;
return timezone;
}
public void setTimezone(String timezone) { private UUID organizationId;
this.timezone = timezone;
}
public String getCulture() { public static final String _organizationId = "organizationId";
return culture;
}
public void setCulture(String culture) { public String getAvatarUrl() {
this.culture = culture; return avatarUrl;
} }
public String getLanguage() { public void setAvatarUrl(String avatarUrl) {
return language; this.avatarUrl = avatarUrl;
} }
public void setLanguage(String language) { public String getTimezone() {
this.language = language; return timezone;
} }
public String getRoleOrganization() { public void setTimezone(String timezone) {
return roleOrganization; this.timezone = timezone;
} }
public void setRoleOrganization(String roleOrganization) { public String getCulture() {
this.roleOrganization = roleOrganization; return culture;
} }
public UUID getOrganizationId() { public void setCulture(String culture) {
return organizationId; this.culture = culture;
} }
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getRoleOrganization() {
return roleOrganization;
}
public void setRoleOrganization(String roleOrganization) {
this.roleOrganization = roleOrganization;
}
public UUID getOrganizationId() {
return organizationId;
}
public void setOrganizationId(UUID organizationId) {
this.organizationId = organizationId;
}
@Component(UserAdditionalInfoPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class UserAdditionalInfoPersistValidator extends BaseValidator<UserAdditionalInfoPersist> {
public static final String ValidatorName = "UserAdditionalInfoPersistValidator";
private final MessageSource messageSource;
protected UserAdditionalInfoPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<UserAdditionalInfoPersist> modelClass() {
return UserAdditionalInfoPersist.class;
}
@Override
protected List<Specification> specifications(UserAdditionalInfoPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getTimezone()))
.failOn(UserAdditionalInfoPersist._timezone).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserAdditionalInfoPersist._timezone}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getCulture()))
.failOn(UserAdditionalInfoPersist._culture).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserAdditionalInfoPersist._culture}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getLanguage()))
.failOn(UserAdditionalInfoPersist._language).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserAdditionalInfoPersist._language}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getOrganizationId()))
.failOn(UserAdditionalInfoPersist._organizationId).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserAdditionalInfoPersist._organizationId}, LocaleContextHolder.getLocale()))
);
}
}
public void setOrganizationId(UUID organizationId) {
this.organizationId = organizationId;
}
} }

View File

@ -1,33 +1,37 @@
package eu.eudat.model.persist; package eu.eudat.model.persist;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.commons.validation.old.ValidId; import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.UserEntity; import eu.eudat.data.UserEntity;
import jakarta.validation.Valid; import eu.eudat.errorcode.ErrorThesaurusProperties;
import jakarta.validation.constraints.NotEmpty; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import jakarta.validation.constraints.NotNull; import org.springframework.context.MessageSource;
import jakarta.validation.constraints.Size; import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID; import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class UserPersist { public class UserPersist {
@ValidId(message = "{validation.invalidid}")
private UUID id; private UUID id;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = UserEntity._nameLength, message = "{validation.largerthanmax}")
private String name; private String name;
public static final String _name = "name";
private String hash; private String hash;
@Valid public static final String _hash = "hash";
private UserAdditionalInfoPersist additionalInfo; private UserAdditionalInfoPersist additionalInfo;
public static final String _additionalInfo = "additionalInfo";
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -59,5 +63,55 @@ public class UserPersist {
public void setAdditionalInfo(UserAdditionalInfoPersist additionalInfo) { public void setAdditionalInfo(UserAdditionalInfoPersist additionalInfo) {
this.additionalInfo = additionalInfo; this.additionalInfo = additionalInfo;
} }
@Component(UserPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class UserPersistValidator extends BaseValidator<UserPersist> {
public static final String ValidatorName = "UserPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected UserPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<UserPersist> modelClass() {
return UserPersist.class;
}
@Override
protected List<Specification> specifications(UserPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(UserPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(UserPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getName()))
.failOn(UserPersist._name).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserPersist._name}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getName()))
.must(() -> this.lessEqualLength(item.getName(), UserEntity._nameLength))
.failOn(UserPersist._name).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{UserPersist._name}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getAdditionalInfo()))
.on(UserPersist._additionalInfo)
.over(item.getAdditionalInfo())
.using(() -> this.validatorFactory.validator(UserAdditionalInfoPersist.UserAdditionalInfoPersistValidator.class))
);
}
}
} }

View File

@ -1,27 +1,31 @@
package eu.eudat.model.persist; package eu.eudat.model.persist;
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 eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; import java.util.Arrays;
import eu.eudat.commons.validation.old.ValidId;
import jakarta.validation.constraints.NotNull;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class UserRolePatchPersist { public class UserRolePatchPersist {
@NotNull(message = "{validation.empty}")
@ValidId(message = "{validation.invalidid}")
private UUID id; private UUID id;
@NotNull(message = "{validation.empty}")
private List<String> roles; private List<String> roles;
@NotNull(message = "{validation.empty}") public static final String _roles = "roles";
private String hash; private String hash;
public static final String _hash = "hash";
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -45,5 +49,42 @@ public class UserRolePatchPersist {
public void setHash(String hash) { public void setHash(String hash) {
this.hash = hash; this.hash = hash;
} }
@Component(UserRolePatchPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class UserRolePatchPersistValidator extends BaseValidator<UserRolePatchPersist> {
public static final String ValidatorName = "UserRolePatchPersistValidator";
private final MessageSource messageSource;
protected UserRolePatchPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<UserRolePatchPersist> modelClass() {
return UserRolePatchPersist.class;
}
@Override
protected List<Specification> specifications(UserRolePatchPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(UserRolePatchPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserRolePatchPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(UserRolePatchPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getRoles()))
.failOn(UserRolePatchPersist._roles).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserRolePatchPersist._roles}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,80 +1,135 @@
package eu.eudat.model.persist; package eu.eudat.model.persist;
import eu.eudat.commons.enums.UserSettingsType; import eu.eudat.commons.enums.UserSettingsType;
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet; import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.old.ValidId; import eu.eudat.commons.validation.specification.Specification;
import jakarta.validation.constraints.NotEmpty; import eu.eudat.convention.ConventionService;
import jakarta.validation.constraints.NotNull; import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID; import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class UserSettingsPersist { public class UserSettingsPersist {
@ValidId(message = "{validation.invalidid}") private UUID id;
private UUID id;
@NotNull(message = "{validation.empty}") private String key;
@NotEmpty(message = "{validation.empty}")
private String key;
@NotNull(message = "{validation.empty}") public static final String _key = "key";
@NotEmpty(message = "{validation.empty}")
private String value;
@ValidId(message = "{validation.invalidid}") private String value;
private UUID entityId;
@NotNull(message = "{validation.empty}") public static final String _value = "value";
private UserSettingsType type;
private String hash; private UUID entityId;
public UUID getId() { public static final String _entityId = "entityId";
return id;
}
public void setId(UUID id) { private UserSettingsType type;
this.id = id;
}
public String getKey() { public static final String _type = "type";
return key;
}
public void setKey(String key) { private String hash;
this.key = key;
}
public UUID getEntityId() { public static final String _hash = "hash";
return entityId;
}
public void setEntityId(UUID entityId) { public UUID getId() {
this.entityId = entityId; return id;
} }
public UserSettingsType getType() { public void setId(UUID id) {
return type; this.id = id;
} }
public void setType(UserSettingsType type) { public String getKey() {
this.type = type; return key;
} }
public String getHash() { public void setKey(String key) {
return hash; this.key = key;
} }
public void setHash(String hash) { public UUID getEntityId() {
this.hash = hash; return entityId;
} }
public String getValue() { public void setEntityId(UUID entityId) {
return value; this.entityId = entityId;
} }
public UserSettingsType getType() {
return type;
}
public void setType(UserSettingsType type) {
this.type = type;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Component(UserSettingsPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class UserSettingsPersistValidator extends BaseValidator<UserSettingsPersist> {
public static final String ValidatorName = "UserSettingsPersistValidator";
private final MessageSource messageSource;
protected UserSettingsPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<UserSettingsPersist> modelClass() {
return UserSettingsPersist.class;
}
@Override
protected List<Specification> specifications(UserSettingsPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(UserSettingsPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserSettingsPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(UserSettingsPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getKey()))
.failOn(UserSettingsPersist._key).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserSettingsPersist._key}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getValue()))
.failOn(UserSettingsPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserSettingsPersist._value}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> this.isValidGuid(item.getEntityId()))
.failOn(UserSettingsPersist._entityId).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserSettingsPersist._entityId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getType()))
.failOn(UserSettingsPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserSettingsPersist._type}, LocaleContextHolder.getLocale()))
);
}
}
public void setValue(String value) {
this.value = value;
}
} }

View File

@ -8,6 +8,7 @@ import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Arrays; import java.util.Arrays;
@ -108,7 +109,24 @@ public class AuthenticationConfigurationPersist {
@Override @Override
protected List<Specification> specifications(AuthenticationConfigurationPersist item) { protected List<Specification> specifications(AuthenticationConfigurationPersist item) {
return Arrays.asList( return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getEnabled()))
.failOn(AuthenticationConfigurationPersist._enabled).failWith(messageSource.getMessage("Validation_Required", new Object[]{AuthenticationConfigurationPersist._enabled}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getAuthUrl()))
.failOn(AuthenticationConfigurationPersist._authUrl).failWith(messageSource.getMessage("Validation_Required", new Object[]{AuthenticationConfigurationPersist._authUrl}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getAuthMethod()))
.failOn(AuthenticationConfigurationPersist._authMethod).failWith(messageSource.getMessage("Validation_Required", new Object[]{AuthenticationConfigurationPersist._authMethod}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getAuthTokenPath()))
.failOn(AuthenticationConfigurationPersist._authTokenPath).failWith(messageSource.getMessage("Validation_Required", new Object[]{AuthenticationConfigurationPersist._authTokenPath}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getAuthRequestBody()))
.failOn(AuthenticationConfigurationPersist._authRequestBody).failWith(messageSource.getMessage("Validation_Required", new Object[]{AuthenticationConfigurationPersist._authRequestBody}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getType()))
.failOn(AuthenticationConfigurationPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{AuthenticationConfigurationPersist._type}, LocaleContextHolder.getLocale()))
); );
} }
} }

View File

@ -2,14 +2,14 @@ package eu.eudat.model.persist.referencetypedefinition;
import eu.eudat.commons.enums.ReferenceFieldDataType; import eu.eudat.commons.enums.ReferenceFieldDataType;
import eu.eudat.commons.validation.BaseValidator; import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.old.ValidEnum;
import eu.eudat.commons.validation.specification.Specification; import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.errorcode.ErrorThesaurusProperties;
import jakarta.validation.constraints.NotEmpty; import eu.eudat.model.persist.DescriptionPersist;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Arrays; import java.util.Arrays;
@ -17,74 +17,85 @@ import java.util.List;
public class ReferenceTypeFieldPersist { public class ReferenceTypeFieldPersist {
private String code = null; private String code = null;
public static final String _code = "code"; public static final String _code = "code";
private String label = null; private String label = null;
public static final String _label = "label"; public static final String _label = "label";
private String description; private String description;
private ReferenceFieldDataType dataType; private ReferenceFieldDataType dataType;
public static final String _dataType = "dataType"; public static final String _dataType = "dataType";
public String getCode() { public String getCode() {
return code; return code;
} }
public void setCode(String code) { public void setCode(String code) {
this.code = code; this.code = code;
} }
public String getLabel() { public String getLabel() {
return label; return label;
} }
public void setLabel(String label) { public void setLabel(String label) {
this.label = label; this.label = label;
} }
public String getDescription() { public String getDescription() {
return description; return description;
} }
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
public ReferenceFieldDataType getDataType() { public ReferenceFieldDataType getDataType() {
return dataType; return dataType;
} }
public void setDataType(ReferenceFieldDataType dataType) { public void setDataType(ReferenceFieldDataType dataType) {
this.dataType = dataType; this.dataType = dataType;
} }
@Component(ReferenceTypeFieldPersistValidator.ValidatorName) @Component(ReferenceTypeFieldPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ReferenceTypeFieldPersistValidator extends BaseValidator<ReferenceTypeFieldPersist> { public static class ReferenceTypeFieldPersistValidator extends BaseValidator<ReferenceTypeFieldPersist> {
public static final String ValidatorName = "ReferenceTypeFieldPersistValidator"; public static final String ValidatorName = "ReferenceTypeFieldPersistValidator";
protected ReferenceTypeFieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors) { private final MessageSource messageSource;
super(conventionService, errors);
}
@Override protected ReferenceTypeFieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
protected Class<ReferenceTypeFieldPersist> modelClass() { super(conventionService, errors);
return ReferenceTypeFieldPersist.class; this.messageSource = messageSource;
} }
@Override @Override
protected List<Specification> specifications(ReferenceTypeFieldPersist item) { protected Class<ReferenceTypeFieldPersist> modelClass() {
return Arrays.asList( return ReferenceTypeFieldPersist.class;
}
); @Override
} protected List<Specification> specifications(ReferenceTypeFieldPersist item) {
} return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getCode()))
.failOn(ReferenceTypeFieldPersist._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeFieldPersist._code}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getLabel()))
.failOn(ReferenceTypeFieldPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeFieldPersist._label}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getDataType()))
.failOn(ReferenceTypeFieldPersist._dataType).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeFieldPersist._dataType}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -2,16 +2,13 @@ package eu.eudat.model.persist.referencetypedefinition;
import eu.eudat.commons.enums.ReferenceTypeExternalApiHTTPMethodType; import eu.eudat.commons.enums.ReferenceTypeExternalApiHTTPMethodType;
import eu.eudat.commons.validation.ValidatorFactory; import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.commons.validation.old.ValidEnum;
import eu.eudat.commons.validation.specification.Specification; import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties; 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.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Arrays; import java.util.Arrays;
@ -21,7 +18,7 @@ public class ReferenceTypeSourceExternalApiConfigurationPersist extends Referenc
private String url; private String url;
public static final String _uri = "uri"; public static final String _url = "url";
private ResultsConfigurationPersist results; private ResultsConfigurationPersist results;
@ -154,7 +151,46 @@ public class ReferenceTypeSourceExternalApiConfigurationPersist extends Referenc
protected List<Specification> specifications(ReferenceTypeSourceExternalApiConfigurationPersist item) { protected List<Specification> specifications(ReferenceTypeSourceExternalApiConfigurationPersist item) {
List<Specification> specifications = getBaseSpecifications(item); List<Specification> specifications = getBaseSpecifications(item);
specifications.addAll(Arrays.asList( specifications.addAll(Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getUrl()))
.failOn(ReferenceTypeSourceExternalApiConfigurationPersist._url).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceExternalApiConfigurationPersist._url}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getPaginationPath()))
.failOn(ReferenceTypeSourceExternalApiConfigurationPersist._paginationPath).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceExternalApiConfigurationPersist._paginationPath}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getContentType()))
.failOn(ReferenceTypeSourceExternalApiConfigurationPersist._contentType).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceExternalApiConfigurationPersist._contentType}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getFirstPage()))
.failOn(ReferenceTypeSourceExternalApiConfigurationPersist._firstPage).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceExternalApiConfigurationPersist._firstPage}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getHttpMethod()))
.failOn(ReferenceTypeSourceExternalApiConfigurationPersist._httpMethod).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceExternalApiConfigurationPersist._httpMethod}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getResults()))
.failOn(ReferenceTypeSourceExternalApiConfigurationPersist._results).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceExternalApiConfigurationPersist._results}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getResults()))
.on(ReferenceTypeSourceExternalApiConfigurationPersist._results)
.over(item.getResults())
.using(() -> this.validatorFactory.validator(ResultsConfigurationPersist.ResultsConfigurationPersistValidator.class)),
this.spec()
.must(() -> !this.isNull(item.getAuth()))
.failOn(ReferenceTypeSourceExternalApiConfigurationPersist._auth).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceExternalApiConfigurationPersist._auth}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getAuth()))
.on(ReferenceTypeSourceExternalApiConfigurationPersist._auth)
.over(item.getAuth())
.using(() -> this.validatorFactory.validator(AuthenticationConfigurationPersist.AuthenticationConfigurationPersistValidator.class)),
this.spec()
.must(() -> !this.isNull(item.getQueries()))
.failOn(ReferenceTypeSourceExternalApiConfigurationPersist._queries).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceExternalApiConfigurationPersist._queries}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getQueries()))
.on(ReferenceTypeSourceExternalApiConfigurationPersist._queries)
.over(item.getQueries())
.using(() -> this.validatorFactory.validator(QueryConfigPersist.QueryConfigPersistValidator.class))
)); ));
return specifications; return specifications;
} }

View File

@ -5,7 +5,9 @@ import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Arrays; import java.util.Arrays;
@ -43,8 +45,11 @@ public class ResultFieldsMappingConfigurationPersist {
public static final String ValidatorName = "ResultFieldsMappingConfigurationPersistValidator"; public static final String ValidatorName = "ResultFieldsMappingConfigurationPersistValidator";
protected ResultFieldsMappingConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors) { private final MessageSource messageSource;
protected ResultFieldsMappingConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors); super(conventionService, errors);
this.messageSource = messageSource;
} }
@Override @Override
@ -55,7 +60,12 @@ public class ResultFieldsMappingConfigurationPersist {
@Override @Override
protected List<Specification> specifications(ResultFieldsMappingConfigurationPersist item) { protected List<Specification> specifications(ResultFieldsMappingConfigurationPersist item) {
return Arrays.asList( return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getCode()))
.failOn(ResultFieldsMappingConfigurationPersist._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{ResultFieldsMappingConfigurationPersist._code}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getResponsePath()))
.failOn(ResultFieldsMappingConfigurationPersist._responsePath).failWith(messageSource.getMessage("Validation_Required", new Object[]{ResultFieldsMappingConfigurationPersist._responsePath}, LocaleContextHolder.getLocale()))
); );
} }
} }

View File

@ -1,12 +1,14 @@
package eu.eudat.model.persist.referencetypedefinition; package eu.eudat.model.persist.referencetypedefinition;
import eu.eudat.commons.validation.BaseValidator; import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.commons.validation.specification.Specification; import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Arrays; import java.util.Arrays;
@ -46,9 +48,12 @@ public class ResultsConfigurationPersist {
private final MessageSource messageSource; private final MessageSource messageSource;
protected ResultsConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { private final ValidatorFactory validatorFactory;
protected ResultsConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors); super(conventionService, errors);
this.messageSource = messageSource; this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
} }
@Override @Override
@ -59,7 +64,18 @@ public class ResultsConfigurationPersist {
@Override @Override
protected List<Specification> specifications(ResultsConfigurationPersist item) { protected List<Specification> specifications(ResultsConfigurationPersist item) {
return Arrays.asList( return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getResultsArrayPath()))
.failOn(ResultsConfigurationPersist._resultsArrayPath).failWith(messageSource.getMessage("Validation_Required", new Object[]{ResultsConfigurationPersist._resultsArrayPath}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getFieldsMapping()))
.failOn(ResultsConfigurationPersist._fieldsMapping).failWith(messageSource.getMessage("Validation_Required", new Object[]{ResultsConfigurationPersist._fieldsMapping}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getFieldsMapping()))
.on(ResultsConfigurationPersist._fieldsMapping)
.over(item.getFieldsMapping())
.using(() -> this.validatorFactory.validator(ResultFieldsMappingConfigurationPersist.ResultFieldsMappingConfigurationPersistValidator.class))
); );
} }
} }

View File

@ -1,10 +1,27 @@
package eu.eudat.model.persist.tenantconfig; package eu.eudat.model.persist.tenantconfig;
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.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
public class TenantConfigPersist { public class TenantConfigPersist {
private TenantDepositConfigPersist deposit; private TenantDepositConfigPersist deposit;
public static final String _deposit = "deposit";
private TenantFileTransformersConfigPersist fileTransformers; private TenantFileTransformersConfigPersist fileTransformers;
public static final String _fileTransformers = "fileTransformers";
public TenantDepositConfigPersist getDeposit() { public TenantDepositConfigPersist getDeposit() {
return deposit; return deposit;
} }
@ -20,5 +37,41 @@ public class TenantConfigPersist {
public void setFileTransformers(TenantFileTransformersConfigPersist fileTransformers) { public void setFileTransformers(TenantFileTransformersConfigPersist fileTransformers) {
this.fileTransformers = fileTransformers; this.fileTransformers = fileTransformers;
} }
@Component(TenantConfigPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class TenantConfigPersistValidator extends BaseValidator<TenantConfigPersist> {
public static final String ValidatorName = "TenantConfigPersistValidator";
private final ValidatorFactory validatorFactory;
protected TenantConfigPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.validatorFactory = validatorFactory;
}
@Override
protected Class<TenantConfigPersist> modelClass() {
return TenantConfigPersist.class;
}
@Override
protected List<Specification> specifications(TenantConfigPersist item) {
return Arrays.asList(
this.refSpec()
.iff(() -> !this.isNull(item.getDeposit()))
.on(TenantConfigPersist._deposit)
.over(item.getDeposit())
.using(() -> this.validatorFactory.validator(TenantDepositConfigPersist.TenantDepositConfigPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getFileTransformers()))
.on(TenantConfigPersist._fileTransformers)
.over(item.getFileTransformers())
.using(() -> this.validatorFactory.validator(TenantFileTransformersConfigPersist.TenantFileTransformersConfigPersistValidator.class))
);
}
}
} }

View File

@ -1,15 +1,23 @@
package eu.eudat.model.persist.tenantconfig; package eu.eudat.model.persist.tenantconfig;
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.annotation.Scope;
import org.springframework.stereotype.Component;
import jakarta.validation.Valid; import java.util.Collections;
import java.util.List; import java.util.List;
public class TenantDepositConfigPersist { public class TenantDepositConfigPersist {
@Valid
private List<TenantSourcePersist> sources; private List<TenantSourcePersist> sources;
public static final String _sources = "sources";
public List<TenantSourcePersist> getSources() { public List<TenantSourcePersist> getSources() {
return sources; return sources;
} }
@ -17,4 +25,35 @@ public class TenantDepositConfigPersist {
public void setSources(List<TenantSourcePersist> sources) { public void setSources(List<TenantSourcePersist> sources) {
this.sources = sources; this.sources = sources;
} }
@Component(TenantDepositConfigPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class TenantDepositConfigPersistValidator extends BaseValidator<TenantDepositConfigPersist> {
public static final String ValidatorName = "TenantDepositConfigPersistValidator";
private final ValidatorFactory validatorFactory;
protected TenantDepositConfigPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.validatorFactory = validatorFactory;
}
@Override
protected Class<TenantDepositConfigPersist> modelClass() {
return TenantDepositConfigPersist.class;
}
@Override
protected List<Specification> specifications(TenantDepositConfigPersist item) {
return Collections.singletonList(
this.refSpec()
.iff(() -> !this.isNull(item.getSources()))
.on(TenantDepositConfigPersist._sources)
.over(item.getSources())
.using(() -> this.validatorFactory.validator(TenantSourcePersist.TenantSourcePersistValidator.class))
);
}
}
} }

View File

@ -1,15 +1,23 @@
package eu.eudat.model.persist.tenantconfig; package eu.eudat.model.persist.tenantconfig;
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.annotation.Scope;
import org.springframework.stereotype.Component;
import jakarta.validation.Valid; import java.util.Collections;
import java.util.List; import java.util.List;
public class TenantFileTransformersConfigPersist { public class TenantFileTransformersConfigPersist {
@Valid
private List<TenantSourcePersist> sources; private List<TenantSourcePersist> sources;
public static final String _sources = "sources";
public List<TenantSourcePersist> getSources() { public List<TenantSourcePersist> getSources() {
return sources; return sources;
} }
@ -17,4 +25,35 @@ public class TenantFileTransformersConfigPersist {
public void setSources(List<TenantSourcePersist> sources) { public void setSources(List<TenantSourcePersist> sources) {
this.sources = sources; this.sources = sources;
} }
@Component(TenantFileTransformersConfigPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class TenantFileTransformersConfigPersistValidator extends BaseValidator<TenantFileTransformersConfigPersist> {
public static final String ValidatorName = "TenantFileTransformersConfigPersistValidator";
private final ValidatorFactory validatorFactory;
protected TenantFileTransformersConfigPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.validatorFactory = validatorFactory;
}
@Override
protected Class<TenantFileTransformersConfigPersist> modelClass() {
return TenantFileTransformersConfigPersist.class;
}
@Override
protected List<Specification> specifications(TenantFileTransformersConfigPersist item) {
return Collections.singletonList(
this.refSpec()
.iff(() -> !this.isNull(item.getSources()))
.on(TenantFileTransformersConfigPersist._sources)
.over(item.getSources())
.using(() -> this.validatorFactory.validator(TenantSourcePersist.TenantSourcePersistValidator.class))
);
}
}
} }

View File

@ -1,37 +1,44 @@
package eu.eudat.model.persist.tenantconfig; package eu.eudat.model.persist.tenantconfig;
import jakarta.validation.Valid; import eu.eudat.commons.validation.BaseValidator;
import jakarta.validation.constraints.NotEmpty; import eu.eudat.commons.validation.specification.Specification;
import jakarta.validation.constraints.NotNull; import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List; import java.util.List;
public class TenantSourcePersist { public class TenantSourcePersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String url; private String url;
@NotNull(message = "{validation.empty}") public static final String _url = "url";
@NotEmpty(message = "{validation.empty}")
private List<String> codes; private List<String> codes;
@NotNull(message = "{validation.empty}") public static final String _codes = "codes";
@NotEmpty(message = "{validation.empty}")
private String issuerUrl ; private String issuerUrl;
public static final String _issuerUrl = "issuerUrl";
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String clientId; private String clientId;
@NotNull(message = "{validation.empty}") public static final String _clientId = "clientId";
@NotEmpty(message = "{validation.empty}")
private String clientSecret; private String clientSecret;
@NotNull(message = "{validation.empty}") public static final String _clientSecret = "clientSecret";
@NotEmpty(message = "{validation.empty}")
private String scope; private String scope;
public static final String _scope = "scope";
public String getUrl() { public String getUrl() {
return url; return url;
} }
@ -79,4 +86,48 @@ public class TenantSourcePersist {
public void setScope(String scope) { public void setScope(String scope) {
this.scope = scope; this.scope = scope;
} }
@Component(TenantSourcePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class TenantSourcePersistValidator extends BaseValidator<TenantSourcePersist> {
public static final String ValidatorName = "TenantSourcePersistValidator";
private final MessageSource messageSource;
protected TenantSourcePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<TenantSourcePersist> modelClass() {
return TenantSourcePersist.class;
}
@Override
protected List<Specification> specifications(TenantSourcePersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getUrl()))
.failOn(TenantSourcePersist._url).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantSourcePersist._url}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getCodes()))
.failOn(TenantSourcePersist._codes).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantSourcePersist._codes}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getIssuerUrl()))
.failOn(TenantSourcePersist._issuerUrl).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantSourcePersist._issuerUrl}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getClientId()))
.failOn(TenantSourcePersist._clientId).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantSourcePersist._clientId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getClientSecret()))
.failOn(TenantSourcePersist._clientSecret).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantSourcePersist._clientSecret}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getScope()))
.failOn(TenantSourcePersist._scope).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantSourcePersist._scope}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -6,6 +6,7 @@ import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission; import eu.eudat.authorization.Permission;
import eu.eudat.commons.enums.*; import eu.eudat.commons.enums.*;
import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.StorageFileEntity; import eu.eudat.data.StorageFileEntity;
import eu.eudat.model.*; import eu.eudat.model.*;
@ -70,6 +71,7 @@ public class StorageFileController {
private final UserScope userScope; private final UserScope userScope;
private final AuthorizationService authorizationService; private final AuthorizationService authorizationService;
private final ConventionService conventionService; private final ConventionService conventionService;
private final ValidatorFactory validatorFactory;
public StorageFileController( public StorageFileController(
AuditService auditService, AuditService auditService,
QueryFactory queryFactory, QueryFactory queryFactory,
@ -77,7 +79,7 @@ public class StorageFileController {
StorageFileService storageFileService, StorageFileService storageFileService,
StorageFileProperties config, StorageFileProperties config,
UserScope userScope, UserScope userScope,
AuthorizationService authorizationService, ConventionService conventionService) { AuthorizationService authorizationService, ConventionService conventionService, ValidatorFactory validatorFactory) {
this.auditService = auditService; this.auditService = auditService;
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.messageSource = messageSource; this.messageSource = messageSource;
@ -86,6 +88,7 @@ public class StorageFileController {
this.userScope = userScope; this.userScope = userScope;
this.authorizationService = authorizationService; this.authorizationService = authorizationService;
this.conventionService = conventionService; this.conventionService = conventionService;
this.validatorFactory = validatorFactory;
} }
@ -105,6 +108,7 @@ public class StorageFileController {
storageFilePersist.setOwnerId(this.userScope.getUserIdSafe()); storageFilePersist.setOwnerId(this.userScope.getUserIdSafe());
storageFilePersist.setStorageType(StorageType.Temp); storageFilePersist.setStorageType(StorageType.Temp);
storageFilePersist.setLifetime(Duration.ofSeconds(this.config.getTempStoreLifetimeSeconds())); storageFilePersist.setLifetime(Duration.ofSeconds(this.config.getTempStoreLifetimeSeconds()));
this.validatorFactory.validator(StorageFilePersist.StorageFilePersistValidator.class).validateForce(storageFilePersist);
StorageFile persisted = this.storageFileService.persistBytes(storageFilePersist, file.getBytes(), new BaseFieldSet(StorageFile._id, StorageFile._name)); StorageFile persisted = this.storageFileService.persistBytes(storageFilePersist, file.getBytes(), new BaseFieldSet(StorageFile._id, StorageFile._name));
addedFiles.add(persisted); addedFiles.add(persisted);

View File

@ -3,6 +3,7 @@ package eu.eudat.controllers.v2;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.audit.AuditableAction; import eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.validation.ValidationFilterAnnotation;
import eu.eudat.data.SupportiveMaterialEntity; import eu.eudat.data.SupportiveMaterialEntity;
import eu.eudat.model.SupportiveMaterial; import eu.eudat.model.SupportiveMaterial;
import eu.eudat.model.builder.SupportiveMaterialBuilder; import eu.eudat.model.builder.SupportiveMaterialBuilder;
@ -23,7 +24,6 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate;
import jakarta.transaction.Transactional; import jakarta.transaction.Transactional;
import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.JAXBException;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -50,14 +50,21 @@ import java.util.stream.Stream;
public class SupportiveMaterialController { public class SupportiveMaterialController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(SupportiveMaterialController.class)); private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(SupportiveMaterialController.class));
private Environment environment; private Environment environment;
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
private final AuditService auditService; private final AuditService auditService;
private final CensorFactory censorFactory; private final CensorFactory censorFactory;
private final QueryFactory queryFactory; private final QueryFactory queryFactory;
private final MessageSource messageSource; private final MessageSource messageSource;
private final SupportiveMaterialService supportiveMaterialService; private final SupportiveMaterialService supportiveMaterialService;
private final AuthorizationService authorizationService; private final AuthorizationService authorizationService;
@Autowired @Autowired
@ -117,19 +124,19 @@ public class SupportiveMaterialController {
SupportiveMaterialQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); SupportiveMaterialQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic);
List<SupportiveMaterialEntity> data = query.collectAs(lookup.getProject()); List<SupportiveMaterialEntity> data = query.collectAs(lookup.getProject());
if (data.size() == 1){ if (data.size() == 1) {
return new ResponseEntity<>(data.get(0).getPayload().getBytes(), HttpStatus.OK); return new ResponseEntity<>(data.get(0).getPayload().getBytes(), HttpStatus.OK);
} }
try (Stream<Path> paths = Files.walk(Paths.get(Objects.requireNonNull(this.environment.getProperty(lookup.getTypes().stream().toList().get(0).name().toLowerCase() +".path"))))) { try (Stream<Path> paths = Files.walk(Paths.get(Objects.requireNonNull(this.environment.getProperty(lookup.getTypes().stream().toList().get(0).name().toLowerCase() + ".path"))))) {
return this.supportiveMaterialService.getResponseEntity(lookup.getLanguageCodes().get(0), paths); return this.supportiveMaterialService.getResponseEntity(lookup.getLanguageCodes().get(0), paths);
} }
} }
@PostMapping("persist") @PostMapping("persist")
@Transactional @Transactional
public SupportiveMaterial persist(@MyValidate @RequestBody SupportiveMaterialPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException { @ValidationFilterAnnotation(validator = SupportiveMaterialPersist.SupportiveMaterialPersistValidator.ValidatorName, argumentName = "model")
public SupportiveMaterial persist(@RequestBody SupportiveMaterialPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException {
logger.debug(new MapLogEntry("persisting" + SupportiveMaterial.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); logger.debug(new MapLogEntry("persisting" + SupportiveMaterial.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
this.censorFactory.censor(SupportiveMaterialCensor.class).censor(fieldSet, null); this.censorFactory.censor(SupportiveMaterialCensor.class).censor(fieldSet, null);
@ -152,5 +159,4 @@ public class SupportiveMaterialController {
this.auditService.track(AuditableAction.SupportiveMaterial_Delete, "id", id); this.auditService.track(AuditableAction.SupportiveMaterial_Delete, "id", id);
} }
} }

View File

@ -38,10 +38,12 @@ import java.util.*;
public class TagController { public class TagController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TagController.class)); private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TagController.class));
@Autowired @Autowired
private ApiContext apiContext; private ApiContext apiContext;
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
private final AuditService auditService; private final AuditService auditService;
private final TagService tagService; private final TagService tagService;
@ -80,7 +82,6 @@ public class TagController {
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
this.auditService.track(AuditableAction.Tag_Query, "lookup", lookup); this.auditService.track(AuditableAction.Tag_Query, "lookup", lookup);
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return new QueryResult<>(models, count); return new QueryResult<>(models, count);
} }
@ -100,14 +101,13 @@ public class TagController {
new AbstractMap.SimpleEntry<String, Object>("id", id), new AbstractMap.SimpleEntry<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet) new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
)); ));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return model; return model;
} }
@PostMapping("persist") @PostMapping("persist")
@Transactional @Transactional
@ValidationFilterAnnotation(validator = TagPersist.TagPersistValidator.ValidatorName, argumentName ="model") @ValidationFilterAnnotation(validator = TagPersist.TagPersistValidator.ValidatorName, argumentName = "model")
public Tag Persist(@RequestBody TagPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException { public Tag Persist(@RequestBody TagPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
logger.debug(new MapLogEntry("persisting" + Tag.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); logger.debug(new MapLogEntry("persisting" + Tag.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
Tag persisted = this.tagService.persist(model, fieldSet); Tag persisted = this.tagService.persist(model, fieldSet);
@ -116,7 +116,7 @@ public class TagController {
new AbstractMap.SimpleEntry<String, Object>("model", model), new AbstractMap.SimpleEntry<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet) new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
)); ));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return persisted; return persisted;
} }
@ -128,6 +128,5 @@ public class TagController {
this.tagService.deleteAndSave(id); this.tagService.deleteAndSave(id);
this.auditService.track(AuditableAction.Tag_Delete, "id", id); this.auditService.track(AuditableAction.Tag_Delete, "id", id);
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
} }
} }

View File

@ -3,13 +3,13 @@ package eu.eudat.controllers.v2;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.audit.AuditableAction; import eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.validation.ValidationFilterAnnotation;
import eu.eudat.data.TenantEntity; import eu.eudat.data.TenantEntity;
import eu.eudat.model.Tenant; import eu.eudat.model.Tenant;
import eu.eudat.model.builder.TenantBuilder; import eu.eudat.model.builder.TenantBuilder;
import eu.eudat.model.censorship.TenantCensor; import eu.eudat.model.censorship.TenantCensor;
import eu.eudat.model.persist.TenantPersist; import eu.eudat.model.persist.TenantPersist;
import eu.eudat.model.result.QueryResult; import eu.eudat.model.result.QueryResult;
import eu.eudat.model.tenantconfig.TenantSource;
import eu.eudat.query.TenantQuery; import eu.eudat.query.TenantQuery;
import eu.eudat.query.lookup.TenantLookup; import eu.eudat.query.lookup.TenantLookup;
import eu.eudat.service.tenant.TenantService; import eu.eudat.service.tenant.TenantService;
@ -23,7 +23,6 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate;
import jakarta.transaction.Transactional; import jakarta.transaction.Transactional;
import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.JAXBException;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -44,7 +43,6 @@ import java.util.AbstractMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
@RestController @RestController
@RequestMapping(path = "api/tenant") @RequestMapping(path = "api/tenant")
@ -88,7 +86,7 @@ public class TenantController {
List<TenantEntity> data = query.collectAs(lookup.getProject()); List<TenantEntity> data = query.collectAs(lookup.getProject());
List<Tenant> models = this.builderFactory.builder(TenantBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); List<Tenant> models = this.builderFactory.builder(TenantBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data);
for (Tenant model: models) { for (Tenant model : models) {
models.set(models.indexOf(model), this.tenantService.decryptTenant(model)); models.set(models.indexOf(model), this.tenantService.decryptTenant(model));
} }
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
@ -121,10 +119,11 @@ public class TenantController {
@PostMapping("persist") @PostMapping("persist")
@Transactional @Transactional
public Tenant persist(@MyValidate @RequestBody TenantPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { @ValidationFilterAnnotation(validator = TenantPersist.TenantPersistValidator.ValidatorName, argumentName = "model")
public Tenant persist(@RequestBody TenantPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
logger.debug(new MapLogEntry("persisting" + Tenant.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); logger.debug(new MapLogEntry("persisting" + Tenant.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
this.censorFactory.censor(TenantCensor.class).censor(fieldSet, null); this.censorFactory.censor(TenantCensor.class).censor(fieldSet, null);
Tenant persisted = this.tenantService.persist(model, fieldSet); Tenant persisted = this.tenantService.persist(model, fieldSet);
this.auditService.track(AuditableAction.Tenant_Persist, Map.ofEntries( this.auditService.track(AuditableAction.Tenant_Persist, Map.ofEntries(

View File

@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.audit.AuditableAction; import eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.commons.validation.ValidationFilterAnnotation;
import eu.eudat.data.UserEntity; import eu.eudat.data.UserEntity;
import eu.eudat.model.User; import eu.eudat.model.User;
import eu.eudat.model.UserRole; import eu.eudat.model.UserRole;
@ -43,7 +44,10 @@ import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerException;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@RestController @RestController
@RequestMapping(path = "api/user") @RequestMapping(path = "api/user")
@ -60,9 +64,11 @@ public class UserController {
private final CensorFactory censorFactory; private final CensorFactory censorFactory;
private final QueryFactory queryFactory; private final QueryFactory queryFactory;
private final UserScope userScope; private final UserScope userScope;
private final MessageSource messageSource; private final MessageSource messageSource;
private final ResponseUtilsService responseUtilsService; private final ResponseUtilsService responseUtilsService;
public UserController( public UserController(
@ -71,8 +77,8 @@ public class UserController {
UserService userTypeService, UserService userTypeService,
CensorFactory censorFactory, CensorFactory censorFactory,
QueryFactory queryFactory, QueryFactory queryFactory,
UserScope userScope, UserScope userScope,
MessageSource messageSource, MessageSource messageSource,
ResponseUtilsService responseUtilsService) { ResponseUtilsService responseUtilsService) {
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.auditService = auditService; this.auditService = auditService;
@ -97,7 +103,6 @@ public class UserController {
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
this.auditService.track(AuditableAction.User_Query, "lookup", lookup); this.auditService.track(AuditableAction.User_Query, "lookup", lookup);
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return new QueryResult<>(models, count); return new QueryResult<>(models, count);
} }
@ -117,7 +122,6 @@ public class UserController {
new AbstractMap.SimpleEntry<String, Object>("id", id), new AbstractMap.SimpleEntry<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet) new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
)); ));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return model; return model;
} }
@ -137,7 +141,6 @@ public class UserController {
new AbstractMap.SimpleEntry<String, Object>("email", email), new AbstractMap.SimpleEntry<String, Object>("email", email),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet) new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
)); ));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return model; return model;
} }
@ -149,10 +152,9 @@ public class UserController {
// this.censorFactory.censor(UserCensor.class).censor(fieldSet, null); // this.censorFactory.censor(UserCensor.class).censor(fieldSet, null);
byte[] bytes = this.userTypeService.exportCsv(); byte[] bytes = this.userTypeService.exportCsv();
this.auditService.track(AuditableAction.User_ExportCsv, Map.ofEntries( this.auditService.track(AuditableAction.User_ExportCsv, Map.ofEntries(
)); ));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return this.responseUtilsService.buildResponseFileFromText(new String(bytes, StandardCharsets.UTF_8), "Users_dump.csv"); return this.responseUtilsService.buildResponseFileFromText(new String(bytes, StandardCharsets.UTF_8), "Users_dump.csv");
} }
@ -171,7 +173,6 @@ public class UserController {
new AbstractMap.SimpleEntry<String, Object>("id", id), new AbstractMap.SimpleEntry<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet) new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
)); ));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return model; return model;
} }
@ -211,7 +212,8 @@ public class UserController {
@PostMapping("persist") @PostMapping("persist")
@Transactional @Transactional
public User persist(@MyValidate @RequestBody UserPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException { @ValidationFilterAnnotation(validator = UserPersist.UserPersistValidator.ValidatorName, argumentName = "model")
public User persist(@RequestBody UserPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException {
logger.debug(new MapLogEntry("persisting" + User.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); logger.debug(new MapLogEntry("persisting" + User.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
User persisted = this.userTypeService.persist(model, fieldSet); User persisted = this.userTypeService.persist(model, fieldSet);
@ -219,13 +221,14 @@ public class UserController {
new AbstractMap.SimpleEntry<String, Object>("model", model), new AbstractMap.SimpleEntry<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet) new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
)); ));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return persisted; return persisted;
} }
@PostMapping("persist/roles") @PostMapping("persist/roles")
@Transactional @Transactional
public User persistRoles(@MyValidate @RequestBody UserRolePatchPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException { @ValidationFilterAnnotation(validator = UserRolePatchPersist.UserRolePatchPersistValidator.ValidatorName, argumentName = "model")
public User persistRoles(@RequestBody UserRolePatchPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException {
logger.debug(new MapLogEntry("persisting" + UserRole.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); logger.debug(new MapLogEntry("persisting" + UserRole.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
User persisted = this.userTypeService.patchRoles(model, fieldSet); User persisted = this.userTypeService.patchRoles(model, fieldSet);
@ -233,7 +236,7 @@ public class UserController {
new AbstractMap.SimpleEntry<String, Object>("model", model), new AbstractMap.SimpleEntry<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet) new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
)); ));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return persisted; return persisted;
} }
@ -245,12 +248,11 @@ public class UserController {
this.userTypeService.deleteAndSave(id); this.userTypeService.deleteAndSave(id);
this.auditService.track(AuditableAction.User_Delete, "id", id); this.auditService.track(AuditableAction.User_Delete, "id", id);
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
} }
@GetMapping("mine/merge-account-request/{email}") @GetMapping("mine/merge-account-request/{email}")
@Transactional @Transactional
public ResponseEntity mergeAccount(@PathVariable("email") String email) throws InvalidApplicationException, JAXBException { public ResponseEntity<ResponseItem<String>> mergeAccount(@PathVariable("email") String email) throws InvalidApplicationException, JAXBException {
logger.debug(new MapLogEntry("merge account to user").And("email", email)); logger.debug(new MapLogEntry("merge account to user").And("email", email));
this.userTypeService.sendMergeAccountConfirmation(email); this.userTypeService.sendMergeAccountConfirmation(email);
@ -264,7 +266,7 @@ public class UserController {
@GetMapping("mine/confirm-merge-account/token/{token}") @GetMapping("mine/confirm-merge-account/token/{token}")
@Transactional @Transactional
public ResponseEntity confirmMergeAccount(@PathVariable("token") String token) throws InvalidApplicationException, JAXBException { public ResponseEntity<ResponseItem<String>> confirmMergeAccount(@PathVariable("token") String token) throws InvalidApplicationException, JAXBException {
logger.debug(new MapLogEntry("confirm merge account to user").And("token", token)); logger.debug(new MapLogEntry("confirm merge account to user").And("token", token));
this.userTypeService.confirmMergeAccount(token); this.userTypeService.confirmMergeAccount(token);
@ -278,7 +280,7 @@ public class UserController {
@GetMapping("mine/remove-credential-request/{email}") @GetMapping("mine/remove-credential-request/{email}")
@Transactional @Transactional
public ResponseEntity removeCredentialAccount(@PathVariable("email") String email) throws InvalidApplicationException, JAXBException { public ResponseEntity<ResponseItem<String>> removeCredentialAccount(@PathVariable("email") String email) throws InvalidApplicationException, JAXBException {
logger.debug(new MapLogEntry("remove credential request to user").And("email", email)); logger.debug(new MapLogEntry("remove credential request to user").And("email", email));
this.userTypeService.sendRemoveCredentialConfirmation(email); this.userTypeService.sendRemoveCredentialConfirmation(email);
@ -292,7 +294,7 @@ public class UserController {
@GetMapping("mine/confirm-remove-credential/token/{token}") @GetMapping("mine/confirm-remove-credential/token/{token}")
@Transactional @Transactional
public ResponseEntity confirmRemoveCredentialAccount(@PathVariable("token") String token) throws InvalidApplicationException, JAXBException { public ResponseEntity<ResponseItem<String>> confirmRemoveCredentialAccount(@PathVariable("token") String token) throws InvalidApplicationException, JAXBException {
logger.debug(new MapLogEntry("confirm remove credential to user").And("token", token)); logger.debug(new MapLogEntry("confirm remove credential to user").And("token", token));
this.userTypeService.confirmRemoveCredential(token); this.userTypeService.confirmRemoveCredential(token);

View File

@ -1,6 +1,8 @@
package eu.eudat.controllers.v2; package eu.eudat.controllers.v2;
import eu.eudat.audit.AuditableAction; import eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.validation.ValidationFilterAnnotation;
import eu.eudat.data.UserSettingsEntity; import eu.eudat.data.UserSettingsEntity;
import eu.eudat.model.UserSettings; import eu.eudat.model.UserSettings;
import eu.eudat.model.builder.UserSettingsBuilder; import eu.eudat.model.builder.UserSettingsBuilder;
@ -29,7 +31,10 @@ import org.springframework.context.MessageSource;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;
import java.util.*; import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@RestController @RestController
@RequestMapping(path = "api/user-settings") @RequestMapping(path = "api/user-settings")
@ -38,10 +43,15 @@ public class UserSettingsController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserSettingsController.class)); private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserSettingsController.class));
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
private final AuditService auditService; private final AuditService auditService;
private final UserSettingsService settingsService; private final UserSettingsService settingsService;
private final CensorFactory censorFactory; private final CensorFactory censorFactory;
private final QueryFactory queryFactory; private final QueryFactory queryFactory;
private final MessageSource messageSource; private final MessageSource messageSource;
@Autowired @Autowired
@ -70,7 +80,6 @@ public class UserSettingsController {
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
this.auditService.track(AuditableAction.User_Settings_Query, "lookup", lookup); this.auditService.track(AuditableAction.User_Settings_Query, "lookup", lookup);
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return new QueryResult<>(models, count); return new QueryResult<>(models, count);
} }
@ -102,6 +111,7 @@ public class UserSettingsController {
@PostMapping("persist") @PostMapping("persist")
@Transactional @Transactional
@ValidationFilterAnnotation(validator = UserSettingsPersist.UserSettingsPersistValidator.ValidatorName, argumentName = "model")
public UserSettings Persist(@MyValidate @RequestBody UserSettingsPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException { public UserSettings Persist(@MyValidate @RequestBody UserSettingsPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
logger.debug(new MapLogEntry("persisting" + UserSettings.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); logger.debug(new MapLogEntry("persisting" + UserSettings.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
@ -111,7 +121,7 @@ public class UserSettingsController {
new AbstractMap.SimpleEntry<String, Object>("model", model), new AbstractMap.SimpleEntry<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet) new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
)); ));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return persisted; return persisted;
} }