tenant configuration changes

This commit is contained in:
Efstratios Giannopoulos 2024-04-19 18:39:51 +03:00
parent 0a26968462
commit 2be94e39ff
47 changed files with 1700 additions and 1118 deletions

View File

@ -1,34 +0,0 @@
package eu.eudat.commons.types.tenant;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "config")
@XmlAccessorType(XmlAccessType.FIELD)
public class TenantConfigEntity {
@XmlElement(name = "deposit-configuration")
private TenantDepositConfigEntity deposit;
@XmlElement(name = "file-transformers-configuration")
private TenantFileTransformersConfigEntity fileTransformers;
public TenantDepositConfigEntity getDeposit() {
return deposit;
}
public void setDeposit(TenantDepositConfigEntity deposit) {
this.deposit = deposit;
}
public TenantFileTransformersConfigEntity getFileTransformers() {
return fileTransformers;
}
public void setFileTransformers(TenantFileTransformersConfigEntity fileTransformers) {
this.fileTransformers = fileTransformers;
}
}

View File

@ -1,25 +0,0 @@
package eu.eudat.commons.types.tenant;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class TenantDepositConfigEntity {
@XmlElementWrapper(name = "sources")
@XmlElement(name = "source")
private List<TenantSourceEntity> sources;
public List<TenantSourceEntity> getSources() {
return sources;
}
public void setSources(List<TenantSourceEntity> sources) {
this.sources = sources;
}
}

View File

@ -1,24 +0,0 @@
package eu.eudat.commons.types.tenant;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class TenantFileTransformersConfigEntity {
@XmlElementWrapper(name = "sources")
@XmlElement(name = "source")
private List<TenantSourceEntity> sources;
public List<TenantSourceEntity> getSources() {
return sources;
}
public void setSources(List<TenantSourceEntity> sources) {
this.sources = sources;
}
}

View File

@ -1,79 +0,0 @@
package eu.eudat.commons.types.tenant;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class TenantSourceEntity {
@XmlElement(name = "url")
private String url;
@XmlElementWrapper(name = "codes")
@XmlElement(name = "code")
private List<String> codes;
@XmlElement(name = "issuer-url")
private String issuerUrl;
@XmlElement(name = "client-id")
private String clientId;
@XmlElement(name = "client-secret")
private String clientSecret;
@XmlElement(name = "scope")
private String scope;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public List<String> getCodes() {
return codes;
}
public void setCodes(List<String> codes) {
this.codes = codes;
}
public String getIssuerUrl() {
return issuerUrl;
}
public void setIssuerUrl(String issuerUrl) {
this.issuerUrl = issuerUrl;
}
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
public String getClientSecret() {
return clientSecret;
}
public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
}

View File

