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

This commit is contained in:
Diamantis Tziotzios 2023-11-24 17:58:25 +02:00
commit 8a20687491
52 changed files with 2050 additions and 203 deletions

View File

@ -0,0 +1,34 @@
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

@ -0,0 +1,25 @@
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

@ -0,0 +1,24 @@
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

@ -0,0 +1,79 @@
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

@ -0,0 +1,20 @@
package eu.eudat.configurations.tenant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableConfigurationProperties(TenantProperties.class)
public class TenantConfiguration {
private final TenantProperties properties;
@Autowired
public TenantConfiguration(TenantProperties properties) {
this.properties = properties;
}
public TenantProperties getProperties() {
return properties;
}
}

View File

@ -0,0 +1,26 @@
package eu.eudat.configurations.tenant;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "tenant")
public class TenantProperties {
private String configEncryptionAesKey;
private String configEncryptionAesIv;
public String getConfigEncryptionAesKey() {
return configEncryptionAesKey;
}
public void setConfigEncryptionAesKey(String configEncryptionAesKey) {
this.configEncryptionAesKey = configEncryptionAesKey;
}
public String getConfigEncryptionAesIv() {
return configEncryptionAesIv;
}
public void setConfigEncryptionAesIv(String configEncryptionAesIv) {
this.configEncryptionAesIv = configEncryptionAesIv;
}
}

View File

@ -4,7 +4,7 @@ import eu.eudat.commons.enums.DmpAccessType;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.DmpVersionStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.converters.enums.DmpAccessTypeConverter;
import eu.eudat.data.converters.enums.DmpAccessTypeNullableConverter;
import eu.eudat.data.converters.enums.DmpStatusConverter;
import eu.eudat.data.converters.enums.DmpVersionStatusConverter;
import eu.eudat.data.converters.enums.IsActiveConverter;
@ -41,13 +41,13 @@ public class DmpEntity implements DataEntity<DmpEntity, UUID> {
public static final String _versionStatus = "versionStatus";
@Column(name = "status", nullable = false)
@Column(name = "status")
@Convert(converter = DmpStatusConverter.class)
private DmpStatus status;
public static final String _status = "status";
@Column(name = "properties")
@Column(name = "properties", nullable = false)
private String properties;
public static final String _properties = "properties";
@ -57,7 +57,7 @@ public class DmpEntity implements DataEntity<DmpEntity, UUID> {
public static final String _groupId = "groupId";
@Column(name = "description")
@Column(name = "description", nullable = false)
private String description;
public static final String _description = "description";
@ -72,7 +72,7 @@ public class DmpEntity implements DataEntity<DmpEntity, UUID> {
public static final String _updatedAt = "updatedAt";
@Column(name = "is_active", nullable = false)
@Column(name = "is_active")
@Convert(converter = IsActiveConverter.class)
private IsActive isActive;
@ -89,7 +89,7 @@ public class DmpEntity implements DataEntity<DmpEntity, UUID> {
public static final String _creatorId = "creatorId";
@Column(name = "access_type", nullable = false)
@Convert(converter = DmpAccessTypeConverter.class)
@Convert(converter = DmpAccessTypeNullableConverter.class)
private DmpAccessType accessType;
public static final String _accessType = "accessType";
@ -99,12 +99,12 @@ public class DmpEntity implements DataEntity<DmpEntity, UUID> {
public static final String _blueprintId = "blueprintId";
@Column(name = "language")
@Column(name = "language", nullable = false)
private String language;
public static final String _language = "language";
@Column(name = "public_after")
@Column(name = "public_after", nullable = false)
private Instant publicAfter;
public static final String _publicAfter = "publicAfter";

View File

@ -1,14 +0,0 @@
package eu.eudat.data.converters.enums;
import eu.eudat.commons.enums.DmpAccessType;
import jakarta.persistence.Converter;
@Converter
public class DmpAccessTypeConverter extends DatabaseEnumConverter<DmpAccessType, Short> {
@Override
protected DmpAccessType of(Short i) {
return DmpAccessType.of(i);
}
}

View File

@ -0,0 +1,25 @@
package eu.eudat.data.converters.enums;
import eu.eudat.commons.enums.DmpAccessType;
import jakarta.persistence.Converter;
@Converter
public class DmpAccessTypeNullableConverter extends DatabaseEnumConverter<DmpAccessType, Short> {
@Override
protected DmpAccessType of(Short i) {
return DmpAccessType.of(i);
}
@Override
public Short convertToDatabaseColumn(DmpAccessType value) {
if (value == null) return null;
return value.getValue();
}
@Override
public DmpAccessType convertToEntityAttribute(Short dbData) {
return dbData == null ? null : this.of(dbData);
}
}

View File

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

View File

@ -1,9 +1,13 @@
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;
import gr.cite.tools.logging.DataLogEntry;
@ -20,10 +24,14 @@ import java.util.*;
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantBuilder extends BaseBuilder<Tenant, TenantEntity> {
private final BuilderFactory builderFactory;
private final XmlHandlingService xmlHandlingService;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public TenantBuilder(ConventionService conventionService) {
public TenantBuilder(ConventionService conventionService, BuilderFactory builderFactory, XmlHandlingService xmlHandlingService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantBuilder.class)));
this.builderFactory = builderFactory;
this.xmlHandlingService = xmlHandlingService;
}
public TenantBuilder authorize(EnumSet<AuthorizationFlags> values){
@ -36,6 +44,8 @@ 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){
Tenant m = new Tenant();
@ -44,7 +54,10 @@ 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(fields.hasField(this.asIndexer(Tenant._config))) m.setConfig(d.getConfig());
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,60 @@
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

@ -0,0 +1,61 @@
package eu.eudat.model.builder.tenantconfig;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.tenant.TenantDepositConfigEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.tenantconfig.TenantDepositConfig;
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 TenantDepositConfigBuilder extends BaseBuilder<TenantDepositConfig, TenantDepositConfigEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public TenantDepositConfigBuilder(
ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantDepositConfigBuilder.class)));
this.builderFactory = builderFactory;
}
public TenantDepositConfigBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<TenantDepositConfig> build(FieldSet fields, List<TenantDepositConfigEntity> 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));
List<TenantDepositConfig> models = new ArrayList<>();
for (TenantDepositConfigEntity d : data) {
TenantDepositConfig m = new TenantDepositConfig();
if (!sourcesFields.isEmpty() && d.getSources() != null) {
m.setSources(this.builderFactory.builder(TenantSourceBuilder.class).authorize(this.authorize).build(sourcesFields, d.getSources()));
}
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -0,0 +1,61 @@
package eu.eudat.model.builder.tenantconfig;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.tenant.TenantFileTransformersConfigEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.tenantconfig.TenantFileTransformersConfig;
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 TenantFileTransformersBuilder extends BaseBuilder<TenantFileTransformersConfig, TenantFileTransformersConfigEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public TenantFileTransformersBuilder(
ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantFileTransformersBuilder.class)));
this.builderFactory = builderFactory;
}
public TenantFileTransformersBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<TenantFileTransformersConfig> build(FieldSet fields, List<TenantFileTransformersConfigEntity> 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));
List<TenantFileTransformersConfig> models = new ArrayList<>();
for (TenantFileTransformersConfigEntity d : data) {
TenantFileTransformersConfig m = new TenantFileTransformersConfig();
if (!sourcesFields.isEmpty() && d.getSources() != null) {
m.setSources(this.builderFactory.builder(TenantSourceBuilder.class).authorize(this.authorize).build(sourcesFields, d.getSources()));
}
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -0,0 +1,63 @@
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,51 @@
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

@ -0,0 +1,48 @@
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

@ -0,0 +1,47 @@
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

@ -0,0 +1,43 @@
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

@ -2,6 +2,7 @@ package eu.eudat.model.persist;
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
import eu.eudat.commons.validation.ValidId;
import eu.eudat.model.persist.tenantconfig.TenantConfigPersist;
import jakarta.validation.constraints.*;
import java.util.UUID;
@ -26,7 +27,7 @@ public class TenantPersist {
@NotEmpty(message = "{validation.empty}")
private String description;
private String config;
private TenantConfigPersist config;
private String hash;
@ -62,11 +63,11 @@ public class TenantPersist {
this.description = description;
}
public String getConfig() {
public TenantConfigPersist getConfig() {
return config;
}
public void setConfig(String config) {
public void setConfig(TenantConfigPersist config) {
this.config = config;
}

View File

@ -0,0 +1,24 @@
package eu.eudat.model.persist.tenantconfig;
public class TenantConfigPersist {
private TenantDepositConfigPersist deposit;
private TenantFileTransformersConfigPersist 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;
}
}

View File

@ -0,0 +1,20 @@
package eu.eudat.model.persist.tenantconfig;
import jakarta.validation.Valid;
import java.util.List;
public class TenantDepositConfigPersist {
@Valid
private List<TenantSourcePersist> sources;
public List<TenantSourcePersist> getSources() {
return sources;
}
public void setSources(List<TenantSourcePersist> sources) {
this.sources = sources;
}
}

View File

@ -0,0 +1,20 @@
package eu.eudat.model.persist.tenantconfig;
import jakarta.validation.Valid;
import java.util.List;
public class TenantFileTransformersConfigPersist {
@Valid
private List<TenantSourcePersist> sources;
public List<TenantSourcePersist> getSources() {
return sources;
}
public void setSources(List<TenantSourcePersist> sources) {
this.sources = sources;
}
}

View File

@ -0,0 +1,82 @@
package eu.eudat.model.persist.tenantconfig;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.List;
public class TenantSourcePersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String url;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private List<String> codes;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String issuerUrl ;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String clientId;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String clientSecret;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
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

@ -0,0 +1,28 @@
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

@ -0,0 +1,17 @@
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

@ -0,0 +1,17 @@
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

@ -0,0 +1,73 @@
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

@ -38,6 +38,8 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
private Collection<UUID> descriptionTemplateGroupIds;
private Collection<UUID> sectionIds;
private Collection<IsActive> isActives;
private Collection<UUID> excludedIds;
@ -90,18 +92,18 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
return this;
}
public DmpDescriptionTemplateQuery dmpIds(UUID value) {
this.dmpIds = List.of(value);
public DmpDescriptionTemplateQuery sectionIds(UUID value) {
this.sectionIds = List.of(value);
return this;
}
public DmpDescriptionTemplateQuery dmpIds(UUID... value) {
this.dmpIds = Arrays.asList(value);
public DmpDescriptionTemplateQuery sectionIds(UUID... value) {
this.sectionIds = Arrays.asList(value);
return this;
}
public DmpDescriptionTemplateQuery dmpIds(Collection<UUID> values) {
this.dmpIds = values;
public DmpDescriptionTemplateQuery sectionIds(Collection<UUID> values) {
this.sectionIds = values;
return this;
}
@ -120,6 +122,21 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
return this;
}
public DmpDescriptionTemplateQuery dmpIds(UUID value) {
this.dmpIds = List.of(value);
return this;
}
public DmpDescriptionTemplateQuery dmpIds(UUID... value) {
this.dmpIds = Arrays.asList(value);
return this;
}
public DmpDescriptionTemplateQuery dmpIds(Collection<UUID> values) {
this.dmpIds = values;
return this;
}
public DmpDescriptionTemplateQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
@ -193,6 +210,12 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
inClause.value(item);
predicates.add(inClause);
}
if (this.sectionIds != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._sectionId));
for (UUID item : this.sectionIds)
inClause.value(item);
predicates.add(inClause);
}
if (this.isActives != null) {
CriteriaBuilder.In<IsActive> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._isActive));
for (IsActive item : this.isActives)

