Implementing validators for Tenant and other persist models (completed)

This commit is contained in:
Thomas Georgios Giannos 2024-01-04 11:51:56 +02:00
parent eb2b5d4df3
commit 18a4684859
13 changed files with 492 additions and 120 deletions

View File

@ -24,9 +24,10 @@ public class SupportiveMaterialEntity extends TenantScopedBaseEntity {
private SupportiveMaterialFieldType 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;
public static final String _languageCode = "languageCode";
public static final int _languageCodeLength = 20;
@Column(name = "payload", nullable = false)
private String payload;

View File

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

View File

@ -1,37 +1,40 @@
package eu.eudat.model.persist;
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 jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
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.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class StorageFilePersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = StorageFileEntity._nameLen, message = "{validation.largerthanmax}")
private String name;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = StorageFileEntity._extensionLen, message = "{validation.largerthanmax}")
public static final String _name = "name";
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;
@NotNull(message = "{validation.empty}")
@ValidEnum(message = "{validation.empty}")
public static final String _mimeType = "mimeType";
private StorageType storageType;
public static final String _storageType = "storageType";
private Duration lifetime;
private UUID ownerId;
@ -83,4 +86,54 @@ public class StorageFilePersist {
public void setLifetime(Duration 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,32 +1,41 @@
package eu.eudat.model.persist;
import eu.eudat.commons.enums.SupportiveMaterialFieldType;
import eu.eudat.commons.validation.old.ValidEnum;
import eu.eudat.commons.validation.old.ValidId;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.SupportiveMaterialEntity;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class SupportiveMaterialPersist {
@ValidId(message = "{validation.invalidid}")
private UUID id;
@ValidEnum(message = "{validation.empty}")
private SupportiveMaterialFieldType type;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = 20, message = "{validation.largerthanmax}")
public static final String _type = "type";
private String languageCode;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
public static final String _languageCode = "languageCode";
private String payload;
public static final String _payload = "payload";
private String hash;
public static final String _hash = "hash";
public UUID getId() {
return id;
}
@ -66,4 +75,51 @@ public class SupportiveMaterialPersist {
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()))
);
}
}
}

View File