@ -36,10 +36,6 @@ public class TenantEntity {
private IsActive isActive;
public final static String _isActive = "isActive";
@Column(name = "config")
private String config;
public final static String _config = "config";
@Column(name = "created_at", nullable = false)
private Instant createdAt;
public final static String _createdAt = "createdAt";
@ -88,14 +84,6 @@ public class TenantEntity {
this.isActive = isActive;
}
public String getConfig() {
return config;
}
public void setConfig(String config) {
this.config = config;
}
public Instant getCreatedAt() {
return createdAt;
}

View File

@ -1,7 +1,6 @@
package eu.eudat.model;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.model.tenantconfig.TenantConfig;
import java.time.Instant;
import java.util.UUID;
@ -24,9 +23,6 @@ public class Tenant {
private IsActive isActive;
public final static String _isActive = "isActive";
private TenantConfig config;
public final static String _config = "config";
private Instant createdAt;
public final static String _createdAt = "createdAt";
@ -75,14 +71,6 @@ public class Tenant {
this.isActive = isActive;
}
public TenantConfig getConfig() {
return config;
}
public void setConfig(TenantConfig config) {
this.config = config;
}
public Instant getCreatedAt() {
return createdAt;
}

View File

@ -2,11 +2,9 @@ package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.types.tenant.TenantConfigEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.TenantEntity;
import eu.eudat.model.Tenant;
import eu.eudat.model.builder.tenantconfig.TenantConfigBuilder;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
@ -44,7 +42,6 @@ public class TenantBuilder extends BaseBuilder<Tenant, TenantEntity> {
this.logger.trace(new DataLogEntry("requested fields",fields));
if(fields == null || data == null || fields.isEmpty()) return new ArrayList<>();
FieldSet configFields = fields.extractPrefixed(this.asPrefix(Tenant._config));
List<Tenant> models = new ArrayList<>();
for(TenantEntity d : data){
@ -54,10 +51,6 @@ public class TenantBuilder extends BaseBuilder<Tenant, TenantEntity> {
if(fields.hasField(this.asIndexer(Tenant._name))) m.setName(d.getName());
if(fields.hasField(this.asIndexer(Tenant._description))) m.setDescription(d.getDescription());
if(fields.hasField(this.asIndexer(Tenant._isActive))) m.setIsActive(d.getIsActive());
if (!configFields.isEmpty() && d.getConfig() != null){
TenantConfigEntity config = this.xmlHandlingService.fromXmlSafe(TenantConfigEntity.class, d.getConfig());
m.setConfig(this.builderFactory.builder(TenantConfigBuilder.class).authorize(this.authorize).build(configFields, config));
}
if(fields.hasField(this.asIndexer(Tenant._createdAt))) m.setCreatedAt(d.getCreatedAt());
if(fields.hasField(this.asIndexer(Tenant._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if(fields.hasField(this.asIndexer(Tenant._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));

View File

@ -0,0 +1,63 @@
package eu.eudat.model.builder.deposit;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.scope.tenant.TenantScope;
import eu.eudat.commons.types.deposit.DepositSourceEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.deposit.DepositSource;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DepositSourceBuilder extends BaseBuilder<DepositSource, DepositSourceEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public DepositSourceBuilder(
ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DepositSourceBuilder.class)));
}
public DepositSourceBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<DepositSource> build(FieldSet fields, List<DepositSourceEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
List<DepositSource> models = new ArrayList<>();
for (DepositSourceEntity d : data) {
DepositSource m = new DepositSource();
if (fields.hasField(this.asIndexer(DepositSource._repositoryId))) m.setRepositoryId(d.getRepositoryId());
if (fields.hasField(this.asIndexer(DepositSource._url))) m.setUrl(d.getUrl());
if (fields.hasField(this.asIndexer(DepositSource._issuerUrl))) m.setIssuerUrl(d.getIssuerUrl());
if (fields.hasField(this.asIndexer(DepositSource._clientId))) m.setClientId(d.getClientId());
if (fields.hasField(this.asIndexer(DepositSource._clientSecret))) m.setClientSecret(d.getClientSecret());
if (fields.hasField(this.asIndexer(DepositSource._scope))) m.setScope(d.getScope());
if (fields.hasField(this.asIndexer(DepositSource._pdfTransformerId))) m.setPdfTransformerId(d.getPdfTransformerId());
if (fields.hasField(this.asIndexer(DepositSource._rdaTransformerId))) m.setRdaTransformerId(d.getRdaTransformerId());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -0,0 +1,57 @@
package eu.eudat.model.builder.filetransformer;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.filetransformer.FileTransformerSourceEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.filetransformer.FileTransformerSource;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class FileTransformerSourceBuilder extends BaseBuilder<FileTransformerSource, FileTransformerSourceEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public FileTransformerSourceBuilder(
ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(FileTransformerSourceBuilder.class)));
}
public FileTransformerSourceBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<FileTransformerSource> build(FieldSet fields, List<FileTransformerSourceEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
List<FileTransformerSource> models = new ArrayList<>();
for (FileTransformerSourceEntity d : data) {
FileTransformerSource m = new FileTransformerSource();
if (fields.hasField(this.asIndexer(FileTransformerSource._transformerId))) m.setTransformerId(d.getTransformerId());
if (fields.hasField(this.asIndexer(FileTransformerSource._url))) m.setUrl(d.getUrl());
if (fields.hasField(this.asIndexer(FileTransformerSource._issuerUrl))) m.setIssuerUrl(d.getIssuerUrl());
if (fields.hasField(this.asIndexer(FileTransformerSource._clientId))) m.setClientId(d.getClientId());
if (fields.hasField(this.asIndexer(FileTransformerSource._clientSecret))) m.setClientSecret(d.getClientSecret());
if (fields.hasField(this.asIndexer(FileTransformerSource._scope))) m.setScope(d.getScope());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -1,60 +0,0 @@
package eu.eudat.model.builder.tenantconfig;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.tenant.TenantConfigEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.tenantconfig.TenantConfig;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantConfigBuilder extends BaseBuilder<TenantConfig, TenantConfigEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public TenantConfigBuilder(
ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantConfigBuilder.class)));
this.builderFactory = builderFactory;
}
public TenantConfigBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<TenantConfig> build(FieldSet fields, List<TenantConfigEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet depositFields = fields.extractPrefixed(this.asPrefix(TenantConfig._deposit));
FieldSet fileFields = fields.extractPrefixed(this.asPrefix(TenantConfig._fileTransformers));
List<TenantConfig> models = new ArrayList<>();
for (TenantConfigEntity d : data) {
TenantConfig m = new TenantConfig();
if (!depositFields.isEmpty() && d.getDeposit() != null) m.setDeposit(this.builderFactory.builder(TenantDepositConfigBuilder.class).authorize(this.authorize).build(depositFields, d.getDeposit()));
if (!fileFields.isEmpty() && d.getFileTransformers() != null) m.setFileTransformers(this.builderFactory.builder(TenantFileTransformersBuilder.class).authorize(this.authorize).build(fileFields, d.getFileTransformers()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -1,63 +0,0 @@
package eu.eudat.model.builder.tenantconfig;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.tenant.TenantSourceEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.tenantconfig.TenantSource;
import eu.eudat.service.tenant.TenantService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantSourceBuilder extends BaseBuilder<TenantSource, TenantSourceEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public TenantSourceBuilder(
ConventionService conventionService, BuilderFactory builderFactory, TenantService tenantService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantSourceBuilder.class)));
this.builderFactory = builderFactory;
}
public TenantSourceBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<TenantSource> build(FieldSet fields, List<TenantSourceEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
List<TenantSource> models = new ArrayList<>();
for (TenantSourceEntity d : data) {
TenantSource m = new TenantSource();
if (fields.hasField(this.asIndexer(TenantSource._url))) m.setUrl(d.getUrl());
if (fields.hasField(this.asIndexer(TenantSource._codes))) m.setCodes(d.getCodes());
if (fields.hasField(this.asIndexer(TenantSource._issuerUrl))) m.setIssuerUrl(d.getIssuerUrl());
if (fields.hasField(this.asIndexer(TenantSource._clientId))) m.setClientId(d.getClientId());
if (fields.hasField(this.asIndexer(TenantSource._clientSecret))) m.setClientSecret(d.getClientSecret());
if (fields.hasField(this.asIndexer(TenantSource._scope))) m.setScope(d.getScope());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -0,0 +1,55 @@
package eu.eudat.model.builder.tenantconfiguration;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.tenantconfiguration.CssColorsTenantConfigurationEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.tenantconfiguration.CssColorsTenantConfiguration;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class CssColorsTenantConfigurationBuilder extends BaseBuilder<CssColorsTenantConfiguration, CssColorsTenantConfigurationEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public CssColorsTenantConfigurationBuilder(
ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(CssColorsTenantConfigurationBuilder.class)));
}
public CssColorsTenantConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<CssColorsTenantConfiguration> build(FieldSet fields, List<CssColorsTenantConfigurationEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
List<CssColorsTenantConfiguration> models = new ArrayList<>();
for (CssColorsTenantConfigurationEntity d : data) {
CssColorsTenantConfiguration m = new CssColorsTenantConfiguration();
if (fields.hasField(this.asIndexer(CssColorsTenantConfiguration._primaryColor))) m.setPrimaryColor(d.getPrimaryColor());
if (fields.hasField(this.asIndexer(CssColorsTenantConfiguration._primaryColor2))) m.setPrimaryColor2(d.getPrimaryColor2());
if (fields.hasField(this.asIndexer(CssColorsTenantConfiguration._primaryColor3))) m.setPrimaryColor3(d.getPrimaryColor3());
if (fields.hasField(this.asIndexer(CssColorsTenantConfiguration._secondaryColor))) m.setSecondaryColor(d.getSecondaryColor());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -0,0 +1,54 @@
package eu.eudat.model.builder.tenantconfiguration;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.tenantconfiguration.DefaultUserLocaleTenantConfigurationEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.tenantconfiguration.DefaultUserLocaleTenantConfiguration;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DefaultUserLocaleTenantConfigurationBuilder extends BaseBuilder<DefaultUserLocaleTenantConfiguration, DefaultUserLocaleTenantConfigurationEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public DefaultUserLocaleTenantConfigurationBuilder(
ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DefaultUserLocaleTenantConfigurationBuilder.class)));
}
public DefaultUserLocaleTenantConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<DefaultUserLocaleTenantConfiguration> build(FieldSet fields, List<DefaultUserLocaleTenantConfigurationEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
List<DefaultUserLocaleTenantConfiguration> models = new ArrayList<>();
for (DefaultUserLocaleTenantConfigurationEntity d : data) {
DefaultUserLocaleTenantConfiguration m = new DefaultUserLocaleTenantConfiguration();
if (fields.hasField(this.asIndexer(DefaultUserLocaleTenantConfiguration._culture))) m.setCulture(d.getCulture());
if (fields.hasField(this.asIndexer(DefaultUserLocaleTenantConfiguration._timezone))) m.setTimezone(d.getTimezone());
if (fields.hasField(this.asIndexer(DefaultUserLocaleTenantConfiguration._language))) m.setLanguage(d.getLanguage());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -1,10 +1,11 @@
package eu.eudat.model.builder.tenantconfig;
package eu.eudat.model.builder.tenantconfiguration;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.tenant.TenantFileTransformersConfigEntity;
import eu.eudat.commons.types.tenantconfiguration.DepositTenantConfigurationEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.tenantconfig.TenantFileTransformersConfig;
import eu.eudat.model.builder.deposit.DepositSourceBuilder;
import eu.eudat.model.tenantconfiguration.DepositTenantConfiguration;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
@ -20,39 +21,38 @@ import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantFileTransformersBuilder extends BaseBuilder<TenantFileTransformersConfig, TenantFileTransformersConfigEntity> {
private final BuilderFactory builderFactory;
public class DepositTenantConfigurationBuilder extends BaseBuilder<DepositTenantConfiguration, DepositTenantConfigurationEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final BuilderFactory builderFactory;
@Autowired
public TenantFileTransformersBuilder(
public DepositTenantConfigurationBuilder(
ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantFileTransformersBuilder.class)));
super(conventionService, new LoggerService(LoggerFactory.getLogger(DepositTenantConfigurationBuilder.class)));
this.builderFactory = builderFactory;
}
public TenantFileTransformersBuilder authorize(EnumSet<AuthorizationFlags> values) {
public DepositTenantConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<TenantFileTransformersConfig> build(FieldSet fields, List<TenantFileTransformersConfigEntity> data) throws MyApplicationException {
public List<DepositTenantConfiguration> build(FieldSet fields, List<DepositTenantConfigurationEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet sourcesFields = fields.extractPrefixed(this.asPrefix(TenantFileTransformersConfig._sources));
FieldSet sourcesFields = fields.extractPrefixed(this.asPrefix(DepositTenantConfiguration._sources));
List<TenantFileTransformersConfig> models = new ArrayList<>();
for (TenantFileTransformersConfigEntity d : data) {
TenantFileTransformersConfig m = new TenantFileTransformersConfig();
List<DepositTenantConfiguration> models = new ArrayList<>();
for (DepositTenantConfigurationEntity d : data) {
DepositTenantConfiguration m = new DepositTenantConfiguration();
if (!sourcesFields.isEmpty() && d.getSources() != null){
m.setSources(this.builderFactory.builder(TenantSourceBuilder.class).authorize(this.authorize).build(sourcesFields, d.getSources()));
m.setSources(this.builderFactory.builder(DepositSourceBuilder.class).authorize(this.authorize).build(sourcesFields, d.getSources()));
}
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));

View File

@ -1,10 +1,11 @@
package eu.eudat.model.builder.tenantconfig;
package eu.eudat.model.builder.tenantconfiguration;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.tenant.TenantDepositConfigEntity;
import eu.eudat.commons.types.tenantconfiguration.FileTransformerTenantConfigurationEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.tenantconfig.TenantDepositConfig;
import eu.eudat.model.builder.filetransformer.FileTransformerSourceBuilder;
import eu.eudat.model.tenantconfiguration.FileTransformerTenantConfiguration;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
@ -20,39 +21,38 @@ import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantDepositConfigBuilder extends BaseBuilder<TenantDepositConfig, TenantDepositConfigEntity> {
private final BuilderFactory builderFactory;
public class FileTransformerTenantConfigurationBuilder extends BaseBuilder<FileTransformerTenantConfiguration, FileTransformerTenantConfigurationEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final BuilderFactory builderFactory;
@Autowired
public TenantDepositConfigBuilder(
public FileTransformerTenantConfigurationBuilder(
ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantDepositConfigBuilder.class)));
super(conventionService, new LoggerService(LoggerFactory.getLogger(FileTransformerTenantConfigurationBuilder.class)));
this.builderFactory = builderFactory;
}
public TenantDepositConfigBuilder authorize(EnumSet<AuthorizationFlags> values) {
public FileTransformerTenantConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<TenantDepositConfig> build(FieldSet fields, List<TenantDepositConfigEntity> data) throws MyApplicationException {
public List<FileTransformerTenantConfiguration> build(FieldSet fields, List<FileTransformerTenantConfigurationEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet sourcesFields = fields.extractPrefixed(this.asPrefix(TenantDepositConfig._sources));
FieldSet sourcesFields = fields.extractPrefixed(this.asPrefix(FileTransformerTenantConfiguration._sources));
List<TenantDepositConfig> models = new ArrayList<>();
for (TenantDepositConfigEntity d : data) {
TenantDepositConfig m = new TenantDepositConfig();
List<FileTransformerTenantConfiguration> models = new ArrayList<>();
for (FileTransformerTenantConfigurationEntity d : data) {
FileTransformerTenantConfiguration m = new FileTransformerTenantConfiguration();
if (!sourcesFields.isEmpty() && d.getSources() != null){
m.setSources(this.builderFactory.builder(TenantSourceBuilder.class).authorize(this.authorize).build(sourcesFields, d.getSources()));
m.setSources(this.builderFactory.builder(FileTransformerSourceBuilder.class).authorize(this.authorize).build(sourcesFields, d.getSources()));
}
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));

View File

@ -0,0 +1,100 @@
package eu.eudat.model.builder.tenantconfiguration;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.tenantconfiguration.LogoTenantConfigurationEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.StorageFile;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.builder.StorageFileBuilder;
import eu.eudat.model.tenantconfiguration.LogoTenantConfiguration;
import eu.eudat.query.StorageFileQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.stream.Collectors;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class LogoTenantConfigurationBuilder extends BaseBuilder<LogoTenantConfiguration, LogoTenantConfigurationEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
@Autowired
public LogoTenantConfigurationBuilder(
ConventionService conventionService, BuilderFactory builderFactory, QueryFactory queryFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(LogoTenantConfigurationBuilder.class)));
this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
}
public LogoTenantConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<LogoTenantConfiguration> build(FieldSet fields, List<LogoTenantConfigurationEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet storageFileFields = fields.extractPrefixed(this.asPrefix(LogoTenantConfiguration._storageFile));
Map<UUID, StorageFile> storageFileItemsMap = this.collectStorageFiles(storageFileFields, data);
List<LogoTenantConfiguration> models = new ArrayList<>();
for (LogoTenantConfigurationEntity d : data) {
LogoTenantConfiguration m = new LogoTenantConfiguration();
if (!storageFileFields.isEmpty() && storageFileItemsMap != null && storageFileItemsMap.containsKey(d.getStorageFileId())) m.setStorageFile(storageFileItemsMap.get(d.getStorageFileId()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
private Map<UUID, StorageFile> collectStorageFiles(FieldSet fields, List<LogoTenantConfigurationEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", StorageFile.class.getSimpleName());
Map<UUID, StorageFile> itemMap;
if (!fields.hasOtherField(this.asIndexer(StorageFile._id))) {
itemMap = this.asEmpty(
data.stream().map(LogoTenantConfigurationEntity::getStorageFileId).distinct().collect(Collectors.toList()),
x -> {
StorageFile item = new StorageFile();
item.setId(x);
return item;
},
StorageFile::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(StorageFile._id);
StorageFileQuery q = this.queryFactory.query(StorageFileQuery.class).authorize(this.authorize).ids(data.stream().map(LogoTenantConfigurationEntity::getStorageFileId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(StorageFileBuilder.class).authorize(this.authorize).asForeignKey(q, clone, StorageFile::getId);
}
if (!fields.hasField(StorageFile._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
}

View File

@ -0,0 +1,100 @@
package eu.eudat.model.builder.tenantconfiguration;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.enums.TenantConfigurationType;
import eu.eudat.commons.scope.tenant.TenantScope;
import eu.eudat.commons.types.tenantconfiguration.*;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.TenantConfigurationEntity;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.tenantconfiguration.TenantConfiguration;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantConfigurationBuilder extends BaseBuilder<TenantConfiguration, TenantConfigurationEntity> {
private final TenantScope tenantScope;
private final JsonHandlingService jsonHandlingService;
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public TenantConfigurationBuilder(
ConventionService conventionService,
BuilderFactory builderFactory, QueryFactory queryFactory, XmlHandlingService xmlHandlingService, TenantScope tenantScope, JsonHandlingService jsonHandlingService, BuilderFactory builderFactory1) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantConfigurationBuilder.class)));
this.tenantScope = tenantScope;
this.jsonHandlingService = jsonHandlingService;
this.builderFactory = builderFactory1;
}
public TenantConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<TenantConfiguration> build(FieldSet fields, List<TenantConfigurationEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet cssColorsFields = fields.extractPrefixed(this.asPrefix(TenantConfiguration._cssColors));
FieldSet defaultUserLocaleFields = fields.extractPrefixed(this.asPrefix(TenantConfiguration._defaultUserLocale));
FieldSet depositPluginsFields = fields.extractPrefixed(this.asPrefix(TenantConfiguration._depositPlugins));
FieldSet fileTransformerPluginsFields = fields.extractPrefixed(this.asPrefix(TenantConfiguration._fileTransformerPlugins));
FieldSet logoFields = fields.extractPrefixed(this.asPrefix(TenantConfiguration._logo));
List<TenantConfiguration> models = new ArrayList<>();
for (TenantConfigurationEntity d : data) {
TenantConfiguration m = new TenantConfiguration();
if (fields.hasField(this.asIndexer(TenantConfiguration._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(TenantConfiguration._type))) m.setType(d.getType());
if (!cssColorsFields.isEmpty() && !this.conventionService.isNullOrEmpty(d.getValue()) && TenantConfigurationType.CssColors.equals(d.getType())){
CssColorsTenantConfigurationEntity valueTyped = this.jsonHandlingService.fromJsonSafe(CssColorsTenantConfigurationEntity.class, d.getValue());
m.setCssColors(this.builderFactory.builder(CssColorsTenantConfigurationBuilder.class).authorize(this.authorize).build(cssColorsFields, valueTyped));
}
if (!defaultUserLocaleFields.isEmpty() && !this.conventionService.isNullOrEmpty(d.getValue()) && TenantConfigurationType.DefaultUserLocale.equals(d.getType())){
DefaultUserLocaleTenantConfigurationEntity valueTyped = this.jsonHandlingService.fromJsonSafe(DefaultUserLocaleTenantConfigurationEntity.class, d.getValue());
m.setDefaultUserLocale(this.builderFactory.builder(DefaultUserLocaleTenantConfigurationBuilder.class).authorize(this.authorize).build(defaultUserLocaleFields, valueTyped));
}
if (!depositPluginsFields.isEmpty() && !this.conventionService.isNullOrEmpty(d.getValue()) && TenantConfigurationType.DepositPlugins.equals(d.getType())){
DepositTenantConfigurationEntity valueTyped = this.jsonHandlingService.fromJsonSafe(DepositTenantConfigurationEntity.class, d.getValue());
m.setDepositPlugins(this.builderFactory.builder(DepositTenantConfigurationBuilder.class).authorize(this.authorize).build(depositPluginsFields, valueTyped));
}
if (!fileTransformerPluginsFields.isEmpty() && !this.conventionService.isNullOrEmpty(d.getValue()) && TenantConfigurationType.FileTransformerPlugins.equals(d.getType())){
FileTransformerTenantConfigurationEntity valueTyped = this.jsonHandlingService.fromJsonSafe(FileTransformerTenantConfigurationEntity.class, d.getValue());
m.setFileTransformerPlugins(this.builderFactory.builder(FileTransformerTenantConfigurationBuilder.class).authorize(this.authorize).build(fileTransformerPluginsFields, valueTyped));
}
if (!logoFields.isEmpty() && !this.conventionService.isNullOrEmpty(d.getValue()) && TenantConfigurationType.Logo.equals(d.getType())){
LogoTenantConfigurationEntity valueTyped = this.jsonHandlingService.fromJsonSafe(LogoTenantConfigurationEntity.class, d.getValue());
m.setLogo(this.builderFactory.builder(LogoTenantConfigurationBuilder.class).authorize(this.authorize).build(logoFields, valueTyped));
}
if (fields.hasField(this.asIndexer(TenantConfiguration._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(TenantConfiguration._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(TenantConfiguration._isActive))) m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(TenantConfiguration._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
if (fields.hasField(this.asIndexer(TenantConfiguration._belongsToCurrentTenant))) m.setBelongsToCurrentTenant(this.getBelongsToCurrentTenant(d, this.tenantScope));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -1,51 +0,0 @@
package eu.eudat.model.censorship.tenantconfig;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.censorship.BaseCensor;
import eu.eudat.model.censorship.referencetypedefinition.ReferenceTypeFieldCensor;
import eu.eudat.model.censorship.referencetypedefinition.ReferenceTypeSourceBaseConfigurationCensor;
import eu.eudat.model.tenantconfig.TenantConfig;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantConfigCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantConfigCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public TenantConfigCensor(ConventionService conventionService,
AuthorizationService authService,
CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseTenant);
FieldSet depositFields = fields.extractPrefixed(this.asIndexerPrefix(TenantConfig._deposit));
this.censorFactory.censor(TenantDepositConfigCensor.class).censor(depositFields, userId);
FieldSet fileFields = fields.extractPrefixed(this.asIndexerPrefix(TenantConfig._fileTransformers));
this.censorFactory.censor(TenantFileTransformersConfigCensor.class).censor(fileFields, userId);
}
}

View File

@ -1,48 +0,0 @@
package eu.eudat.model.censorship.tenantconfig;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.censorship.BaseCensor;
import eu.eudat.model.censorship.referencetypedefinition.ReferenceTypeFieldCensor;
import eu.eudat.model.tenantconfig.TenantDepositConfig;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantDepositConfigCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantDepositConfigCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public TenantDepositConfigCensor(ConventionService conventionService,
AuthorizationService authService,
CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseTenant);
FieldSet sourceFields = fields.extractPrefixed(this.asIndexerPrefix(TenantDepositConfig._sources));
this.censorFactory.censor(TenantSourceCensor.class).censor(sourceFields, userId);
}
}

View File

@ -1,47 +0,0 @@
package eu.eudat.model.censorship.tenantconfig;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.censorship.BaseCensor;
import eu.eudat.model.tenantconfig.TenantFileTransformersConfig;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantFileTransformersConfigCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantFileTransformersConfigCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public TenantFileTransformersConfigCensor(ConventionService conventionService,
AuthorizationService authService,
CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseTenant);
FieldSet sourceFields = fields.extractPrefixed(this.asIndexerPrefix(TenantFileTransformersConfig._sources));
this.censorFactory.censor(TenantSourceCensor.class).censor(sourceFields, userId);
}
}

View File

@ -1,43 +0,0 @@
package eu.eudat.model.censorship.tenantconfig;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.censorship.BaseCensor;
import eu.eudat.model.tenantconfig.TenantSource;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantSourceCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantSourceCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public TenantSourceCensor(ConventionService conventionService,
AuthorizationService authService, CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseTenant);
}
}

View File

@ -0,0 +1,81 @@
package eu.eudat.model.deleter;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.TenantConfigurationEntity;
import eu.eudat.data.TenantEntity;
import eu.eudat.data.TenantEntityManager;
import eu.eudat.query.TenantConfigurationQuery;
import eu.eudat.query.TenantQuery;
import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.management.InvalidApplicationException;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantConfigurationDeleter implements Deleter {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantConfigurationDeleter.class));
private final TenantEntityManager entityManager;
protected final QueryFactory queryFactory;
protected final DeleterFactory deleterFactory;
@Autowired
public TenantConfigurationDeleter(
TenantEntityManager entityManager,
QueryFactory queryFactory,
DeleterFactory deleterFactory
) {
this.entityManager = entityManager;
this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory;
}
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
List<TenantConfigurationEntity> data = this.queryFactory.query(TenantConfigurationQuery.class).ids(ids).collect();
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.deleteAndSave(data);
}
public void deleteAndSave(List<TenantConfigurationEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.delete(data);
logger.trace("saving changes");
this.entityManager.flush();
logger.trace("changes saved");
}
public void delete(List<TenantConfigurationEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty())
return;
Instant now = Instant.now();
for (TenantConfigurationEntity item : data) {
logger.trace("deleting item {}", item.getId());
item.setIsActive(IsActive.Inactive);
item.setUpdatedAt(now);
logger.trace("updating item");
this.entityManager.merge(item);
logger.trace("updated item");
}
}
}

View File

@ -6,7 +6,6 @@ import gr.cite.tools.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 org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
@ -33,10 +32,6 @@ public class TenantPersist {
public static final String _description = "description";
private TenantConfigPersist config;
public static final String _config = "config";
private String hash;
public static final String _hash = "hash";
@ -73,14 +68,6 @@ public class TenantPersist {
this.description = description;
}
public TenantConfigPersist getConfig() {
return config;
}
public void setConfig(TenantConfigPersist config) {
this.config = config;
}
public String getHash() {
return hash;
}
@ -137,13 +124,8 @@ public class TenantPersist {
.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())),
.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

@ -0,0 +1,147 @@
package eu.eudat.model.persist.deposit;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
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 DepositSourcePersist {
private String repositoryId;
public static final String _repositoryId = "repositoryId";
private String url;
public static final String _url = "url";
private String issuerUrl;
public static final String _issuerUrl = "issuerUrl";
private String clientId;
public static final String _clientId = "clientId";
private String clientSecret;
public static final String _clientSecret = "clientSecret";
private String scope;
public static final String _scope = "scope";
private String pdfTransformerId;
public static final String _pdfTransformerId = "pdfTransformerId";
private String rdaTransformerId;
public static final String _rdaTransformerId = "rdaTransformerId";
public String getRepositoryId() {
return repositoryId;
}
public void setRepositoryId(String repositoryId) {
this.repositoryId = repositoryId;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getIssuerUrl() {
return issuerUrl;
}
public void setIssuerUrl(String issuerUrl) {
this.issuerUrl = issuerUrl;
}
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
public String getClientSecret() {
return clientSecret;
}
public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
public String getPdfTransformerId() {
return pdfTransformerId;
}
public void setPdfTransformerId(String pdfTransformerId) {
this.pdfTransformerId = pdfTransformerId;
}
public String getRdaTransformerId() {
return rdaTransformerId;
}
public void setRdaTransformerId(String rdaTransformerId) {
this.rdaTransformerId = rdaTransformerId;
}
@Component(DepositSourcePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DepositSourcePersistValidator extends BaseValidator<DepositSourcePersist> {
public static final String ValidatorName = "DepositSourcePersistValidator";
private final MessageSource messageSource;
protected DepositSourcePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<DepositSourcePersist> modelClass() {
return DepositSourcePersist.class;
}
@Override
protected List<Specification> specifications(DepositSourcePersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getRepositoryId()))
.failOn(DepositSourcePersist._repositoryId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DepositSourcePersist._repositoryId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getUrl()))
.failOn(DepositSourcePersist._url).failWith(messageSource.getMessage("Validation_Required", new Object[]{DepositSourcePersist._url}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getIssuerUrl()))
.failOn(DepositSourcePersist._issuerUrl).failWith(messageSource.getMessage("Validation_Required", new Object[]{DepositSourcePersist._issuerUrl}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getClientId()))
.failOn(DepositSourcePersist._clientId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DepositSourcePersist._clientId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getClientSecret()))
.failOn(DepositSourcePersist._clientSecret).failWith(messageSource.getMessage("Validation_Required", new Object[]{DepositSourcePersist._clientSecret}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getScope()))
.failOn(DepositSourcePersist._scope).failWith(messageSource.getMessage("Validation_Required", new Object[]{DepositSourcePersist._scope}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getPdfTransformerId()))
.failOn(DepositSourcePersist._pdfTransformerId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DepositSourcePersist._pdfTransformerId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getRdaTransformerId()))
.failOn(DepositSourcePersist._rdaTransformerId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DepositSourcePersist._rdaTransformerId}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -0,0 +1,121 @@
package eu.eudat.model.persist.filetransformer;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
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 FileTransformerSourcePersist {
private String url;
public static final String _url = "url";
private String transformerId;
public static final String _transformerId = "transformerId";
private String issuerUrl;
public static final String _issuerUrl = "issuerUrl";
private String clientId;
public static final String _clientId = "clientId";
private String clientSecret;
public static final String _clientSecret = "clientSecret";
private String scope;
public static final String _scope = "scope";
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getTransformerId() {
return transformerId;
}
public void setTransformerId(String transformerId) {
this.transformerId = transformerId;
}
public String getIssuerUrl() {
return issuerUrl;
}
public void setIssuerUrl(String issuerUrl) {
this.issuerUrl = issuerUrl;
}
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
public String getClientSecret() {
return clientSecret;
}
public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
@Component(FileTransformerSourcePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class FileTransformerSourcePersistValidator extends BaseValidator<FileTransformerSourcePersist> {
public static final String ValidatorName = "FileTransformerSourcePersistValidator";
private final MessageSource messageSource;
protected FileTransformerSourcePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<FileTransformerSourcePersist> modelClass() {
return FileTransformerSourcePersist.class;
}
@Override
protected List<Specification> specifications(FileTransformerSourcePersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getTransformerId()))
.failOn(FileTransformerSourcePersist._transformerId).failWith(messageSource.getMessage("Validation_Required", new Object[]{FileTransformerSourcePersist._transformerId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getUrl()))
.failOn(FileTransformerSourcePersist._url).failWith(messageSource.getMessage("Validation_Required", new Object[]{FileTransformerSourcePersist._url}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getIssuerUrl()))
.failOn(FileTransformerSourcePersist._issuerUrl).failWith(messageSource.getMessage("Validation_Required", new Object[]{FileTransformerSourcePersist._issuerUrl}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getClientId()))
.failOn(FileTransformerSourcePersist._clientId).failWith(messageSource.getMessage("Validation_Required", new Object[]{FileTransformerSourcePersist._clientId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getClientSecret()))
.failOn(FileTransformerSourcePersist._clientSecret).failWith(messageSource.getMessage("Validation_Required", new Object[]{FileTransformerSourcePersist._clientSecret}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getScope()))
.failOn(FileTransformerSourcePersist._scope).failWith(messageSource.getMessage("Validation_Required", new Object[]{FileTransformerSourcePersist._scope}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -1,77 +0,0 @@
package eu.eudat.model.persist.tenantconfig;
import eu.eudat.commons.validation.BaseValidator;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.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;
}
public void setDeposit(TenantDepositConfigPersist deposit) {
this.deposit = deposit;
}
public TenantFileTransformersConfigPersist getFileTransformers() {
return fileTransformers;
}
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,59 +0,0 @@
package eu.eudat.model.persist.tenantconfig;
import eu.eudat.commons.validation.BaseValidator;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.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.Collections;
import java.util.List;
public class TenantDepositConfigPersist {
private List<TenantSourcePersist> sources;
public static final String _sources = "sources";
public List<TenantSourcePersist> getSources() {
return sources;
}
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.navSpec()
.iff(() -> !this.isListNullOrEmpty(item.getSources()))
.on(TenantDepositConfigPersist._sources)
.over(item.getSources())
.using((itm) -> this.validatorFactory.validator(TenantSourcePersist.TenantSourcePersistValidator.class))
);
}
}
}

View File

@ -1,59 +0,0 @@
package eu.eudat.model.persist.tenantconfig;
import eu.eudat.commons.validation.BaseValidator;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.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.Collections;
import java.util.List;
public class TenantFileTransformersConfigPersist {
private List<TenantSourcePersist> sources;
public static final String _sources = "sources";
public List<TenantSourcePersist> getSources() {
return sources;
}
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.navSpec()
.iff(() -> !this.isListNullOrEmpty(item.getSources()))
.on(TenantFileTransformersConfigPersist._sources)
.over(item.getSources())
.using((itm) -> this.validatorFactory.validator(TenantSourcePersist.TenantSourcePersistValidator.class))
);
}
}
}

View File

@ -1,133 +0,0 @@
package eu.eudat.model.persist.tenantconfig;
import eu.eudat.commons.validation.BaseValidator;
import gr.cite.tools.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 {
private String url;
public static final String _url = "url";
private List<String> codes;
public static final String _codes = "codes";
private String issuerUrl;
public static final String _issuerUrl = "issuerUrl";
private String clientId;
public static final String _clientId = "clientId";
private String clientSecret;
public static final String _clientSecret = "clientSecret";
private String scope;
public static final String _scope = "scope";
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public List<String> getCodes() {
return codes;
}
public void setCodes(List<String> codes) {
this.codes = codes;
}
public String getIssuerUrl() {
return issuerUrl;
}
public void setIssuerUrl(String issuerUrl) {
this.issuerUrl = issuerUrl;
}
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
public String getClientSecret() {
return clientSecret;
}
public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}
public String getScope() {
return scope;
}
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.isListNullOrEmpty(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

@ -0,0 +1,96 @@
package eu.eudat.model.persist.tenantconfiguration;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
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 CssColorsTenantConfigurationPersist {
private String primaryColor;
public static final String _primaryColor = "primaryColor";
private String primaryColor2;
public static final String _primaryColor2 = "primaryColor2";
private String primaryColor3;
public static final String _primaryColor3 = "primaryColor3";
private String secondaryColor;
public static final String _secondaryColor = "secondaryColor";
public String getPrimaryColor() {
return primaryColor;
}
public void setPrimaryColor(String primaryColor) {
this.primaryColor = primaryColor;
}
public String getPrimaryColor2() {
return primaryColor2;
}
public void setPrimaryColor2(String primaryColor2) {
this.primaryColor2 = primaryColor2;
}
public String getPrimaryColor3() {
return primaryColor3;
}
public void setPrimaryColor3(String primaryColor3) {
this.primaryColor3 = primaryColor3;
}
public String getSecondaryColor() {
return secondaryColor;
}
public void setSecondaryColor(String secondaryColor) {
this.secondaryColor = secondaryColor;
}
@Component(CssColorsTenantConfigurationPersist.CssColorsTenantConfigurationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class CssColorsTenantConfigurationPersistValidator extends BaseValidator<CssColorsTenantConfigurationPersist> {
public static final String ValidatorName = "CssColorsTenantConfigurationPersistValidator";
private final MessageSource messageSource;
protected CssColorsTenantConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<CssColorsTenantConfigurationPersist> modelClass() {
return CssColorsTenantConfigurationPersist.class;
}
@Override
protected List<Specification> specifications(CssColorsTenantConfigurationPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getPrimaryColor()))
.failOn(CssColorsTenantConfigurationPersist._primaryColor).failWith(messageSource.getMessage("Validation_Required", new Object[]{CssColorsTenantConfigurationPersist._primaryColor}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getPrimaryColor2()))
.failOn(CssColorsTenantConfigurationPersist._primaryColor2).failWith(messageSource.getMessage("Validation_Required", new Object[]{CssColorsTenantConfigurationPersist._primaryColor2}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getPrimaryColor3()))
.failOn(CssColorsTenantConfigurationPersist._primaryColor3).failWith(messageSource.getMessage("Validation_Required", new Object[]{CssColorsTenantConfigurationPersist._primaryColor3}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getSecondaryColor()))
.failOn(CssColorsTenantConfigurationPersist._secondaryColor).failWith(messageSource.getMessage("Validation_Required", new Object[]{CssColorsTenantConfigurationPersist._secondaryColor}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -0,0 +1,82 @@
package eu.eudat.model.persist.tenantconfiguration;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
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 DefaultUserLocaleTenantConfigurationPersist {
private String timezone;
public static final String _timezone = "timezone";
private String language;
public static final String _language = "language";
private String culture;
public static final String _culture = "culture";
public String getTimezone() {
return timezone;
}
public void setTimezone(String timezone) {
this.timezone = timezone;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getCulture() {
return culture;
}
public void setCulture(String culture) {
this.culture = culture;
}
@Component(DefaultUserLocaleTenantConfigurationPersist.DefaultUserLocaleTenantConfigurationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DefaultUserLocaleTenantConfigurationPersistValidator extends BaseValidator<DefaultUserLocaleTenantConfigurationPersist> {
public static final String ValidatorName = "DefaultUserLocaleTenantConfigurationPersistValidator";
private final MessageSource messageSource;
protected DefaultUserLocaleTenantConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<DefaultUserLocaleTenantConfigurationPersist> modelClass() {
return DefaultUserLocaleTenantConfigurationPersist.class;
}
@Override
protected List<Specification> specifications(DefaultUserLocaleTenantConfigurationPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getTimezone()))
.failOn(DefaultUserLocaleTenantConfigurationPersist._timezone).failWith(messageSource.getMessage("Validation_Required", new Object[]{DefaultUserLocaleTenantConfigurationPersist._timezone}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getLanguage()))
.failOn(DefaultUserLocaleTenantConfigurationPersist._language).failWith(messageSource.getMessage("Validation_Required", new Object[]{DefaultUserLocaleTenantConfigurationPersist._language}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getCulture()))
.failOn(DefaultUserLocaleTenantConfigurationPersist._culture).failWith(messageSource.getMessage("Validation_Required", new Object[]{DefaultUserLocaleTenantConfigurationPersist._culture}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -0,0 +1,68 @@
package eu.eudat.model.persist.tenantconfiguration;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.*;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.persist.deposit.DepositSourcePersist;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
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 DepositTenantConfigurationPersist {
private List<DepositSourcePersist> sources;
public static final String _sources = "sources";
public List<DepositSourcePersist> getSources() {
return sources;
}
public void setSources(List<DepositSourcePersist> sources) {
this.sources = sources;
}
@Component(DepositTenantConfigurationPersist.DepositTenantConfigurationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DepositTenantConfigurationPersistValidator extends BaseValidator<DepositTenantConfigurationPersist> {
public static final String ValidatorName = "DepositTenantConfigurationPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected DepositTenantConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<DepositTenantConfigurationPersist> modelClass() {
return DepositTenantConfigurationPersist.class;
}
@Override
protected List<Specification> specifications(DepositTenantConfigurationPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isListNullOrEmpty(item.getSources()))
.failOn(DepositTenantConfigurationPersist._sources).failWith(messageSource.getMessage("Validation_Required", new Object[]{DepositTenantConfigurationPersist._sources}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isListNullOrEmpty(item.getSources()))
.on(DepositTenantConfigurationPersist._sources)
.over(item.getSources())
.using(() -> this.validatorFactory.validator(DepositSourcePersist.DepositSourcePersistValidator.class))
);
}
}
}

View File

@ -0,0 +1,67 @@
package eu.eudat.model.persist.tenantconfiguration;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.persist.filetransformer.FileTransformerSourcePersist;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
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 FileTransformerTenantConfigurationPersist {
private List<FileTransformerSourcePersist> sources;
public static final String _sources = "sources";
public List<FileTransformerSourcePersist> getSources() {
return sources;
}
public void setSources(List<FileTransformerSourcePersist> sources) {
this.sources = sources;
}
@Component(FileTransformerTenantConfigurationPersist.FileTransformerTenantConfigurationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class FileTransformerTenantConfigurationPersistValidator extends BaseValidator<FileTransformerTenantConfigurationPersist> {
public static final String ValidatorName = "FileTransformerTenantConfigurationPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected FileTransformerTenantConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<FileTransformerTenantConfigurationPersist> modelClass() {
return FileTransformerTenantConfigurationPersist.class;
}
@Override
protected List<Specification> specifications(FileTransformerTenantConfigurationPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isListNullOrEmpty(item.getSources()))
.failOn(FileTransformerTenantConfigurationPersist._sources).failWith(messageSource.getMessage("Validation_Required", new Object[]{FileTransformerTenantConfigurationPersist._sources}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isListNullOrEmpty(item.getSources()))
.on(FileTransformerTenantConfigurationPersist._sources)
.over(item.getSources())
.using(() -> this.validatorFactory.validator(FileTransformerSourcePersist.FileTransformerSourcePersistValidator.class))
);
}
}
}

View File

@ -0,0 +1,56 @@
package eu.eudat.model.persist.tenantconfiguration;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
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 LogoTenantConfigurationPersist {
private UUID storageFileId;
public static final String _storageFileId = "storageFileId";
public UUID getStorageFileId() {
return storageFileId;
}
public void setStorageFileId(UUID storageFileId) {
this.storageFileId = storageFileId;
}
@Component(LogoTenantConfigurationPersist.LogoTenantConfigurationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class LogoTenantConfigurationPersistValidator extends BaseValidator<LogoTenantConfigurationPersist> {
public static final String ValidatorName = "LogoTenantConfigurationPersistValidator";
private final MessageSource messageSource;
protected LogoTenantConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<LogoTenantConfigurationPersist> modelClass() {
return LogoTenantConfigurationPersist.class;
}
@Override
protected List<Specification> specifications(LogoTenantConfigurationPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isValidGuid(item.getStorageFileId()))
.failOn(LogoTenantConfigurationPersist._storageFileId).failWith(messageSource.getMessage("Validation_Required", new Object[]{LogoTenantConfigurationPersist._storageFileId}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -0,0 +1,208 @@
package eu.eudat.model.persist.tenantconfiguration;
import eu.eudat.commons.enums.TenantConfigurationType;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
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.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class TenantConfigurationPersist {
private UUID id;
public static final String _id = "id";
private TenantConfigurationType type;
public static final String _type = "type";
private CssColorsTenantConfigurationPersist cssColors;
public static final String _cssColors = "cssColors";
private DefaultUserLocaleTenantConfigurationPersist defaultUserLocale;
public static final String _defaultUserLocale = "defaultUserLocale";
private DepositTenantConfigurationPersist depositPlugins;
public static final String _depositPlugins = "depositPlugins";
private FileTransformerTenantConfigurationPersist fileTransformerPlugins;
public static final String _fileTransformerPlugins = "fileTransformerPlugins";
private LogoTenantConfigurationPersist logo;
public static final String _logo = "logo";
private String hash;
public static final String _hash = "hash";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public CssColorsTenantConfigurationPersist getCssColors() {
return cssColors;
}
public void setCssColors(CssColorsTenantConfigurationPersist cssColors) {
this.cssColors = cssColors;
}
public DefaultUserLocaleTenantConfigurationPersist getDefaultUserLocale() {
return defaultUserLocale;
}
public void setDefaultUserLocale(DefaultUserLocaleTenantConfigurationPersist defaultUserLocale) {
this.defaultUserLocale = defaultUserLocale;
}
public DepositTenantConfigurationPersist getDepositPlugins() {
return depositPlugins;
}
public void setDepositPlugins(DepositTenantConfigurationPersist depositPlugins) {
this.depositPlugins = depositPlugins;
}
public FileTransformerTenantConfigurationPersist getFileTransformerPlugins() {
return fileTransformerPlugins;
}
public void setFileTransformerPlugins(FileTransformerTenantConfigurationPersist fileTransformerPlugins) {
this.fileTransformerPlugins = fileTransformerPlugins;
}
public LogoTenantConfigurationPersist getLogo() {
return logo;
}
public void setLogo(LogoTenantConfigurationPersist logo) {
this.logo = logo;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
public TenantConfigurationType getType() {
return type;
}
public void setType(TenantConfigurationType type) {
this.type = type;
}
@Component(TenantConfigurationPersist.TenantConfigurationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class TenantConfigurationPersistValidator extends BaseValidator<TenantConfigurationPersist> {
public static final String ValidatorName = "TenantConfigurationPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected TenantConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<TenantConfigurationPersist> modelClass() {
return TenantConfigurationPersist.class;
}
@Override
protected List<Specification> specifications(TenantConfigurationPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(TenantConfigurationPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(TenantConfigurationPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getType()))
.failOn(TenantConfigurationPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationPersist._type}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isNull(item.getType()) && TenantConfigurationType.CssColors.equals(item.getType()))
.must(() -> !this.isNull(item.getCssColors()))
.failOn(TenantConfigurationPersist._cssColors).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationPersist._cssColors}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isNull(item.getType()) && TenantConfigurationType.CssColors.equals(item.getType()))
.must(() -> !this.isNull(item.getDefaultUserLocale()))
.failOn(TenantConfigurationPersist._defaultUserLocale).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationPersist._defaultUserLocale}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isNull(item.getType()) && TenantConfigurationType.CssColors.equals(item.getType()))
.must(() -> !this.isNull(item.getDepositPlugins()))
.failOn(TenantConfigurationPersist._depositPlugins).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationPersist._depositPlugins}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isNull(item.getType()) && TenantConfigurationType.CssColors.equals(item.getType()))
.must(() -> !this.isNull(item.getFileTransformerPlugins()))
.failOn(TenantConfigurationPersist._fileTransformerPlugins).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationPersist._fileTransformerPlugins}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isNull(item.getType()) && TenantConfigurationType.CssColors.equals(item.getType()))
.must(() -> !this.isNull(item.getLogo()))
.failOn(TenantConfigurationPersist._logo).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationPersist._logo}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getCssColors()) && TenantConfigurationType.CssColors.equals(item.getType()))
.on(TenantConfigurationPersist._cssColors)
.over(item.getCssColors())
.using(() -> this.validatorFactory.validator(CssColorsTenantConfigurationPersist.CssColorsTenantConfigurationPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getDefaultUserLocale()) && TenantConfigurationType.DefaultUserLocale.equals(item.getType()))
.on(TenantConfigurationPersist._defaultUserLocale)
.over(item.getDefaultUserLocale())
.using(() -> this.validatorFactory.validator(DefaultUserLocaleTenantConfigurationPersist.DefaultUserLocaleTenantConfigurationPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getDepositPlugins()) && TenantConfigurationType.DepositPlugins.equals(item.getType()))
.on(TenantConfigurationPersist._depositPlugins)
.over(item.getDepositPlugins())
.using(() -> this.validatorFactory.validator(DepositTenantConfigurationPersist.DepositTenantConfigurationPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getFileTransformerPlugins()) && TenantConfigurationType.FileTransformerPlugins.equals(item.getType()))
.on(TenantConfigurationPersist._fileTransformerPlugins)
.over(item.getFileTransformerPlugins())
.using(() -> this.validatorFactory.validator(FileTransformerTenantConfigurationPersist.FileTransformerTenantConfigurationPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getLogo()) && TenantConfigurationType.Logo.equals(item.getType()))
.on(TenantConfigurationPersist._logo)
.over(item.getLogo())
.using(() -> this.validatorFactory.validator(LogoTenantConfigurationPersist.LogoTenantConfigurationPersistValidator.class))
);
}
}
}

View File

@ -1,28 +0,0 @@
package eu.eudat.model.tenantconfig;
public class TenantConfig {
public final static String _deposit = "deposit";
private TenantDepositConfig deposit;
public final static String _fileTransformers = "fileTransformers";
private TenantFileTransformersConfig fileTransformers;
public TenantDepositConfig getDeposit() {
return deposit;
}
public void setDeposit(TenantDepositConfig deposit) {
this.deposit = deposit;
}
public TenantFileTransformersConfig getFileTransformers() {
return fileTransformers;
}
public void setFileTransformers(TenantFileTransformersConfig fileTransformers) {
this.fileTransformers = fileTransformers;
}
}

View File

@ -1,17 +0,0 @@
package eu.eudat.model.tenantconfig;
import java.util.List;
public class TenantDepositConfig {
public final static String _sources = "sources";
private List<TenantSource> sources;
public List<TenantSource> getSources() {
return sources;
}
public void setSources(List<TenantSource> sources) {
this.sources = sources;
}
}

View File

@ -1,17 +0,0 @@
package eu.eudat.model.tenantconfig;
import java.util.List;
public class TenantFileTransformersConfig {
public final static String _sources = "sources";
private List<TenantSource> sources;
public List<TenantSource> getSources() {
return sources;
}
public void setSources(List<TenantSource> sources) {
this.sources = sources;
}
}

View File

@ -1,73 +0,0 @@
package eu.eudat.model.tenantconfig;
import java.util.List;
public class TenantSource {
public final static String _url = "url";
private String url;
public final static String _codes = "codes";
private List<String> codes;
public final static String _issuerUrl = "issuerUrl";
private String issuerUrl;
public final static String _clientId = "clientId";
private String clientId;
public final static String _clientSecret = "clientSecret";
private String clientSecret;
public final static String _scope = "scope";
private String scope;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public List<String> getCodes() {
return codes;
}
public void setCodes(List<String> codes) {
this.codes = codes;
}
public String getIssuerUrl() {
return issuerUrl;
}
public void setIssuerUrl(String issuerUrl) {
this.issuerUrl = issuerUrl;
}
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
public String getClientSecret() {
return clientSecret;
}
public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
}

View File

@ -1,18 +1,19 @@
package eu.eudat.model.tenantconfiguration;
import eu.eudat.commons.types.deposit.DepositSourceEntity;
import eu.eudat.model.deposit.DepositSource;
import java.util.List;
public class DepositTenantConfiguration {
private List<DepositSourceEntity> sources;
private List<DepositSource> sources;
public static final String _sources = "sources";
public List<DepositSourceEntity> getSources() {
public List<DepositSource> getSources() {
return sources;
}
public void setSources(List<DepositSourceEntity> sources) {
public void setSources(List<DepositSource> sources) {
this.sources = sources;
}
}

View File

@ -1,19 +1,20 @@
package eu.eudat.model.tenantconfiguration;
import eu.eudat.commons.types.filetransformer.FileTransformerSourceEntity;
import eu.eudat.model.filetransformer.FileTransformerSource;
import java.util.List;
public class FileTransformerTenantConfiguration {
private List<FileTransformerSourceEntity> sources;
private List<FileTransformerSource> sources;
public static final String _sources = "sources";
public List<FileTransformerSourceEntity> getSources() {
public List<FileTransformerSource> getSources() {
return sources;
}
public void setSources(List<FileTransformerSourceEntity> sources) {
public void setSources(List<FileTransformerSource> sources) {
this.sources = sources;
}
}

View File

@ -1,16 +1,16 @@
package eu.eudat.model.tenantconfiguration;
import java.util.UUID;
import eu.eudat.model.StorageFile;
public class LogoTenantConfiguration {
private UUID storageFileId;
public static final String _storageFileId = "storageFileId";
private StorageFile storageFile;
public static final String _storageFile = "storageFile";
public UUID getStorageFileId() {
return storageFileId;
public StorageFile getStorageFile() {
return storageFile;
}
public void setStorageFileId(UUID storageFileId) {
this.storageFileId = storageFileId;
public void setStorageFile(StorageFile storageFile) {
this.storageFile = storageFile;
}
}

View File

@ -1,6 +1,7 @@
package eu.eudat.model.tenantconfiguration;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.TenantConfigurationType;
import java.time.Instant;
import java.util.UUID;
@ -11,6 +12,10 @@ public class TenantConfiguration {
public static final String _id = "id";
private TenantConfigurationType type;
public static final String _type = "type";
private Instant createdAt;
public static final String _createdAt = "createdAt";
@ -47,6 +52,9 @@ public class TenantConfiguration {
public static final String _hash = "hash";
private Boolean belongsToCurrentTenant;
public static final String _belongsToCurrentTenant = "belongsToCurrentTenant";
public UUID getId() {
return id;
}
@ -126,4 +134,20 @@ public class TenantConfiguration {
public void setHash(String hash) {
this.hash = hash;
}
public Boolean getBelongsToCurrentTenant() {
return belongsToCurrentTenant;
}
public void setBelongsToCurrentTenant(Boolean belongsToCurrentTenant) {
this.belongsToCurrentTenant = belongsToCurrentTenant;
}
public TenantConfigurationType getType() {
return type;
}
public void setType(TenantConfigurationType type) {
this.type = type;
}
}

View File

@ -0,0 +1,189 @@
package eu.eudat.query;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.TenantConfigurationType;
import eu.eudat.data.TenantConfigurationEntity;
import eu.eudat.model.tenantconfiguration.TenantConfiguration;
import eu.eudat.query.utils.QueryUtilsService;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.data.query.QueryContext;
import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.time.Instant;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantConfigurationQuery extends QueryBase<TenantConfigurationEntity> {
private Collection<UUID> ids;
private Collection<IsActive> isActives;
private Collection<TenantConfigurationType> types;
private Collection<UUID> excludedIds;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final QueryUtilsService queryUtilsService;
public TenantConfigurationQuery(QueryUtilsService queryUtilsService) {
this.queryUtilsService = queryUtilsService;
}
public TenantConfigurationQuery ids(UUID value) {
this.ids = List.of(value);
return this;
}
public TenantConfigurationQuery ids(UUID... value) {
this.ids = Arrays.asList(value);
return this;
}
public TenantConfigurationQuery ids(Collection<UUID> values) {
this.ids = values;
return this;
}
public TenantConfigurationQuery isActive(IsActive value) {
this.isActives = List.of(value);
return this;
}
public TenantConfigurationQuery isActive(IsActive... value) {
this.isActives = Arrays.asList(value);
return this;
}
public TenantConfigurationQuery isActive(Collection<IsActive> values) {
this.isActives = values;
return this;
}
public TenantConfigurationQuery types(TenantConfigurationType value) {
this.types = List.of(value);
return this;
}
public TenantConfigurationQuery types(TenantConfigurationType... value) {
this.types = Arrays.asList(value);
return this;
}
public TenantConfigurationQuery types(Collection<TenantConfigurationType> values) {
this.types = values;
return this;
}
public TenantConfigurationQuery excludedIds(Collection<UUID> values) {
this.excludedIds = values;
return this;
}
public TenantConfigurationQuery excludedIds(UUID value) {
this.excludedIds = List.of(value);
return this;
}
public TenantConfigurationQuery excludedIds(UUID... value) {
this.excludedIds = Arrays.asList(value);
return this;
}
public TenantConfigurationQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) ||this.isEmpty(this.isActives)||this.isEmpty(this.types);
}
@Override
protected Class<TenantConfigurationEntity> entityClass() {
return TenantConfigurationEntity.class;
}
@Override
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
List<Predicate> predicates = new ArrayList<>();
if (this.ids != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._id));
for (UUID item : this.ids) inClause.value(item);
predicates.add(inClause);
}
if (this.isActives != null) {
CriteriaBuilder.In<IsActive> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._isActive));
for (IsActive item : this.isActives) inClause.value(item);
predicates.add(inClause);
}
if (this.types != null) {
CriteriaBuilder.In<TenantConfigurationType> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._type));
for (TenantConfigurationType item : this.types) inClause.value(item);
predicates.add(inClause);
}
if (this.excludedIds != null) {
CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._id));
for (UUID item : this.excludedIds)
notInClause.value(item);
predicates.add(notInClause.not());
}
if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
return queryContext.CriteriaBuilder.and(predicatesArray);
} else {
return null;
}
}
@Override
protected TenantConfigurationEntity convert(Tuple tuple, Set<String> columns) {
TenantConfigurationEntity item = new TenantConfigurationEntity();
item.setId(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._id, UUID.class));
item.setValue(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._value, String.class));
item.setTenantId(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._tenantId, UUID.class));
item.setType(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._type, TenantConfigurationType.class));
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._createdAt, Instant.class));
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._updatedAt, Instant.class));
item.setIsActive(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._isActive, IsActive.class));
return item;
}
@Override
protected String fieldNameOf(FieldResolver item) {
if (item.match(TenantConfiguration._id)) return TenantConfigurationEntity._id;
else if (item.match(TenantConfiguration._type)) return TenantConfigurationEntity._type;
else if (item.prefix(TenantConfiguration._cssColors)) return TenantConfigurationEntity._value;
else if (item.match(TenantConfiguration._cssColors)) return TenantConfigurationEntity._value;
else if (item.prefix(TenantConfiguration._depositPlugins)) return TenantConfigurationEntity._value;
else if (item.match(TenantConfiguration._depositPlugins)) return TenantConfigurationEntity._value;
else if (item.prefix(TenantConfiguration._defaultUserLocale)) return TenantConfigurationEntity._value;
else if (item.match(TenantConfiguration._defaultUserLocale)) return TenantConfigurationEntity._value;
else if (item.prefix(TenantConfiguration._fileTransformerPlugins)) return TenantConfigurationEntity._value;
else if (item.match(TenantConfiguration._fileTransformerPlugins)) return TenantConfigurationEntity._value;
else if (item.prefix(TenantConfiguration._logo)) return TenantConfigurationEntity._value;
else if (item.match(TenantConfiguration._logo)) return TenantConfigurationEntity._value;
else if (item.match(TenantConfiguration._createdAt)) return TenantConfigurationEntity._createdAt;
else if (item.match(TenantConfiguration._updatedAt)) return TenantConfigurationEntity._updatedAt;
else if (item.match(TenantConfiguration._isActive)) return TenantConfigurationEntity._isActive;
else if (item.match(TenantConfiguration._belongsToCurrentTenant)) return TenantConfigurationEntity._tenantId;
else if (item.match(TenantConfigurationEntity._tenantId)) return TenantConfigurationEntity._tenantId;
else return null;
}
}