View File

@ -151,7 +151,7 @@ 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.match(Tenant._config)) return TenantEntity._config;
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,14 @@
package eu.eudat.service.encryption;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
public interface EncryptionService {
String encryptAES(String input, String key, String iv) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException;
String decryptAES(String cipherText, String key, String iv) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException;
}

View File

@ -0,0 +1,62 @@
package eu.eudat.service.encryption;
import eu.eudat.convention.ConventionService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
@Service
public class EncryptionServiceImpl implements EncryptionService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(EncryptionServiceImpl.class));
private final AuthorizationService authorizationService;
private final ConventionService conventionService;
@Autowired
public EncryptionServiceImpl(
AuthorizationService authorizationService,
ConventionService conventionService) {
this.authorizationService = authorizationService;
this.conventionService = conventionService;
}
@Override
public String encryptAES(String input, String keyString, String ivString) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException,
BadPaddingException, IllegalBlockSizeException {
SecretKey key = new SecretKeySpec(keyString.getBytes(),"AES");
IvParameterSpec ivParameterSpec = new IvParameterSpec(ivString.getBytes());
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key, ivParameterSpec );
byte[] cipherText = cipher.doFinal(input.getBytes());
return Base64.getEncoder()
.encodeToString(cipherText);
}
@Override
public String decryptAES(String cipherText, String keyString, String ivString) throws NoSuchPaddingException, NoSuchAlgorithmException,
InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
SecretKey key = new SecretKeySpec(keyString.getBytes(),"AES");
IvParameterSpec iv = new IvParameterSpec(ivString.getBytes());
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, key, iv);
byte[] plainText = cipher.doFinal(Base64.getDecoder()
.decode(cipherText));
return new String(plainText);
}
}

View File