@ -1,36 +1,46 @@
package eu.eudat.model.persist;
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
import eu.eudat.commons.validation.old.ValidId;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.TenantEntity;
import eu.eudat.errorcode.ErrorThesaurusProperties;
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;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class TenantPersist {
@ValidId(message = "{validation.invalidid}")
private UUID id;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max= 200, message = "{validation.largerthanmax}")
private String code;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max= 500, message = "{validation.largerthanmax}")
public static final String _code = "code";
private String name;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
public static final String _name = "name";
private String description;
public static final String _description = "description";
private TenantConfigPersist config;
public static final String _config = "config";
private String hash;
public static final String _hash = "hash";
public UUID getId() {
return id;
}
@ -78,4 +88,64 @@ public class TenantPersist {
public void setHash(String 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,10 +1,27 @@
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 {
private TenantDepositConfigPersist deposit;
public static final String _deposit = "deposit";
private TenantFileTransformersConfigPersist fileTransformers;
public static final String _fileTransformers = "fileTransformers";
public TenantDepositConfigPersist getDeposit() {
return deposit;
}
@ -20,5 +37,41 @@ public class TenantConfigPersist {
public void setFileTransformers(TenantFileTransformersConfigPersist 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;
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;
public class TenantDepositConfigPersist {
@Valid
private List<TenantSourcePersist> sources;
public static final String _sources = "sources";
public List<TenantSourcePersist> getSources() {
return sources;
}
@ -17,4 +25,35 @@ public class TenantDepositConfigPersist {
public void setSources(List<TenantSourcePersist> 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;
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;
public class TenantFileTransformersConfigPersist {
@Valid
private List<TenantSourcePersist> sources;
public static final String _sources = "sources";
public List<TenantSourcePersist> getSources() {
return sources;
}
@ -17,4 +25,35 @@ public class TenantFileTransformersConfigPersist {
public void setSources(List<TenantSourcePersist> 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;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
public class TenantSourcePersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String url;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
public static final String _url = "url";
private List<String> codes;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String issuerUrl ;
public static final String _codes = "codes";
private String issuerUrl;
public static final String _issuerUrl = "issuerUrl";
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String clientId;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
public static final String _clientId = "clientId";
private String clientSecret;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
public static final String _clientSecret = "clientSecret";
private String scope;
public static final String _scope = "scope";
public String getUrl() {
return url;
}
@ -79,4 +86,48 @@ public class TenantSourcePersist {
public void setScope(String 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.commons.enums.*;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.StorageFileEntity;
import eu.eudat.model.*;
@ -70,6 +71,7 @@ public class StorageFileController {
private final UserScope userScope;
private final AuthorizationService authorizationService;
private final ConventionService conventionService;
private final ValidatorFactory validatorFactory;
public StorageFileController(
AuditService auditService,
QueryFactory queryFactory,
@ -77,7 +79,7 @@ public class StorageFileController {
StorageFileService storageFileService,
StorageFileProperties config,
UserScope userScope,
AuthorizationService authorizationService, ConventionService conventionService) {
AuthorizationService authorizationService, ConventionService conventionService, ValidatorFactory validatorFactory) {
this.auditService = auditService;
this.queryFactory = queryFactory;
this.messageSource = messageSource;
@ -86,6 +88,7 @@ public class StorageFileController {
this.userScope = userScope;
this.authorizationService = authorizationService;
this.conventionService = conventionService;
this.validatorFactory = validatorFactory;
}
@ -105,6 +108,7 @@ public class StorageFileController {
storageFilePersist.setOwnerId(this.userScope.getUserIdSafe());
storageFilePersist.setStorageType(StorageType.Temp);
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));
addedFiles.add(persisted);

View File

@ -3,6 +3,7 @@ package eu.eudat.controllers.v2;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.validation.ValidationFilterAnnotation;
import eu.eudat.data.SupportiveMaterialEntity;
import eu.eudat.model.SupportiveMaterial;
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.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate;
import jakarta.transaction.Transactional;
import jakarta.xml.bind.JAXBException;
import org.slf4j.LoggerFactory;
@ -50,14 +50,21 @@ import java.util.stream.Stream;
public class SupportiveMaterialController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(SupportiveMaterialController.class));
private Environment environment;
private final BuilderFactory builderFactory;
private final AuditService auditService;
private final CensorFactory censorFactory;
private final QueryFactory queryFactory;
private final MessageSource messageSource;
private final SupportiveMaterialService supportiveMaterialService;
private final AuthorizationService authorizationService;
@Autowired
@ -117,19 +124,19 @@ public class SupportiveMaterialController {
SupportiveMaterialQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic);
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);
}
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);
}
}
@PostMapping("persist")
@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));
this.censorFactory.censor(SupportiveMaterialCensor.class).censor(fieldSet, null);
@ -152,5 +159,4 @@ public class SupportiveMaterialController {
this.auditService.track(AuditableAction.SupportiveMaterial_Delete, "id", id);
}
}

View File

@ -38,10 +38,12 @@ import java.util.*;
public class TagController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TagController.class));
@Autowired
private ApiContext apiContext;
private final BuilderFactory builderFactory;
private final AuditService auditService;
private final TagService tagService;
@ -80,7 +82,6 @@ public class TagController {
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
this.auditService.track(AuditableAction.Tag_Query, "lookup", lookup);
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return new QueryResult<>(models, count);
}
@ -100,14 +101,13 @@ public class TagController {
new AbstractMap.SimpleEntry<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return model;
}
@PostMapping("persist")
@Transactional
@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 {
logger.debug(new MapLogEntry("persisting" + Tag.class.getSimpleName()).And("model", model).And("fieldSet", 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>("fields", fieldSet)
));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return persisted;
}
@ -128,6 +128,5 @@ public class TagController {
this.tagService.deleteAndSave(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 eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.validation.ValidationFilterAnnotation;
import eu.eudat.data.TenantEntity;
import eu.eudat.model.Tenant;
import eu.eudat.model.builder.TenantBuilder;
import eu.eudat.model.censorship.TenantCensor;
import eu.eudat.model.persist.TenantPersist;
import eu.eudat.model.result.QueryResult;
import eu.eudat.model.tenantconfig.TenantSource;
import eu.eudat.query.TenantQuery;
import eu.eudat.query.lookup.TenantLookup;
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.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate;
import jakarta.transaction.Transactional;
import jakarta.xml.bind.JAXBException;
import org.slf4j.LoggerFactory;
@ -44,7 +43,6 @@ import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
@RestController
@RequestMapping(path = "api/tenant")
@ -88,7 +86,7 @@ public class TenantController {
List<TenantEntity> data = query.collectAs(lookup.getProject());
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));
}
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
@ -121,7 +119,8 @@ public class TenantController {
@PostMapping("persist")
@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));
this.censorFactory.censor(TenantCensor.class).censor(fieldSet, null);