View File

@ -169,7 +169,6 @@ public class TenantQuery extends QueryBase<TenantEntity> {
item.setCode(QueryBase.convertSafe(tuple, columns, TenantEntity._code, String.class));
item.setName(QueryBase.convertSafe(tuple, columns, TenantEntity._name, String.class));
item.setDescription(QueryBase.convertSafe(tuple, columns, TenantEntity._description, String.class));
item.setConfig(QueryBase.convertSafe(tuple, columns, TenantEntity._config, String.class));
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, TenantEntity._createdAt, Instant.class));
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, TenantEntity._updatedAt, Instant.class));
item.setIsActive(QueryBase.convertSafe(tuple, columns, TenantEntity._isActive, IsActive.class));
@ -182,7 +181,6 @@ public class TenantQuery extends QueryBase<TenantEntity> {
else if (item.match(Tenant._code)) return TenantEntity._code;
else if (item.match(Tenant._name)) return TenantEntity._name;
else if (item.match(Tenant._description)) return TenantEntity._description;
else if (item.prefix(Tenant._config)) return TenantEntity._config;
else if (item.match(Tenant._createdAt)) return TenantEntity._createdAt;
else if (item.match(Tenant._updatedAt)) return TenantEntity._updatedAt;
else if (item.match(Tenant._isActive)) return TenantEntity._isActive;

View File

@ -0,0 +1,63 @@
package eu.eudat.query.lookup;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.TenantConfigurationType;
import eu.eudat.query.TenantConfigurationQuery;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
import java.util.List;
import java.util.UUID;
public class TenantConfigurationLookup extends Lookup {
private List<IsActive> isActive;
private List<TenantConfigurationType> types;
private List<UUID> ids;
private List<UUID> excludedIds;
public List<IsActive> getIsActive() {
return isActive;
}
public void setIsActive(List<IsActive> isActive) {
this.isActive = isActive;
}
public List<UUID> getIds() {
return ids;
}
public void setIds(List<UUID> ids) {
this.ids = ids;
}
public List<UUID> getExcludedIds() {
return excludedIds;
}
public void setExcludedIds(List<UUID> excludeIds) {
this.excludedIds = excludeIds;
}
public List<TenantConfigurationType> getTypes() {
return types;
}
public void setTypes(List<TenantConfigurationType> types) {
this.types = types;
}
public TenantConfigurationQuery enrich(QueryFactory queryFactory) {
TenantConfigurationQuery query = queryFactory.query(TenantConfigurationQuery.class);
if (this.types != null) query.types(this.types);
if (this.isActive != null) query.isActive(this.isActive);
if (this.ids != null) query.ids(this.ids);
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
this.enrichCommon(query);
return query;
}
}

View File

@ -6,7 +6,6 @@ import eu.eudat.authorization.Permission;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.scope.tenant.TenantScope;
import eu.eudat.commons.types.tenant.*;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.TenantEntity;
import eu.eudat.data.TenantEntityManager;
@ -18,18 +17,13 @@ import eu.eudat.integrationevent.outbox.tenantremoval.TenantRemovalIntegrationEv
import eu.eudat.integrationevent.outbox.tenanttouched.TenantTouchedIntegrationEvent;
import eu.eudat.integrationevent.outbox.tenanttouched.TenantTouchedIntegrationEventHandler;
import eu.eudat.model.Tenant;
import eu.eudat.model.UserCredential;
import eu.eudat.model.builder.TenantBuilder;
import eu.eudat.model.deleter.TenantDeleter;
import eu.eudat.model.deleter.UserRoleDeleter;
import eu.eudat.model.persist.TenantPersist;
import eu.eudat.model.persist.tenantconfig.*;
import eu.eudat.model.tenantconfig.TenantSource;
import eu.eudat.query.UserCredentialQuery;
import eu.eudat.query.UserRoleQuery;
import eu.eudat.service.encryption.EncryptionService;
import eu.eudat.service.keycloak.KeycloakService;
import eu.eudat.service.responseutils.ResponseUtilsService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.deleter.DeleterFactory;
@ -49,7 +43,9 @@ import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import javax.crypto.*;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.management.InvalidApplicationException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
@ -58,7 +54,6 @@ import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@Service
public class TenantServiceImpl implements TenantService {
@ -143,7 +138,6 @@ public class TenantServiceImpl implements TenantService {
data.setName(model.getName());
data.setDescription(model.getDescription());
data.setUpdatedAt(Instant.now());
data.setConfig(this.xmlHandlingService.toXmlSafe(this.buildConfigEntity(model.getConfig())));
if (isUpdate) this.entityManager.merge(data);
else this.entityManager.persist(data);
@ -196,75 +190,18 @@ public class TenantServiceImpl implements TenantService {
}
private @NotNull TenantConfigEntity buildConfigEntity(TenantConfigPersist persist) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
TenantConfigEntity data = new TenantConfigEntity();
if (persist == null) return data;
if (persist.getDeposit() != null) {
data.setDeposit(this.buildDepositConfigEntity(persist.getDeposit()));
}
if (persist.getFileTransformers() != null) {
data.setFileTransformers(this.buildFileConfigEntity(persist.getFileTransformers()));
}
return data;
}
private @NotNull TenantDepositConfigEntity buildDepositConfigEntity(TenantDepositConfigPersist persist) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
TenantDepositConfigEntity data = new TenantDepositConfigEntity();
if (persist == null) return data;
if (!this.conventionService.isListNullOrEmpty(persist.getSources())) {
data.setSources(new ArrayList<>());
for (TenantSourcePersist sourcePersist : persist.getSources()) {
data.getSources().add(this.buildSourceEntity(sourcePersist));
}
}
return data;
}
private @NotNull TenantFileTransformersConfigEntity buildFileConfigEntity(TenantFileTransformersConfigPersist persist) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
TenantFileTransformersConfigEntity data = new TenantFileTransformersConfigEntity();
if (persist == null) return data;
if (!this.conventionService.isListNullOrEmpty(persist.getSources())) {
data.setSources(new ArrayList<>());
for (TenantSourcePersist sourcePersist : persist.getSources()) {
data.getSources().add(this.buildSourceEntity(sourcePersist));
}
}
return data;
}
private @NotNull TenantSourceEntity buildSourceEntity(TenantSourcePersist persist) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException {
TenantSourceEntity data = new TenantSourceEntity();
if (persist == null) return data;
data.setUrl(persist.getUrl());
data.setCodes(persist.getCodes());
data.setIssuerUrl(persist.getIssuerUrl());
data.setClientId(persist.getClientId());
data.setClientSecret(this.encryptionService.encryptAES(persist.getClientSecret(), properties.getConfigEncryptionAesKey(), properties.getConfigEncryptionAesIv()));
//data.setClientSecret(persist.getClientSecret());
data.setScope(persist.getScope());
return data;
}
@Override
public Tenant decryptTenant(Tenant model) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, InvalidApplicationException {
if (model.getConfig() != null && model.getConfig().getDeposit() != null && model.getConfig().getDeposit().getSources() != null) {
for (TenantSource source : model.getConfig().getDeposit().getSources().stream().toList()) {
source.setClientSecret(this.encryptionService.decryptAES(source.getClientSecret(), properties.getConfigEncryptionAesKey(), properties.getConfigEncryptionAesIv()));
}
}
if (model.getConfig() != null && model.getConfig().getFileTransformers() != null && model.getConfig().getFileTransformers().getSources() != null) {
for (TenantSource source : model.getConfig().getFileTransformers().getSources().stream().toList()) {
source.setClientSecret(this.encryptionService.decryptAES(source.getClientSecret(), properties.getConfigEncryptionAesKey(), properties.getConfigEncryptionAesIv()));
}
}
// if (model.getConfig() != null && model.getConfig().getDeposit() != null && model.getConfig().getDeposit().getSources() != null) {
// for (TenantSource source : model.getConfig().getDeposit().getSources().stream().toList()) {
// source.setClientSecret(this.encryptionService.decryptAES(source.getClientSecret(), properties.getConfigEncryptionAesKey(), properties.getConfigEncryptionAesIv()));
// }
// }
// if (model.getConfig() != null && model.getConfig().getFileTransformers() != null && model.getConfig().getFileTransformers().getSources() != null) {
// for (TenantSource source : model.getConfig().getFileTransformers().getSources().stream().toList()) {
// source.setClientSecret(this.encryptionService.decryptAES(source.getClientSecret(), properties.getConfigEncryptionAesKey(), properties.getConfigEncryptionAesIv()));
// }
// }
TenantEntity data = this.entityManager.find(TenantEntity.class, model.getId());
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Tenant.class.getSimpleName()}, LocaleContextHolder.getLocale()));