@ -8,12 +8,23 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.fieldset.FieldSet;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.management.InvalidApplicationException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.UUID;
public interface TenantService {
Tenant persist(TenantPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException;
Tenant persist(TenantPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException,
InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException;
Tenant decryptTenant(Tenant model) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException;
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
}

View File

@ -4,6 +4,8 @@ import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.types.tenant.*;
import eu.eudat.configurations.tenant.TenantProperties;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.TenantEntity;
import eu.eudat.errorcode.ErrorThesaurusProperties;
@ -11,6 +13,9 @@ import eu.eudat.model.Tenant;
import eu.eudat.model.builder.TenantBuilder;
import eu.eudat.model.deleter.TenantDeleter;
import eu.eudat.model.persist.TenantPersist;
import eu.eudat.model.persist.tenantconfig.*;
import eu.eudat.model.tenantconfig.TenantSource;
import eu.eudat.service.encryption.EncryptionService;
import eu.eudat.service.responseutils.ResponseUtilsService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory;
@ -26,16 +31,23 @@ import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.ValidationService;
import jakarta.persistence.EntityManager;
import org.jetbrains.annotations.NotNull;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import javax.crypto.*;
import javax.management.InvalidApplicationException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
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 {
@ -57,6 +69,9 @@ public class TenantServiceImpl implements TenantService {
private final XmlHandlingService xmlHandlingService;
private final ErrorThesaurusProperties errors;
private final ValidationService validationService;
private final EncryptionService encryptionService;
private final TenantProperties properties;
@Autowired
public TenantServiceImpl(
@ -66,10 +81,10 @@ public class TenantServiceImpl implements TenantService {
BuilderFactory builderFactory,
ConventionService conventionService,
MessageSource messageSource, QueryFactory queryFactory,
ResponseUtilsService responseUtilsService,
ResponseUtilsService responseUtilsService,
XmlHandlingService xmlHandlingService,
ErrorThesaurusProperties errors,
ValidationService validationService) {
ErrorThesaurusProperties errors,
ValidationService validationService, EncryptionService encryptionService, TenantProperties properties) {
this.entityManager = entityManager;
this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory;
@ -81,10 +96,12 @@ public class TenantServiceImpl implements TenantService {
this.xmlHandlingService = xmlHandlingService;
this.errors = errors;
this.validationService = validationService;
this.encryptionService = encryptionService;
this.properties = properties;
}
@Override
public Tenant persist(TenantPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException {
public Tenant persist(TenantPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
logger.debug(new MapLogEntry("persisting data").And("model", model).And("fields", fields));
this.authorizationService.authorizeForce(Permission.EditTenant);
@ -94,8 +111,10 @@ public class TenantServiceImpl implements TenantService {
TenantEntity data;
if (isUpdate) {
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()));
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
if (data == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Tenant.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash()))
throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
} else {
data = new TenantEntity();
data.setId(UUID.randomUUID());
@ -107,15 +126,88 @@ public class TenantServiceImpl implements TenantService {
data.setName(model.getName());
data.setDescription(model.getDescription());
data.setUpdatedAt(Instant.now());
data.setConfig(model.getConfig());
data.setConfig(this.xmlHandlingService.toXmlSafe(this.buildConfigEntity(model.getConfig())));
if (isUpdate) this.entityManager.merge(data);
else this.entityManager.persist(data);
else this.entityManager.persist(data);
this.entityManager.flush();
return this.builderFactory.builder(TenantBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Tenant._id), data);
}
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 {
if (model.getConfig() != null && model.getConfig().getDeposit() != null && model.getConfig().getDeposit().getSources() != null) {
for (TenantSource source : model.getConfig().getDeposit().getSources().stream().collect(Collectors.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().collect(Collectors.toList())) {
source.setClientSecret(this.encryptionService.decryptAES(source.getClientSecret(), properties.getConfigEncryptionAesKey(), properties.getConfigEncryptionAesIv()));
}
}
return model;
}
@Override
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug("deleting : {}", id);

View File

@ -9,6 +9,7 @@ import eu.eudat.model.builder.TenantBuilder;
import eu.eudat.model.censorship.TenantCensor;
import eu.eudat.model.persist.TenantPersist;
import eu.eudat.model.result.QueryResult;
import eu.eudat.model.tenantconfig.TenantSource;
import eu.eudat.query.TenantQuery;
import eu.eudat.query.lookup.TenantLookup;
import eu.eudat.service.tenant.TenantService;
@ -30,13 +31,20 @@ import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.*;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.management.InvalidApplicationException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
@RestController
@RequestMapping(path = "api/tenant")
@ -72,7 +80,7 @@ public class TenantController {
}
@PostMapping("query")
public QueryResult<Tenant> query(@RequestBody TenantLookup lookup) throws MyApplicationException, MyForbiddenException {
public QueryResult<Tenant> query(@RequestBody TenantLookup lookup) throws MyApplicationException, MyForbiddenException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
logger.debug("querying {}", Tenant.class.getSimpleName());
this.censorFactory.censor(TenantCensor.class).censor(lookup.getProject(), null);
@ -80,6 +88,9 @@ public class TenantController {
List<TenantEntity> data = query.collectAs(lookup.getProject());
List<Tenant> models = this.builderFactory.builder(TenantBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data);
for (Tenant model: models) {
models.set(models.indexOf(model), this.tenantService.decryptTenant(model));
}
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
this.auditService.track(AuditableAction.Tenant_Query, "lookup", lookup);
@ -88,7 +99,7 @@ public class TenantController {
}
@GetMapping("{id}")
public Tenant get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
public Tenant get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException {
logger.debug(new MapLogEntry("retrieving" + Tenant.class.getSimpleName()).And("id", id).And("fields", fieldSet));
this.censorFactory.censor(TenantCensor.class).censor(fieldSet, null);
@ -98,6 +109,8 @@ public class TenantController {
if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Tenant.class.getSimpleName()}, LocaleContextHolder.getLocale()));
model = this.tenantService.decryptTenant(model);
this.auditService.track(AuditableAction.Tenant_Lookup, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
@ -108,7 +121,7 @@ public class TenantController {
@PostMapping("persist")
@Transactional
public Tenant persist(@MyValidate @RequestBody TenantPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException {
public Tenant persist(@MyValidate @RequestBody TenantPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
logger.debug(new MapLogEntry("persisting" + Tenant.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
this.censorFactory.censor(TenantCensor.class).censor(fieldSet, null);

View File

@ -19,4 +19,6 @@ spring:
optional:classpath:config/swagger.yml[.yml], optional:classpath:config/swagger-${spring.profiles.active}.yml[.yml], optional:file:../config/swagger-${spring.profiles.active}.yml[.yml],
optional:classpath:config/deposit.yml[.yml], optional:classpath:config/deposit-${spring.profiles.active}.yml[.yml], optional:file:../config/deposit-${spring.profiles.active}.yml[.yml],
optional:classpath:config/errors.yml[.yml], optional:classpath:config/errors-${spring.profiles.active}.yml[.yml], optional:file:../config/errors-${spring.profiles.active}.yml[.yml],
optional:classpath:config/reference-type.yml[.yml], optional:classpath:config/reference-type-${spring.profiles.active}.yml[.yml], optional:file:../config/reference-type-${spring.profiles.active}.yml[.yml]
optional:classpath:config/reference-type.yml[.yml], optional:classpath:config/reference-type-${spring.profiles.active}.yml[.yml], optional:file:../config/reference-type-${spring.profiles.active}.yml[.yml],
optional:classpath:config/tenant.yml[.yml], optional:classpath:config/tenant-${spring.profiles.active}.yml[.yml], optional:file:../config/tenant-${spring.profiles.active}.yml[.yml]

View File

@ -0,0 +1,3 @@
tenant:
configEncryptionAesKey: 42J7rLaej8X+kUGR
configEncryptionAesIv: oL859DQRZP+AhfQ+

View File

@ -19,8 +19,8 @@ CREATE TABLE public."Dmp"
finalized_at timestamp without time zone,
creator uuid NOT NULL,
blueprint uuid NOT NULL,
language character varying(100) COLLATE pg_catalog."default" NOT NULL,
access_type smallint NOT NULL,
language character varying(100) COLLATE pg_catalog."default",
access_type smallint,
public_after timestamp without time zone,
version_status smallint NOT NULL DEFAULT 1,
CONSTRAINT "Dmp_pkey" PRIMARY KEY (id),

View File

@ -13,15 +13,15 @@ BEGIN
END
FROM public."UserInfo";
INSERT INTO public."UserContactInfo" ("id", "user", "created_at","ordinal", "type", "value")
SELECT uuid_generate_v1(), "id", "created", 0, 0, "email"
FROM public."UserInfo"
WHERE "email" is not null AND email != '';
--INSERT INTO public."UserContactInfo" ("id", "user", "created_at","ordinal", "type", "value")
--SELECT uuid_generate_v1(), "id", "created", 0, 0, "email"
--FROM public."UserInfo"
--WHERE "email" is not null AND email != '';
INSERT INTO public."UserContactInfo" ("id", "user", "created_at", "ordinal", "type", "value")
SELECT uuid_generate_v1(), "UserId", "CreationTime", 1, 0, "Email"
FROM public."Credential"
WHERE "Email" is not null AND "Email" != '';
--INSERT INTO public."UserContactInfo" ("id", "user", "created_at", "ordinal", "type", "value")
--SELECT uuid_generate_v1(), "UserId", "CreationTime", 1, 0, "Email"
--FROM public."Credential"
--WHERE "Email" is not null AND "Email" != '';
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.021', '2023-11-20 12:00:00.000000+02', now(), 'Sync user tables data.');

View File

@ -4,7 +4,33 @@ export interface Tenant extends BaseEntity{
name: string;
code: string;
description: string;
config: string;
config?: TenantConfig;
}
export interface TenantConfig{
deposit: TenantDepositConfig;
fileTransformers: TenantFileTransformersConfig;
}
export interface TenantDepositConfig{
sources: TenantSource[];
}
export interface TenantFileTransformersConfig{
sources: TenantSource[];
}
export interface TenantSource{
url: string;
codes: string[];
issuerUrl: string;
clientId: string;
clientSecret: string;
scope: string;
}
export interface SourceCode{
code: string;
}
//persist
@ -13,5 +39,31 @@ export interface TenantPersist extends BaseEntityPersist{
name: string;
code: string;
description: string;
config: string;
config?: TenantConfigPersist;
}
export interface TenantConfigPersist{
deposit: TenantDepositConfigPersist;
fileTransformers: TenantFileTransformersConfigPersist;
}
export interface TenantDepositConfigPersist{
sources: TenantSourcePersist[];
}
export interface TenantFileTransformersConfigPersist{
sources: TenantSourcePersist[];
}
export interface TenantSourcePersist{
url: string;
codes: string[];
issuerUrl: string;
clientId: string;
clientSecret: string;
scope: string;
}
export interface SourceCodePersist{
code: string;
}

View File

@ -5,7 +5,7 @@
<app-navigation-breadcrumb />
</div>
<div class="col-auto">
<button mat-button class="action-btn" (click)="cancel()" type="button">{{'REFERENCE-TYPE-EDITOR.ACTIONS.CANCEL' | translate}}</button>
<button mat-button class="action-btn" (click)="cancel()" type="button">{{'TENANT-EDITOR.ACTIONS.CANCEL' | translate}}</button>
</div>
<div class="col-auto" *ngIf="!isNew">
<button mat-button class="action-btn" type="button" (click)="delete()">
@ -47,7 +47,7 @@
<div class="col-12">
<h3>{{'TENANT-EDITOR.FIELDS.DESCRIPTION' | translate}}</h3>
<div class="col-12">
<rich-text-editor-component [parentFormGroup]="formGroup" [controlName]="'description'" [placeholder]="'DATASET-PROFILE-EDITOR.STEPS.GENERAL-INFO.DATASET-TEMPLATE-DESCRIPTION-PLACEHOLDER'" [wrapperClasses]="(formGroup.get('description').touched && formGroup.get('description').hasError('required')) ? 'required' : ''" [editable]="formGroup.controls['description'].status !== 'DISABLED'">
<rich-text-editor-component [parentFormGroup]="formGroup" [controlName]="'description'" [placeholder]="'TENANT-EDITOR.FIELDS.DESCRIPTION-PLACEHOLDER'" [wrapperClasses]="(formGroup.get('description').touched && formGroup.get('description').hasError('required')) ? 'required' : ''" [editable]="formGroup.controls['description'].status !== 'DISABLED'">
</rich-text-editor-component>
<div [class]="(formGroup.get('description').touched && formGroup.get('description').hasError('required')) ? 'visible' : 'invisible'" class="mat-form-field formGroup-field-subscript-wrapper">
<mat-error>
@ -56,13 +56,172 @@
</div>
</div>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'TENANT-EDITOR.FIELDS.NAME' | translate}}</mat-label>
<input matInput type="text" name="config" [formControl]="formGroup.get('config')" required>
<mat-error *ngIf="formGroup.get('config').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<!-- Deposit -->
<div class="col-12">
<h3>
{{'TENANT-EDITOR.FIELDS.DEPOSIT' | translate}}
<button mat-button class="action-btn" type="button" (click)="addDepositSource()" [disabled]="formGroup.disabled">{{'TENANT-EDITOR.ACTIONS.ADD-SOURCE' | translate}}</button>
</h3>
<div *ngFor="let source of formGroup.get('config').get('deposit').get('sources').controls; let sourceIndex=index;" class="row mb-3">
<div class="col-12">
<div class="row mb-3 d-flex align-items-center">
<div class="col-auto d-flex">
<mat-card-title>{{'TENANT-EDITOR.FIELDS.SOURCE' | translate}} {{sourceIndex + 1}}</mat-card-title>
</div>
<div class="col-auto d-flex">
<button mat-icon-button class="action-list-icon" matTooltip="{{'TENANT-EDITOR.ACTIONS.REMOVE-SOURCE' | translate}}" (click)="removeDepositSource(sourceIndex)" [disabled]="formGroup.disabled">
<mat-icon>delete</mat-icon>
</button>
</div>
</div>
<div class="row" >
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'TENANT-EDITOR.FIELDS.URL' | translate}}</mat-label>
<input matInput type="text" name="url" [formControl]="source.get('url')" required>
<mat-error *ngIf="source.get('url').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'TENANT-EDITOR.FIELDS.ISSUER-URL' | translate}}</mat-label>
<input matInput type="text" name="issuerUrl" [formControl]="source.get('issuerUrl')" required>
<mat-error *ngIf="source.get('issuerUrl').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'TENANT-EDITOR.FIELDS.CLIENT-ID' | translate}}</mat-label>
<input matInput type="text" name="clientId" [formControl]="source.get('clientId')" required>
<mat-error *ngIf="source.get('clientId').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'TENANT-EDITOR.FIELDS.CLIENT-SECRET' | translate}}</mat-label>
<input matInput type="text" name="clientSecret" [formControl]="source.get('clientSecret')" required>
<mat-error *ngIf="source.get('clientSecret').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'TENANT-EDITOR.FIELDS.SCOPE' | translate}}</mat-label>
<input matInput type="text" name="scope" [formControl]="source.get('scope')" required>
<mat-error *ngIf="source.get('scope').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="chip-list">
<mat-label>{{'TENANT-EDITOR.FIELDS.CODES' | translate}}</mat-label>
<mat-chip-grid #chipGrid [formControl]="source.get('codes')">
<mat-chip-row *ngFor="let code of depositCodes"
(removed)="removeDepositCode(code)"
[editable]="true"
(edited)="editDepositCode(code, $event)">
{{code}}
<button matChipRemove>
<mat-icon>cancel</mat-icon>
</button>
</mat-chip-row>
<input placeholder="{{'TENANT-EDITOR.FIELDS.CODES-PLACEHOLDER' | translate}}"
[matChipInputFor]="chipGrid"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
[matChipInputAddOnBlur]="true"
(matChipInputTokenEnd)="addDepositCode($event)"/>
</mat-chip-grid>
</mat-form-field>
</div>
</div>
</div>
</div>
</div>
<div class="col-12">
<h3>
{{'TENANT-EDITOR.FIELDS.FILE-TRANSFORMERS' | translate}}
<button mat-button class="action-btn" type="button" (click)="addFileSource()" [disabled]="formGroup.disabled">{{'TENANT-EDITOR.ACTIONS.ADD-SOURCE' | translate}}</button>
</h3>
<div *ngFor="let source of formGroup.get('config').get('fileTransformers').get('sources').controls; let sourceIndex=index;" class="row mb-3">
<div class="col-12">
<div class="row mb-3 d-flex align-items-center">
<div class="col-auto d-flex">
<mat-card-title>{{'TENANT-EDITOR.FIELDS.SOURCE' | translate}} {{sourceIndex + 1}}</mat-card-title>
</div>
<div class="col-auto d-flex">
<button mat-icon-button class="action-list-icon" matTooltip="{{'TENANT-EDITOR.ACTIONS.REMOVE-SOURCE' | translate}}" (click)="removeFileSource(sourceIndex)" [disabled]="formGroup.disabled">
<mat-icon>delete</mat-icon>
</button>
</div>
</div>
<div class="row" >
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'TENANT-EDITOR.FIELDS.URL' | translate}}</mat-label>
<input matInput type="text" name="url" [formControl]="source.get('url')" required>
<mat-error *ngIf="source.get('url').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'TENANT-EDITOR.FIELDS.ISSUER-URL' | translate}}</mat-label>
<input matInput type="text" name="issuerUrl" [formControl]="source.get('issuerUrl')" required>
<mat-error *ngIf="source.get('issuerUrl').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'TENANT-EDITOR.FIELDS.CLIENT-ID' | translate}}</mat-label>
<input matInput type="text" name="clientId" [formControl]="source.get('clientId')" required>
<mat-error *ngIf="source.get('clientId').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'TENANT-EDITOR.FIELDS.CLIENT-SECRET' | translate}}</mat-label>
<input matInput type="text" name="clientSecret" [formControl]="source.get('clientSecret')" required>
<mat-error *ngIf="source.get('clientSecret').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'TENANT-EDITOR.FIELDS.SCOPE' | translate}}</mat-label>
<input matInput type="text" name="scope" [formControl]="source.get('scope')" required>
<mat-error *ngIf="source.get('scope').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="chip-list">
<mat-label>{{'TENANT-EDITOR.FIELDS.CODES' | translate}}</mat-label>
<mat-chip-grid #chipGrid [formControl]="source.get('codes')">
<mat-chip-row *ngFor="let code of fileTransformersCodes"
(removed)="removeFileCode(code)"
[editable]="true"
(edited)="editFileCode(code, $event)">
{{code}}
<button matChipRemove>
<mat-icon>cancel</mat-icon>
</button>
</mat-chip-row>
<input placeholder="{{'TENANT-EDITOR.FIELDS.CODES-PLACEHOLDER' | translate}}"
[matChipInputFor]="chipGrid"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
[matChipInputAddOnBlur]="true"
(matChipInputTokenEnd)="addFileCode($event)"/>
</mat-chip-grid>
</mat-form-field>
</div>
</div>
</div>
</div>
</div>
</div>
</mat-card-content>

View File

@ -23,21 +23,6 @@
background-color: #b0b0b0;
}
.finalize-btn {
border-radius: 30px;
border: 1px solid var(--primary-color);
background: transparent;
padding-left: 2em;
padding-right: 2em;
box-shadow: 0px 3px 6px #1E202029;
color: var(--primary-color);
&:disabled{
background-color: #CBCBCB;
color: #FFF;
border: 0px;
}
}
.action-btn {
border-radius: 30px;
background-color: var(--secondary-color);
@ -55,62 +40,4 @@
color: #FFF;
border: 0px;
}
}
.dlt-section-btn {
margin: 0;
position: absolute;
top: 50%;
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
.section-input {
position: relative;
}
.section-input .arrows {
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
}
.action-list-item{
display: flex;
align-items: center;
cursor: pointer;
.action-list-icon{
font-size: 1.2em;
// padding-right: 1em;
// width: 14px;
// margin-right: 0.5em;
// margin-left: -.09em;
// height: auto;
color: var(--primary-color);
}
.action-list-text{
font-size: 1em;
color: var(--primary-color);
}
}
.field-delete{
align-items: center;
display: flex;
cursor: pointer;
.field-delete-icon{
font-size: 1.2em;
width: 14px;
color: var(--primary-color);
}
.field-delete-text{
font-size: 1em;
margin-left: 0.5em;
color: var(--primary-color);
}
}

View File

@ -10,10 +10,8 @@ import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
import { DatePipe } from '@angular/common';
import { IsActive } from '@app/core/common/enum/is-active.enum';
import { AppPermission } from '@app/core/common/enum/permission.enum';
import { DatasetProfileModel } from '@app/core/model/dataset/dataset-profile';
import { Tenant, TenantPersist } from '@app/core/model/tenant/tenant';
import { AuthService } from '@app/core/services/auth/auth.service';
import { DmpService } from '@app/core/services/dmp/dmp.service';
import { LoggingService } from '@app/core/services/logging/logging-service';
import { MatomoService } from '@app/core/services/matomo/matomo-service';
import { FileUtils } from '@app/core/services/utilities/file-utils.service';
@ -29,7 +27,8 @@ import { TranslateService } from '@ngx-translate/core';
import { map, takeUntil } from 'rxjs/operators';
import { TenantEditorResolver } from './tenant-editor.resolver';
import { TenantEditorService } from './tenant-editor.service';
import { TenantEditorModel } from './tenant-editor.model';
import { TenantEditorModel, TenantSourceEditorModel } from './tenant-editor.model';
import { MatChipEditedEvent, MatChipInputEvent } from '@angular/material/chips';
@Component({
@ -44,6 +43,8 @@ export class TenantEditorComponent extends BaseEditor<TenantEditorModel, Tenant>
isDeleted = false;
formGroup: UntypedFormGroup = null;
showInactiveDetails = false;
depositCodes: string[] = [];
fileTransformersCodes: string[] = [];
protected get canDelete(): boolean {
return !this.isDeleted && !this.isNew && this.hasPermission(this.authService.permissionEnum.DeleteTenant);
@ -103,6 +104,11 @@ export class TenantEditorComponent extends BaseEditor<TenantEditorModel, Tenant>
prepareForm(data: Tenant) {
try {
this.editorModel = data ? new TenantEditorModel().fromModel(data) : new TenantEditorModel();
if(data && data.config){
if(data.config.deposit && data.config.deposit.sources) data.config.deposit.sources.forEach(source => this.depositCodes = source.codes)
if(data.config.fileTransformers && data.config.fileTransformers.sources) data.config.fileTransformers.sources.forEach(source => this.fileTransformersCodes = source.codes)
}
this.isDeleted = data ? data.isActive === IsActive.Inactive : false;
this.buildForm();
} catch (error) {
@ -182,4 +188,85 @@ export class TenantEditorComponent extends BaseEditor<TenantEditorModel, Tenant>
this.formService.validateAllFormFields(this.formGroup);
}
//
// deposit source
//
addDepositSource(): void {
const source: TenantSourceEditorModel = new TenantSourceEditorModel();
(this.formGroup.get('config').get('deposit').get('sources') as FormArray).push(source.buildForm());
}
removeDepositSource(sourceIndex: number): void {
(this.formGroup.get('config').get('deposit').get('sources') as FormArray).removeAt(sourceIndex);
}
// deposit source codes
addDepositCode(event: MatChipInputEvent): void {
const value = (event.value || '').trim();
if (value) this.depositCodes.push(value)
event.chipInput!.clear();
}
removeDepositCode(code: string): void {
const index = this.depositCodes.indexOf(code);
if (index >= 0) this.depositCodes.splice(index, 1);
}
editDepositCode(code: string, event: MatChipEditedEvent) {
const value = event.value.trim();
// Remove code if it no longer has a value
if (!value) {
this.removeDepositCode(code);
return;
}
const index = this.depositCodes.indexOf(code);
if (index >= 0) this.depositCodes[index] = value
}
//
// fileTransformers source
//
addFileSource(): void {
const source: TenantSourceEditorModel = new TenantSourceEditorModel();
(this.formGroup.get('config').get('fileTransformers').get('sources') as FormArray).push(source.buildForm());
}
removeFileSource(sourceIndex: number): void {
(this.formGroup.get('config').get('fileTransformers').get('sources') as FormArray).removeAt(sourceIndex);
}
// fileTransformers source codes
addFileCode(event: MatChipInputEvent): void {
const value = (event.value || '').trim();
if (value) this.fileTransformersCodes.push(value)
event.chipInput!.clear();
}
removeFileCode(code: string): void {
const index = this.fileTransformersCodes.indexOf(code);
if (index >= 0) this.fileTransformersCodes.splice(index, 1);
}
editFileCode(code: string, event: MatChipEditedEvent) {
const value = event.value.trim();
// Remove code if it no longer has a value
if (!value) {
this.removeFileCode(code);
return;
}
const index = this.fileTransformersCodes.indexOf(code);
if (index >= 0) this.fileTransformersCodes[index] = value
}
}

View File

@ -1,5 +1,5 @@
import { UntypedFormBuilder, UntypedFormGroup, Validators } from "@angular/forms";
import { Tenant, TenantPersist } from "@app/core/model/tenant/tenant";
import { Tenant, TenantConfig, TenantConfigPersist, TenantDepositConfig, TenantDepositConfigPersist, TenantFileTransformersConfig, TenantFileTransformersConfigPersist, TenantPersist, TenantSource, TenantSourcePersist } from "@app/core/model/tenant/tenant";
import { BaseEditorModel } from "@common/base/base-form-editor-model";
import { BackendErrorValidator } from "@common/forms/validation/custom-validator";
import { ValidationErrorModel } from "@common/forms/validation/error-model/validation-error-model";
@ -9,7 +9,7 @@ export class TenantEditorModel extends BaseEditorModel implements TenantPersist
name: string;
code: string;
description: string;
config: string;
config: TenantConfigEditorModel = new TenantConfigEditorModel();
permissions: string[];
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel();
@ -23,7 +23,7 @@ export class TenantEditorModel extends BaseEditorModel implements TenantPersist
this.name = item.name;
this.code = item.code;
this.description = item.description;
this.config = item.config;
if (item.config) this.config = new TenantConfigEditorModel().fromModel(item.config);
}
return this;
}
@ -36,7 +36,9 @@ export class TenantEditorModel extends BaseEditorModel implements TenantPersist
name: [{ value: this.name, disabled: disabled }, context.getValidation('name').validators],
code: [{ value: this.code, disabled: disabled }, context.getValidation('code').validators],
description: [{ value: this.description, disabled: disabled }, context.getValidation('description').validators],
config: [{ value: this.config, disabled: disabled }, context.getValidation('config').validators],
config: this.config.buildForm({
rootPath: `config.`
}),
hash: [{ value: this.hash, disabled: disabled }, context.getValidation('hash').validators]
});
}
@ -48,7 +50,6 @@ export class TenantEditorModel extends BaseEditorModel implements TenantPersist
baseValidationArray.push({ key: 'name', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'name')] });
baseValidationArray.push({ key: 'code', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'code')] });
baseValidationArray.push({ key: 'description', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'description')] });
baseValidationArray.push({ key: 'config', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'config')] });
baseValidationArray.push({ key: 'hash', validators: [] });
baseContext.validation = baseValidationArray;
@ -56,3 +57,241 @@ export class TenantEditorModel extends BaseEditorModel implements TenantPersist
}
}
export class TenantConfigEditorModel implements TenantConfigPersist {
deposit: TenantDepositConfigEditorModel = new TenantDepositConfigEditorModel();
fileTransformers: TenantFileTransformersConfigEditorModel = new TenantFileTransformersConfigEditorModel();
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
constructor(
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
) { }
public fromModel(item: TenantConfig): TenantConfigEditorModel {
if (item) {
if (item.deposit) this.deposit = new TenantDepositConfigEditorModel().fromModel(item.deposit);
if (item.fileTransformers) this.fileTransformers = new TenantFileTransformersConfigEditorModel().fromModel(item.fileTransformers);
}
return this;
}
buildForm(params?: {
context?: ValidationContext,
disabled?: boolean,
rootPath?: string
}): UntypedFormGroup {
let { context = null, disabled = false, rootPath } = params ?? {}
if (context == null) {
context = TenantConfigEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel,
rootPath
});
}
return this.formBuilder.group({
deposit: this.deposit.buildForm({
rootPath: `deposit.`
}),
fileTransformers: this.fileTransformers.buildForm({
rootPath: `fileTransformers.`
}),
});
}
static createValidationContext(params: {
rootPath?: string,
validationErrorModel: ValidationErrorModel
}): ValidationContext {
const { rootPath = '', validationErrorModel } = params;
const baseContext: ValidationContext = new ValidationContext();
const baseValidationArray: Validation[] = new Array<Validation>();
baseContext.validation = baseValidationArray;
return baseContext;
}
}
export class TenantDepositConfigEditorModel implements TenantDepositConfigPersist {
sources: TenantSourceEditorModel[]= [];
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
constructor(
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
) { }
public fromModel(item: TenantDepositConfig): TenantDepositConfigEditorModel {
if (item) {
if (item.sources) { item.sources.map(x => this.sources.push(new TenantSourceEditorModel().fromModel(x))); }
}
return this;
}
buildForm(params?: {
context?: ValidationContext,
disabled?: boolean,
rootPath?: string
}): UntypedFormGroup {
let { context = null, disabled = false, rootPath } = params ?? {}
if (context == null) {
context = TenantDepositConfigEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel,
rootPath
});
}
return this.formBuilder.group({
sources: this.formBuilder.array(
(this.sources ?? []).map(
(item, index) => new TenantSourceEditorModel(
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `sources[${index}].`
}), context.getValidation('sources')
)
),
});
}
static createValidationContext(params: {
rootPath?: string,
validationErrorModel: ValidationErrorModel
}): ValidationContext {
const { rootPath = '', validationErrorModel } = params;
const baseContext: ValidationContext = new ValidationContext();
const baseValidationArray: Validation[] = new Array<Validation>();
baseValidationArray.push({ key: 'sources', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}sources`)] });
baseContext.validation = baseValidationArray;
return baseContext;
}
}
export class TenantFileTransformersConfigEditorModel implements TenantFileTransformersConfigPersist {
sources: TenantSourceEditorModel[]= [];
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
constructor(
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
) { }
public fromModel(item: TenantFileTransformersConfig): TenantFileTransformersConfigEditorModel {
if (item) {
if (item.sources) { item.sources.map(x => this.sources.push(new TenantSourceEditorModel().fromModel(x))); }
}
return this;
}
buildForm(params?: {
context?: ValidationContext,
disabled?: boolean,
rootPath?: string
}): UntypedFormGroup {
let { context = null, disabled = false, rootPath } = params ?? {}
if (context == null) {
context = TenantFileTransformersConfigEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel,
rootPath
});
}
return this.formBuilder.group({
sources: this.formBuilder.array(
(this.sources ?? []).map(
(item, index) => new TenantSourceEditorModel(
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `sources[${index}].`
}), context.getValidation('sources')
)
),
});
}
static createValidationContext(params: {
rootPath?: string,
validationErrorModel: ValidationErrorModel
}): ValidationContext {
const { rootPath = '', validationErrorModel } = params;
const baseContext: ValidationContext = new ValidationContext();
const baseValidationArray: Validation[] = new Array<Validation>();
baseValidationArray.push({ key: 'sources', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}sources`)] });
baseContext.validation = baseValidationArray;
return baseContext;
}
}
export class TenantSourceEditorModel implements TenantSourcePersist {
url: string;
codes: string[]= [];
issuerUrl: string;
clientId: string;
clientSecret: string;
scope: string;
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
constructor(
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
) { }
public fromModel(item: TenantSource): TenantSourceEditorModel {
if (item) {
this.url = item.url;
//if (item.codes) { item.codes.map(x => this.codes.push(new SourceCodeEditorModel().fromModel(x))); }
this.codes = item.codes;
this.issuerUrl = item.issuerUrl;
this.clientId = item.clientId;
this.clientSecret = item.clientSecret;
this.scope = item.scope;
}
return this;
}
buildForm(params?: {
context?: ValidationContext,
disabled?: boolean,
rootPath?: string
}): UntypedFormGroup {
let { context = null, disabled = false, rootPath } = params ?? {}
if (context == null) {
context = TenantSourceEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel,
rootPath
});
}
return this.formBuilder.group({
url: [{ value: this.url, disabled: disabled }, context.getValidation('url').validators],
issuerUrl: [{ value: this.issuerUrl, disabled: disabled }, context.getValidation('issuerUrl').validators],
clientId: [{ value: this.clientId, disabled: disabled }, context.getValidation('clientId').validators],
clientSecret: [{ value: this.clientSecret, disabled: disabled }, context.getValidation('clientSecret').validators],
scope: [{ value: this.scope, disabled: disabled }, context.getValidation('scope').validators],
codes: [{ value: this.codes, disabled: disabled }, context.getValidation('codes').validators],
});
}
static createValidationContext(params: {
rootPath?: string,
validationErrorModel: ValidationErrorModel
}): ValidationContext {
const { rootPath = '', validationErrorModel } = params;
const baseContext: ValidationContext = new ValidationContext();
const baseValidationArray: Validation[] = new Array<Validation>();
baseValidationArray.push({ key: 'url', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}url`)] });
baseValidationArray.push({ key: 'codes', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}codes`)] });
baseValidationArray.push({ key: 'issuerUrl', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}issuerUrl`)] });
baseValidationArray.push({ key: 'clientId', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}clientId`)] });
baseValidationArray.push({ key: 'clientSecret', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}clientSecret`)] });
baseValidationArray.push({ key: 'scope', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}scope`)] });
baseContext.validation = baseValidationArray;
return baseContext;
}
}

View File

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Tenant } from '@app/core/model/tenant/tenant';
import { SourceCode, Tenant, TenantConfig, TenantDepositConfig, TenantSource } from '@app/core/model/tenant/tenant';
import { TenantService } from '@app/core/services/tenant/tenant.service';
import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service';
import { BaseEditorResolver } from '@common/base/base-editor.resolver';
@ -22,7 +22,22 @@ export class TenantEditorResolver extends BaseEditorResolver {
nameof<Tenant>(x => x.name),
nameof<Tenant>(x => x.code),
nameof<Tenant>(x => x.description),
nameof<Tenant>(x => x.config),
[nameof<Tenant>(x => x.config), nameof<TenantConfig>(x => x.deposit), nameof<TenantDepositConfig>(x => x.sources), nameof<TenantSource>(x => x.url)].join('.'),
[nameof<Tenant>(x => x.config), nameof<TenantConfig>(x => x.deposit), nameof<TenantDepositConfig>(x => x.sources), nameof<TenantSource>(x => x.issuerUrl)].join('.'),
[nameof<Tenant>(x => x.config), nameof<TenantConfig>(x => x.deposit), nameof<TenantDepositConfig>(x => x.sources), nameof<TenantSource>(x => x.clientId)].join('.'),
[nameof<Tenant>(x => x.config), nameof<TenantConfig>(x => x.deposit), nameof<TenantDepositConfig>(x => x.sources), nameof<TenantSource>(x => x.clientSecret)].join('.'),
[nameof<Tenant>(x => x.config), nameof<TenantConfig>(x => x.deposit), nameof<TenantDepositConfig>(x => x.sources), nameof<TenantSource>(x => x.scope)].join('.'),
[nameof<Tenant>(x => x.config), nameof<TenantConfig>(x => x.deposit), nameof<TenantDepositConfig>(x => x.sources), nameof<TenantSource>(x => x.codes)].join('.'),
[nameof<Tenant>(x => x.config), nameof<TenantConfig>(x => x.fileTransformers), nameof<TenantDepositConfig>(x => x.sources), nameof<TenantSource>(x => x.url)].join('.'),
[nameof<Tenant>(x => x.config), nameof<TenantConfig>(x => x.fileTransformers), nameof<TenantDepositConfig>(x => x.sources), nameof<TenantSource>(x => x.issuerUrl)].join('.'),
[nameof<Tenant>(x => x.config), nameof<TenantConfig>(x => x.fileTransformers), nameof<TenantDepositConfig>(x => x.sources), nameof<TenantSource>(x => x.clientId)].join('.'),
[nameof<Tenant>(x => x.config), nameof<TenantConfig>(x => x.fileTransformers), nameof<TenantDepositConfig>(x => x.sources), nameof<TenantSource>(x => x.clientSecret)].join('.'),
[nameof<Tenant>(x => x.config), nameof<TenantConfig>(x => x.fileTransformers), nameof<TenantDepositConfig>(x => x.sources), nameof<TenantSource>(x => x.scope)].join('.'),
[nameof<Tenant>(x => x.config), nameof<TenantConfig>(x => x.fileTransformers), nameof<TenantDepositConfig>(x => x.sources), nameof<TenantSource>(x => x.codes)].join('.'),
nameof<Tenant>(x => x.createdAt),
nameof<Tenant>(x => x.updatedAt),
nameof<Tenant>(x => x.hash),

View File

@ -1205,12 +1205,27 @@
"FIELDS": {
"NAME": "Name",
"CODE": "Code",
"DESCRIPTION": "Description"
"DESCRIPTION": "Description",
"DESCRIPTION-PLACEHOLDER": "Tenant description",
"DEPOSIT":"Deposit",
"SOURCE": "Source",
"URL":"Url",
"CODES": "Codes",
"CODES-PLACEHOLDER": "New code ..",
"ISSUER-URL": "Issuer Url",
"CLIENT-ID": "Client ID",
"CLIENT-SECRET": "Client Secret",
"SCOPE": "Scope",
"FILE-TRANSFORMERS":"File transformers"
},
"ACTIONS": {
"SAVE": "Save",
"CANCEL": "Cancel",
"DELETE": "Delete"
"DELETE": "Delete",
"ADD-SOURCE": "Add Source",
"REMOVE-SOURCE": "Remove Source",
"ADD-CODE": "Add Code",
"REMOVE-CODE": "Remove Code"
},
"CONFIRM-DELETE-DIALOG": {
"MESSAGE": "Would you like to delete this Tenant?",

View File

@ -104,11 +104,11 @@ public class DatasetMigrationService {
throw new MyApplicationException("Migrate Dataset " + item.getId() + " cannot found section id for section " + item.getDmpSectionIndex());
}
List<DmpDescriptionTemplateEntity> itemDescriptionTemplates = descriptionTemplates.stream().filter(x-> x.getDescriptionTemplateId().equals(item.getProfile().getId()) && x.getDmpId().equals(item.getDmp().getId()) && x.getSectionId().equals(sectionId)).toList();
List<DmpDescriptionTemplateEntity> itemDescriptionTemplates = descriptionTemplates.stream().filter(x-> x.getDescriptionTemplateGroupId().equals(item.getProfile().getGroupId()) && x.getDmpId().equals(item.getDmp().getId()) && x.getSectionId().equals(sectionId)).toList();
if (itemDescriptionTemplates.isEmpty()) {
logger.error("Migrate Dataset " + item.getId() + " cannot found DmpDescriptionTemplateEntity for section " + item.getDmpSectionIndex());
if(descriptionTemplates.stream().filter(x-> x.getDmpId().equals(item.getDmp().getId()) && x.getSectionId().equals(sectionId)).count() > 0) continue;
if (descriptionTemplates.stream().filter(x-> x.getDmpId().equals(item.getDmp().getId()) && x.getSectionId().equals(sectionId)).count() > 0) continue;
throw new MyApplicationException("Migrate Dataset " + item.getId() + " cannot found DmpDescriptionTemplateEntity for section " + item.getDmpSectionIndex());
}
@ -128,6 +128,7 @@ public class DatasetMigrationService {
data.setDmpId(item.getDmp().getId());
data.setLabel(item.getLabel());
data.setDmpDescriptionTemplateId(itemDescriptionTemplates.get(0).getId());
data.setDescriptionTemplateId(item.getProfile().getId());
data.setCreatedAt(item.getCreated() != null ? item.getCreated().toInstant() : Instant.now());
data.setUpdatedAt(item.getModified() != null ? item.getModified().toInstant() : Instant.now());
if (item.getFinalizedAt() != null)
@ -157,7 +158,7 @@ public class DatasetMigrationService {
}
if (data.getCreatedById() == null){//TODO
if (data.getCreatedById() == null){
logger.error("Migration skipped creator not found " + item.getId());
throw new MyApplicationException("Migration skipped creator not found " + item.getId());
}

View File

@ -1,33 +1,25 @@
package eu.old.eudat.migration;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceFieldDataType;
import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.commons.types.reference.FieldEntity;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.data.DmpDescriptionTemplateEntity;
import eu.eudat.data.ReferenceEntity;
import eu.eudat.model.DmpBlueprint;
import eu.eudat.query.DescriptionTemplateQuery;
import eu.eudat.query.DmpBlueprintQuery;
import eu.eudat.query.DmpDescriptionTemplateQuery;
import eu.old.eudat.data.dao.entities.DmpDatasetProfileDao;
import eu.old.eudat.data.dao.entities.ResearcherDao;
import eu.old.eudat.data.entities.DMPDatasetProfile;
import eu.old.eudat.data.entities.Researcher;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
import eu.old.eudat.queryable.QueryableList;
import gr.cite.tools.data.query.Paging;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import jakarta.persistence.EntityManager;
import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaDelete;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Root;
import jakarta.xml.bind.JAXBException;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@ -36,6 +28,7 @@ import eu.eudat.commons.types.dmpblueprint.DefinitionEntity;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.security.SecureRandom;
import java.time.Instant;
import java.util.*;
@ -107,7 +100,7 @@ public class DmpDatasetProfileMigrationService {
DmpDescriptionTemplateEntity data = new DmpDescriptionTemplateEntity();
data.setId(UUID.randomUUID());
data.setDescriptionTemplateGroupId(item.getDatasetprofile().getId());
data.setDescriptionTemplateGroupId(item.getDatasetprofile().getGroupId());
data.setDmpId(item.getDmp().getId());
data.setCreatedAt(Instant.now());
data.setUpdatedAt(Instant.now());
@ -122,41 +115,41 @@ public class DmpDatasetProfileMigrationService {
}
} while (items != null && !items.isEmpty() && !TestMode);
removeDuplicates();
//removeDuplicates();
}
private void removeDuplicates() {
logger.debug("Checking for duplicates on DmpDescriptionTemplate table after migration");
int page = 0;
DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class);
long total = dmpDescriptionTemplateQuery.count();
List<DmpDescriptionTemplateEntity> dmpDescriptionTemplateEntities;
do {
logger.debug("Checking " + page * PageSize + " of " + total);
dmpDescriptionTemplateQuery.setPage(new Paging(page * PageSize, PageSize));
dmpDescriptionTemplateEntities = dmpDescriptionTemplateQuery.collect();
logger.debug("Record count to check: {}", total);
DmpDescriptionTemplateEntity previousEntity = null;
for(DmpDescriptionTemplateEntity currentEntity : dmpDescriptionTemplateEntities) {
if (previousEntity == null) {
previousEntity = currentEntity;
continue;
}
if (currentEntity.getDmpId().equals(previousEntity.getDmpId())
&& currentEntity.getDescriptionTemplateGroupId().equals(previousEntity.getDescriptionTemplateGroupId())
&& currentEntity.getSectionId().equals(previousEntity.getSectionId())
) {
logger.warn("Removing found duplicate DmpDescriptionTemplate entity ({}) after DmpDatasetProfiles migration", currentEntity.getId());
this.entityManager.remove(currentEntity);
} else {
previousEntity = currentEntity;
}
}
entityManager.flush();
CriteriaBuilder b = this.entityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> criteria = b.createQuery(Tuple.class);
Root<DmpDescriptionTemplateEntity> root = criteria.from(DmpDescriptionTemplateEntity.class);
criteria.groupBy(Arrays.asList(root.get("dmp"), root.get("descriptionTemplateGroupId"), root.get("sectionId")));
criteria.multiselect(root.get("dmp"), root.get("descriptionTemplateGroupId"), root.get("sectionId"), b.count(root));
List<Tuple> resultList = this.entityManager.createQuery(criteria).getResultList();
page++;
} while (!dmpDescriptionTemplateEntities.isEmpty() && !TestMode);
List<Tuple> duplicatesList = resultList.stream().filter(x -> (long) x.get(3) > 1).toList();
CriteriaDelete<DmpDescriptionTemplateEntity> delete = b.createCriteriaDelete(DmpDescriptionTemplateEntity.class);
Root<DmpDescriptionTemplateEntity> root1 = delete.from(DmpDescriptionTemplateEntity.class);
for (Tuple duplicate : duplicatesList) {
List<DmpDescriptionTemplateEntity> duplicateEntities = dmpDescriptionTemplateQuery
.dmpIds((UUID) duplicate.get(0))
.descriptionTemplateGroupIds((UUID) duplicate.get(1))
.sectionIds((UUID) duplicate.get(2))
.collect();
List<UUID> toDelete = new ArrayList<>(duplicateEntities.stream().map(DmpDescriptionTemplateEntity::getId).toList());
int random = new SecureRandom().nextInt(0, toDelete.size());
toDelete.remove(random);
delete.where(root1.get("id").in(toDelete));
this.entityManager.createQuery(delete).executeUpdate();
}
entityManager.flush();
}
@JsonIgnoreProperties({"validationErrorModel"})

View File

@ -66,10 +66,10 @@ public class DmpMigrationService {
data.setId(model.getId());
data.setLabel(model.getLabel());
data.setDescription(model.getDescription());
if (model.getCreator() != null) {
if (model.getCreator() != null && model.getCreator().getId() != null) {
data.setCreatorId(model.getCreator().getId());
} else {
List<DMP> groupDmps = dmpDao.asQueryable().where((builder, root) -> root.get("GroupId").in(List.of(item.getGroupId()))).toList();
List<DMP> groupDmps = dmpDao.asQueryable().where((builder, root) -> root.get("groupId").in(List.of(item.getGroupId()))).toList();
for (DMP groupDmp: groupDmps) {
DataManagementPlan groupDmpModel = new DataManagementPlan();
groupDmpModel.fromDataModel(groupDmp);

View File

@ -0,0 +1,66 @@
package eu.old.eudat.migration;
import eu.eudat.commons.enums.DmpUserRole;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DmpUserEntity;
import eu.old.eudat.data.dao.entities.UserDmpDao;
import eu.old.eudat.data.entities.UserDMP;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
import gr.cite.tools.logging.LoggerService;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.time.Instant;
import java.util.List;
@Service
public class DmpUserMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpUserMigrationService.class));
private final DatabaseRepository databaseRepository;
private final EntityManager entityManager;
private static final int PageSize = 500;
private static final boolean TestMode = false;
public DmpUserMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
this.databaseRepository = databaseRepository;
this.entityManager = entityManager;
}
public void migrate() {
UserDmpDao userDmpDao = databaseRepository.getUserDmpDao();
long total = userDmpDao.asQueryable().count();
logger.debug("Migrate UserDMP Total : " + total);
int page = 0;
List<UserDMP> items;
do {
items = userDmpDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate UserDMP " + page * PageSize + " of " + total);
for (UserDMP item : items) {
entityManager.detach(item);
DmpUserEntity data = new DmpUserEntity();
data.setId(item.getId());
data.setDmp(item.getDmp().getId());
data.setUserId(item.getUser().getId());
data.setRole(DmpUserRole.of(item.getRole().shortValue()));
data.setCreatedAt(Instant.now());
data.setUpdatedAt(Instant.now());
data.setIsActive(IsActive.Active);
this.entityManager.persist(data);
}
this.entityManager.flush();
page++;
}
} while (items != null && !items.isEmpty() && !TestMode);
}
}

View File

@ -0,0 +1,79 @@
package eu.old.eudat.migration;
import eu.eudat.commons.enums.ContactInfoType;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.data.ReferenceEntity;
import eu.eudat.data.UserContactInfoEntity;
import eu.old.eudat.data.dao.entities.FunderDao;
import eu.old.eudat.data.dao.entities.UserInfoDao;
import eu.old.eudat.data.entities.Credential;
import eu.old.eudat.data.entities.Funder;
import eu.old.eudat.data.entities.UserInfo;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
import gr.cite.tools.logging.LoggerService;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
@Service
public class UserContactInfoMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserContactInfoMigrationService.class));
private static final int PageSize = 500;
private static final boolean TestMode = false;
private final DatabaseRepository databaseRepository;
private final EntityManager entityManager;
public UserContactInfoMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
this.databaseRepository = databaseRepository;
this.entityManager = entityManager;
}
public void migrate(){
UserInfoDao userInfoDao = databaseRepository.getUserInfoDao();
long total = userInfoDao.asQueryable().count();
logger.debug("Migrate Contacts Total : " + total);
int page = 0;
List<UserInfo> items;
do {
items = userInfoDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("id"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Contacts " + page * PageSize + " of " + total);
for (UserInfo item : items) {
// entityManager.detach(item);
if (!item.getUserStatus().equals((short)0)) continue;
List<String> emails = new ArrayList<>();
if (item.getEmail() != null && !item.getEmail().isBlank()) emails.add(item.getEmail().toLowerCase(Locale.ROOT));
for (Credential credential: item.getCredentials()) {
if (credential.getStatus().equals(0) || credential.getEmail() == null || credential.getEmail().isBlank()) continue;
if (emails.stream().noneMatch(x-> x.equals(credential.getEmail().toLowerCase(Locale.ROOT))))
emails.add(credential.getEmail().toLowerCase(Locale.ROOT));
}
int i = 0;
for (String email: emails) {
UserContactInfoEntity data = new UserContactInfoEntity();
data.setId(UUID.randomUUID());
data.setType(ContactInfoType.Email);
data.setValue(email);
data.setUserId(item.getId());
data.setCreatedAt(item.getCreated().toInstant());
data.setOrdinal(i);
i++;
this.entityManager.persist(data);
}
}
this.entityManager.flush();
page++;
}
} while (items != null && !items.isEmpty() && !TestMode);
}
}

View File

@ -33,6 +33,8 @@ public class MigrationController {
private final DmpDatasetProfileMigrationService dmpDatasetProfileMigrationService;
private final OrganizationMigrationService organizationMigrationService;
private final ReferenceMigrationService referenceMigrationService;
private final UserContactInfoMigrationService userContactInfoMigrationService;
private final DmpUserMigrationService dmpUserMigrationService;
public MigrationController(
DmpMigrationService dmpMigrationService,
@ -47,7 +49,9 @@ public class MigrationController {
ResearcherMigrationService researcherMigrationService,
ServiceMigrationService serviceMigrationService,
OrganizationMigrationService organizationMigrationService,
ReferenceMigrationService referenceMigrationService) {
ReferenceMigrationService referenceMigrationService,
UserContactInfoMigrationService userContactInfoMigrationService,
DmpUserMigrationService dmpUserMigrationService) {
this.dmpMigrationService = dmpMigrationService;
this.datasetMigrationService = datasetMigrationService;
this.dmpDatasetProfileMigrationService = dmpDatasetProfileMigrationService;
@ -61,8 +65,42 @@ public class MigrationController {
this.serviceMigrationService = serviceMigrationService;
this.organizationMigrationService = organizationMigrationService;
this.referenceMigrationService = referenceMigrationService;
this.userContactInfoMigrationService = userContactInfoMigrationService;
this.dmpUserMigrationService = dmpUserMigrationService;
}
@GetMapping("all")
@Transactional
public boolean migrateAll() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException {
this.dataRepositoryMigrationService.migrate();
this.externalDatasetMigrationService.migrate();
this.funderMigrationService.migrate();
this.grantMigrationService.migrate();
this.organizationMigrationService.migrate();
this.projectMigrationService.migrate();
this.registryMigrationService.migrate();
this.researcherMigrationService.migrate();
this.serviceMigrationService.migrate();
this.dmpMigrationService.migrate();
this.dmpDatasetProfileMigrationService.migrate();
this.datasetMigrationService.migrate();
this.userContactInfoMigrationService.migrate();
return true;
}
@GetMapping("contacts")
@Transactional
public boolean migrateContacts() {
this.userContactInfoMigrationService.migrate();
return true;
}
@GetMapping("dmps")
@Transactional
public boolean migrateDmps() throws JsonProcessingException {
@ -106,6 +144,13 @@ public class MigrationController {
return true;
}
@GetMapping("dmp-users")
@Transactional
public boolean migrateDmpUsers() {
this.dmpUserMigrationService.migrate();
return true;
}
@GetMapping("dataset-references")
@Transactional
public boolean migrateDatasetReferences() {