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

This commit is contained in:
Sofia Papacharalampous 2024-04-22 13:37:25 +03:00
commit 3f1d5205ac
27 changed files with 638 additions and 74 deletions

View File

@ -11,6 +11,8 @@ import javax.management.InvalidApplicationException;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
@Component
@RequestScope
public class TenantScope {
public static final String TenantReplaceParameter = "::TenantCode::";
private final MultitenancyProperties multitenancy;

View File

@ -162,5 +162,10 @@ public class AuditableAction {
public static final EventId PrefillingSource_Delete = new EventId(260003, "PrefillingSource_Delete");
public static final EventId PrefillingSource_Generate = new EventId(260004, "PrefillingSource_Generate");
public static final EventId TenantConfiguration_Query = new EventId(270000, "TenantConfiguration_Query");
public static final EventId TenantConfiguration_Lookup = new EventId(270001, "TenantConfiguration_Lookup");
public static final EventId TenantConfiguration_Persist = new EventId(270002, "TenantConfiguration_Persist");
public static final EventId TenantConfiguration_Delete = new EventId(270003, "TenantConfiguration_Delete");
}

View File

@ -174,4 +174,14 @@ public class ErrorThesaurusProperties {
public void setTenantTampering(ErrorDescription tenantTampering) {
this.tenantTampering = tenantTampering;
}
private ErrorDescription tenantConfigurationTypeCanNotChange;
public ErrorDescription getTenantConfigurationTypeCanNotChange() {
return tenantConfigurationTypeCanNotChange;
}
public void setTenantConfigurationTypeCanNotChange(ErrorDescription tenantConfigurationTypeCanNotChange) {
this.tenantConfigurationTypeCanNotChange = tenantConfigurationTypeCanNotChange;
}
}

View File

@ -1,14 +1,12 @@
package eu.eudat.model.builder.deposit;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.scope.tenant.TenantScope;
import eu.eudat.commons.types.deposit.DepositSourceEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.deposit.DepositSource;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import eu.eudat.service.encryption.EncryptionService;
import eu.eudat.service.tenant.TenantProperties;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
@ -25,11 +23,16 @@ import java.util.*;
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DepositSourceBuilder extends BaseBuilder<DepositSource, DepositSourceEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private boolean encrypted;
private final EncryptionService encryptionService;
private final TenantProperties tenantProperties;
@Autowired
public DepositSourceBuilder(
ConventionService conventionService) {
ConventionService conventionService, EncryptionService encryptionService, TenantProperties tenantProperties) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DepositSourceBuilder.class)));
this.encryptionService = encryptionService;
this.tenantProperties = tenantProperties;
}
public DepositSourceBuilder authorize(EnumSet<AuthorizationFlags> values) {
@ -37,6 +40,11 @@ public class DepositSourceBuilder extends BaseBuilder<DepositSource, DepositSour
return this;
}
public DepositSourceBuilder encrypted(boolean encrypted) {
this.encrypted = encrypted;
return this;
}
@Override
public List<DepositSource> build(FieldSet fields, List<DepositSourceEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
@ -51,7 +59,17 @@ public class DepositSourceBuilder extends BaseBuilder<DepositSource, DepositSour
if (fields.hasField(this.asIndexer(DepositSource._url))) m.setUrl(d.getUrl());
if (fields.hasField(this.asIndexer(DepositSource._issuerUrl))) m.setIssuerUrl(d.getIssuerUrl());
if (fields.hasField(this.asIndexer(DepositSource._clientId))) m.setClientId(d.getClientId());
if (fields.hasField(this.asIndexer(DepositSource._clientSecret))) m.setClientSecret(d.getClientSecret());
if (fields.hasField(this.asIndexer(DepositSource._clientSecret))) {
if (encrypted) {
try {
if (!this.conventionService.isNullOrEmpty(d.getClientSecret())) m.setClientSecret(this.encryptionService.decryptAES(d.getClientSecret(), tenantProperties.getConfigEncryptionAesKey(), tenantProperties.getConfigEncryptionAesIv()));
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
m.setClientSecret(d.getClientSecret());
}
}
if (fields.hasField(this.asIndexer(DepositSource._scope))) m.setScope(d.getScope());
if (fields.hasField(this.asIndexer(DepositSource._pdfTransformerId))) m.setPdfTransformerId(d.getPdfTransformerId());
if (fields.hasField(this.asIndexer(DepositSource._rdaTransformerId))) m.setRdaTransformerId(d.getRdaTransformerId());

View File

@ -5,6 +5,8 @@ import eu.eudat.commons.types.filetransformer.FileTransformerSourceEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.filetransformer.FileTransformerSource;
import eu.eudat.service.encryption.EncryptionService;
import eu.eudat.service.tenant.TenantProperties;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
@ -15,17 +17,27 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class FileTransformerSourceBuilder extends BaseBuilder<FileTransformerSource, FileTransformerSourceEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final EncryptionService encryptionService;
private final TenantProperties tenantProperties;
private boolean encrypted;
@Autowired
public FileTransformerSourceBuilder(
ConventionService conventionService) {
ConventionService conventionService, EncryptionService encryptionService, TenantProperties tenantProperties) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(FileTransformerSourceBuilder.class)));
this.encryptionService = encryptionService;
this.tenantProperties = tenantProperties;
}
public FileTransformerSourceBuilder authorize(EnumSet<AuthorizationFlags> values) {
@ -33,6 +45,11 @@ public class FileTransformerSourceBuilder extends BaseBuilder<FileTransformerSou
return this;
}
public FileTransformerSourceBuilder encrypted(boolean encrypted) {
this.encrypted = encrypted;
return this;
}
@Override
public List<FileTransformerSource> build(FieldSet fields, List<FileTransformerSourceEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
@ -47,7 +64,17 @@ public class FileTransformerSourceBuilder extends BaseBuilder<FileTransformerSou
if (fields.hasField(this.asIndexer(FileTransformerSource._url))) m.setUrl(d.getUrl());
if (fields.hasField(this.asIndexer(FileTransformerSource._issuerUrl))) m.setIssuerUrl(d.getIssuerUrl());
if (fields.hasField(this.asIndexer(FileTransformerSource._clientId))) m.setClientId(d.getClientId());
if (fields.hasField(this.asIndexer(FileTransformerSource._clientSecret))) m.setClientSecret(d.getClientSecret());
if (fields.hasField(this.asIndexer(FileTransformerSource._clientSecret))){
if (encrypted) {
try {
if (!this.conventionService.isNullOrEmpty(d.getClientSecret())) m.setClientSecret(this.encryptionService.decryptAES(d.getClientSecret(), tenantProperties.getConfigEncryptionAesKey(), tenantProperties.getConfigEncryptionAesIv()));
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
m.setClientSecret(d.getClientSecret());
}
}
if (fields.hasField(this.asIndexer(FileTransformerSource._scope))) m.setScope(d.getScope());
models.add(m);
}

View File

@ -51,7 +51,7 @@ public class DepositTenantConfigurationBuilder extends BaseBuilder<DepositTenant
for (DepositTenantConfigurationEntity d : data) {
DepositTenantConfiguration m = new DepositTenantConfiguration();
if (!sourcesFields.isEmpty() && d.getSources() != null){
m.setSources(this.builderFactory.builder(DepositSourceBuilder.class).authorize(this.authorize).build(sourcesFields, d.getSources()));
m.setSources(this.builderFactory.builder(DepositSourceBuilder.class).encrypted(true).authorize(this.authorize).build(sourcesFields, d.getSources()));
}
models.add(m);
}

View File

@ -51,7 +51,7 @@ public class FileTransformerTenantConfigurationBuilder extends BaseBuilder<FileT
for (FileTransformerTenantConfigurationEntity d : data) {
FileTransformerTenantConfiguration m = new FileTransformerTenantConfiguration();
if (!sourcesFields.isEmpty() && d.getSources() != null){
m.setSources(this.builderFactory.builder(FileTransformerSourceBuilder.class).authorize(this.authorize).build(sourcesFields, d.getSources()));
m.setSources(this.builderFactory.builder(FileTransformerSourceBuilder.class).encrypted(true).authorize(this.authorize).build(sourcesFields, d.getSources()));
}
models.add(m);
}

View File

@ -36,7 +36,7 @@ public class TenantConfigurationBuilder extends BaseBuilder<TenantConfiguration,
@Autowired
public TenantConfigurationBuilder(
ConventionService conventionService,
BuilderFactory builderFactory, QueryFactory queryFactory, XmlHandlingService xmlHandlingService, TenantScope tenantScope, JsonHandlingService jsonHandlingService, BuilderFactory builderFactory1) {
TenantScope tenantScope, JsonHandlingService jsonHandlingService, BuilderFactory builderFactory1) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantConfigurationBuilder.class)));
this.tenantScope = tenantScope;
this.jsonHandlingService = jsonHandlingService;

View File

@ -1,8 +1,9 @@
package eu.eudat.model.deleter;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.TenantEntity;
import eu.eudat.data.TenantEntityManager;
import eu.eudat.data.*;
import eu.eudat.query.DescriptionTagQuery;
import eu.eudat.query.TenantConfigurationQuery;
import eu.eudat.query.TenantQuery;
import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.deleter.DeleterFactory;
@ -20,6 +21,7 @@ import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ -64,6 +66,14 @@ public class TenantDeleter implements Deleter {
if (data == null || data.isEmpty())
return;
List<UUID> ids = data.stream().map(TenantEntity::getId).distinct().collect(Collectors.toList());
{
logger.debug("checking related - {}", TenantConfigurationEntity.class.getSimpleName());
List<TenantConfigurationEntity> items = this.queryFactory.query(TenantConfigurationQuery.class).tenantIds(ids).collect();
TenantConfigurationDeleter deleter = this.deleterFactory.deleter(TenantConfigurationDeleter.class);
deleter.delete(items);
}
Instant now = Instant.now();
for (TenantEntity item : data) {

View File

@ -6,7 +6,6 @@ import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.TenantConfigurationType;
import eu.eudat.data.TenantConfigurationEntity;
import eu.eudat.model.tenantconfiguration.TenantConfiguration;
import eu.eudat.query.utils.QueryUtilsService;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.data.query.QueryContext;
@ -25,16 +24,15 @@ import java.util.*;
public class TenantConfigurationQuery extends QueryBase<TenantConfigurationEntity> {
private Collection<UUID> ids;
private Collection<UUID> tenantIds;
private Boolean tenantIsSet;
private Collection<IsActive> isActives;
private Collection<TenantConfigurationType> types;
private Collection<UUID> excludedIds;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final QueryUtilsService queryUtilsService;
public TenantConfigurationQuery(QueryUtilsService queryUtilsService) {
this.queryUtilsService = queryUtilsService;
public TenantConfigurationQuery() {
}
public TenantConfigurationQuery ids(UUID value) {
@ -52,6 +50,26 @@ public class TenantConfigurationQuery extends QueryBase<TenantConfigurationEntit
return this;
}
public TenantConfigurationQuery tenantIds(UUID value) {
this.tenantIds = List.of(value);
return this;
}
public TenantConfigurationQuery tenantIds(UUID... value) {
this.tenantIds = Arrays.asList(value);
return this;
}
public TenantConfigurationQuery tenantIds(Collection<UUID> values) {
this.tenantIds = values;
return this;
}
public TenantConfigurationQuery tenantIsSet(Boolean values) {
this.tenantIsSet = values;
return this;
}
public TenantConfigurationQuery isActive(IsActive value) {
this.isActives = List.of(value);
return this;
@ -104,7 +122,7 @@ public class TenantConfigurationQuery extends QueryBase<TenantConfigurationEntit
@Override
protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) ||this.isEmpty(this.isActives)||this.isEmpty(this.types);
return this.isEmpty(this.ids) ||this.isEmpty(this.isActives) ||this.isEmpty(this.types) || this.isEmpty(this.tenantIds);
}
@Override
@ -120,7 +138,12 @@ public class TenantConfigurationQuery extends QueryBase<TenantConfigurationEntit
for (UUID item : this.ids) inClause.value(item);
predicates.add(inClause);
}
if (this.tenantIds != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._tenantId));
for (UUID item : this.tenantIds) inClause.value(item);
predicates.add(inClause);
}
if (this.isActives != null) {
CriteriaBuilder.In<IsActive> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._isActive));
@ -128,6 +151,12 @@ public class TenantConfigurationQuery extends QueryBase<TenantConfigurationEntit
predicates.add(inClause);
}
if (this.tenantIsSet != null) {
if (this.tenantIsSet) predicates.add(queryContext.CriteriaBuilder.isNotNull(queryContext.Root.get(TenantConfigurationEntity._tenantId)));
else predicates.add(queryContext.CriteriaBuilder.isNull(queryContext.Root.get(TenantConfigurationEntity._tenantId)));
}
if (this.types != null) {
CriteriaBuilder.In<TenantConfigurationType> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._type));

View File

@ -21,6 +21,46 @@ public class EntityDoiLookup extends Lookup {
private List<String> dois;
public List<IsActive> getIsActive() {
return isActive;
}
public void setIsActive(List<IsActive> isActive) {
this.isActive = isActive;
}
public List<EntityType> getTypes() {
return types;
}
public void setTypes(List<EntityType> types) {
this.types = types;
}
public List<UUID> getIds() {
return ids;
}
public void setIds(List<UUID> ids) {
this.ids = ids;
}
public List<UUID> getExcludedIds() {
return excludedIds;
}
public void setExcludedIds(List<UUID> excludedIds) {
this.excludedIds = excludedIds;
}
public List<String> getDois() {
return dois;
}
public void setDois(List<String> dois) {
this.dois = dois;
}
public EntityDoiQuery enrich(QueryFactory queryFactory) {
EntityDoiQuery query = queryFactory.query(EntityDoiQuery.class);
if (this.isActive != null)

View File

@ -14,7 +14,9 @@ public class TenantConfigurationLookup extends Lookup {
private List<IsActive> isActive;
private List<TenantConfigurationType> types;
private List<UUID> ids;
private List<UUID> tenantIds;
private List<UUID> excludedIds;
private Boolean tenantIsSet;
public List<IsActive> getIsActive() {
@ -49,12 +51,30 @@ public class TenantConfigurationLookup extends Lookup {
this.types = types;
}
public List<UUID> getTenantIds() {
return tenantIds;
}
public void setTenantIds(List<UUID> tenantIds) {
this.tenantIds = tenantIds;
}
public Boolean getTenantIsSet() {
return tenantIsSet;
}
public void setTenantIsSet(Boolean tenantIsSet) {
this.tenantIsSet = tenantIsSet;
}
public TenantConfigurationQuery enrich(QueryFactory queryFactory) {
TenantConfigurationQuery query = queryFactory.query(TenantConfigurationQuery.class);
if (this.types != null) query.types(this.types);
if (this.isActive != null) query.isActive(this.isActive);
if (this.ids != null) query.ids(this.ids);
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
if (this.tenantIds != null) query.tenantIds(this.tenantIds);
if (this.tenantIsSet != null) query.tenantIsSet(this.tenantIsSet);
this.enrichCommon(query);

View File

@ -25,6 +25,5 @@ public interface TenantService {
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, InvalidApplicationException;
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
}

View File

@ -51,7 +51,6 @@ 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;
@ -190,28 +189,7 @@ public class TenantServiceImpl implements TenantService {
}
@Override
public Tenant decryptTenant(Tenant model) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, InvalidApplicationException {
// if (model.getConfig() != null && model.getConfig().getDeposit() != null && model.getConfig().getDeposit().getSources() != null) {
// for (TenantSource source : model.getConfig().getDeposit().getSources().stream().toList()) {
// source.setClientSecret(this.encryptionService.decryptAES(source.getClientSecret(), properties.getConfigEncryptionAesKey(), properties.getConfigEncryptionAesIv()));
// }
// }
// if (model.getConfig() != null && model.getConfig().getFileTransformers() != null && model.getConfig().getFileTransformers().getSources() != null) {
// for (TenantSource source : model.getConfig().getFileTransformers().getSources().stream().toList()) {
// source.setClientSecret(this.encryptionService.decryptAES(source.getClientSecret(), properties.getConfigEncryptionAesKey(), properties.getConfigEncryptionAesIv()));
// }
// }
TenantEntity data = this.entityManager.find(TenantEntity.class, model.getId());
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Tenant.class.getSimpleName()}, LocaleContextHolder.getLocale()));
TenantTouchedIntegrationEvent tenantTouchedIntegrationEvent = new TenantTouchedIntegrationEvent();
tenantTouchedIntegrationEvent.setId(data.getId());
tenantTouchedIntegrationEvent.setCode(data.getCode());
this.tenantTouchedIntegrationEventHandler.handle(tenantTouchedIntegrationEvent);
return model;
}
@Override
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {

View File

@ -0,0 +1,27 @@
package eu.eudat.service.tenantconfiguration;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.model.persist.tenantconfiguration.TenantConfigurationPersist;
import eu.eudat.model.tenantconfiguration.TenantConfiguration;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyForbiddenException;
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.management.InvalidApplicationException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;
public interface TenantConfigurationService {
TenantConfiguration persist(TenantConfigurationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException;
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
}

View File

@ -0,0 +1,248 @@
package eu.eudat.service.tenantconfiguration;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.StorageType;
import eu.eudat.commons.enums.TenantConfigurationType;
import eu.eudat.commons.types.deposit.DepositSourceEntity;
import eu.eudat.commons.types.filetransformer.FileTransformerSourceEntity;
import eu.eudat.commons.types.tenantconfiguration.*;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.TenantConfigurationEntity;
import eu.eudat.data.TenantEntityManager;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.StorageFile;
import eu.eudat.model.builder.tenantconfiguration.TenantConfigurationBuilder;
import eu.eudat.model.deleter.TenantConfigurationDeleter;
import eu.eudat.model.persist.deposit.DepositSourcePersist;
import eu.eudat.model.persist.filetransformer.FileTransformerSourcePersist;
import eu.eudat.model.persist.tenantconfiguration.*;
import eu.eudat.model.tenantconfiguration.TenantConfiguration;
import eu.eudat.service.encryption.EncryptionService;
import eu.eudat.service.storage.StorageFileService;
import eu.eudat.service.tenant.TenantProperties;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
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.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
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;
@Service
public class TenantConfigurationServiceImpl implements TenantConfigurationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantConfigurationServiceImpl.class));
private final TenantEntityManager entityManager;
private final AuthorizationService authorizationService;
private final DeleterFactory deleterFactory;
private final BuilderFactory builderFactory;
private final ConventionService conventionService;
private final ErrorThesaurusProperties errors;
private final MessageSource messageSource;
private final JsonHandlingService jsonHandlingService;
private final EncryptionService encryptionService;
private final TenantProperties tenantProperties;
private final StorageFileService storageFileService;
@Autowired
public TenantConfigurationServiceImpl(
TenantEntityManager entityManager,
AuthorizationService authorizationService,
DeleterFactory deleterFactory,
BuilderFactory builderFactory,
ConventionService conventionService,
ErrorThesaurusProperties errors,
MessageSource messageSource, JsonHandlingService jsonHandlingService, EncryptionService encryptionService, TenantProperties tenantProperties, StorageFileService storageFileService) {
this.entityManager = entityManager;
this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory;
this.builderFactory = builderFactory;
this.conventionService = conventionService;
this.errors = errors;
this.messageSource = messageSource;
this.jsonHandlingService = jsonHandlingService;
this.encryptionService = encryptionService;
this.tenantProperties = tenantProperties;
this.storageFileService = storageFileService;
}
public TenantConfiguration persist(TenantConfigurationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
logger.debug(new MapLogEntry("persisting data TenantConfiguration").And("model", model).And("fields", fields));
this.authorizationService.authorizeForce(Permission.EditTenantConfiguration);
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
TenantConfigurationEntity data;
if (isUpdate) {
data = this.entityManager.find(TenantConfigurationEntity.class, model.getId());
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), TenantConfiguration.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.getType().equals(model.getType())) throw new MyValidationException(this.errors.getTenantConfigurationTypeCanNotChange().getCode(), this.errors.getTenantConfigurationTypeCanNotChange().getMessage());
} else {
data = new TenantConfigurationEntity();
data.setId(UUID.randomUUID());
data.setIsActive(IsActive.Active);
data.setCreatedAt(Instant.now());
data.setType(model.getType());
}
switch (data.getType()){
case CssColors -> data.setValue(this.jsonHandlingService.toJson(this.buildCssColorsTenantConfigurationEntity(model.getCssColors())));
case DefaultUserLocale -> data.setValue(this.jsonHandlingService.toJson(this.buildDefaultUserLocaleTenantConfigurationEntity(model.getDefaultUserLocale())));
case DepositPlugins -> data.setValue(this.jsonHandlingService.toJson(this.buildDepositTenantConfigurationEntity(model.getDepositPlugins())));
case FileTransformerPlugins -> data.setValue(this.jsonHandlingService.toJson(this.buildFileTransformerTenantConfigurationEntity(model.getFileTransformerPlugins())));
case Logo -> {
LogoTenantConfigurationEntity oldValue = this.conventionService.isNullOrEmpty(data.getValue()) ? null : this.jsonHandlingService.fromJsonSafe(LogoTenantConfigurationEntity.class, data.getValue());
data.setValue(this.jsonHandlingService.toJson(this.buildLogoTenantConfigurationEntity(model.getLogo(), oldValue)));
}
default -> throw new InternalError("unknown type: " + data.getType());
}
data.setUpdatedAt(Instant.now());
if (isUpdate)
this.entityManager.merge(data);
else
this.entityManager.persist(data);
this.entityManager.flush();
return this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, TenantConfiguration._id), data);
}
private @NotNull DepositTenantConfigurationEntity buildDepositTenantConfigurationEntity(DepositTenantConfigurationPersist persist) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
DepositTenantConfigurationEntity data = new DepositTenantConfigurationEntity();
if (persist == null || this.conventionService.isListNullOrEmpty(persist.getSources())) return data;
data.setSources(new ArrayList<>());
for (DepositSourcePersist depositSourcePersist : persist.getSources()) {
data.getSources().add(this.buildDepositSourceEntity(depositSourcePersist));
}
return data;
}
private DepositSourceEntity buildDepositSourceEntity(DepositSourcePersist depositSourcePersist) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
DepositSourceEntity depositSourceEntity = new DepositSourceEntity();
depositSourceEntity.setClientId(depositSourcePersist.getClientId());
if (!this.conventionService.isNullOrEmpty(depositSourcePersist.getClientSecret())) depositSourceEntity.setClientSecret(this.encryptionService.encryptAES(depositSourcePersist.getClientSecret(), this.tenantProperties.getConfigEncryptionAesKey(), this.tenantProperties.getConfigEncryptionAesIv()));
depositSourceEntity.setRepositoryId(depositSourcePersist.getRepositoryId());
depositSourceEntity.setUrl(depositSourcePersist.getUrl());
depositSourceEntity.setIssuerUrl(depositSourcePersist.getIssuerUrl());
depositSourceEntity.setScope(depositSourcePersist.getScope());
depositSourceEntity.setPdfTransformerId(depositSourcePersist.getPdfTransformerId());
depositSourceEntity.setRdaTransformerId(depositSourcePersist.getRdaTransformerId());
return depositSourceEntity;
}
private @NotNull FileTransformerTenantConfigurationEntity buildFileTransformerTenantConfigurationEntity(FileTransformerTenantConfigurationPersist persist) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
FileTransformerTenantConfigurationEntity data = new FileTransformerTenantConfigurationEntity();
if (persist == null || this.conventionService.isListNullOrEmpty(persist.getSources())) return data;
data.setSources(new ArrayList<>());
for (FileTransformerSourcePersist depositSourcePersist : persist.getSources()) {
data.getSources().add(this.buildFileTransformerSourceEntity(depositSourcePersist));
}
return data;
}
private FileTransformerSourceEntity buildFileTransformerSourceEntity(FileTransformerSourcePersist depositSourcePersist) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
FileTransformerSourceEntity depositSourceEntity = new FileTransformerSourceEntity();
depositSourceEntity.setClientId(depositSourcePersist.getClientId());
if (!this.conventionService.isNullOrEmpty(depositSourcePersist.getClientSecret())) depositSourceEntity.setClientSecret(this.encryptionService.encryptAES(depositSourcePersist.getClientSecret(), this.tenantProperties.getConfigEncryptionAesKey(), this.tenantProperties.getConfigEncryptionAesIv()));
depositSourceEntity.setUrl(depositSourcePersist.getUrl());
depositSourceEntity.setIssuerUrl(depositSourcePersist.getIssuerUrl());
depositSourceEntity.setScope(depositSourcePersist.getScope());
depositSourceEntity.setTransformerId(depositSourcePersist.getTransformerId());
return depositSourceEntity;
}
private @NotNull CssColorsTenantConfigurationEntity buildCssColorsTenantConfigurationEntity(CssColorsTenantConfigurationPersist persist){
CssColorsTenantConfigurationEntity data = new CssColorsTenantConfigurationEntity();
if (persist == null) return data;
data.setPrimaryColor(persist.getPrimaryColor());
data.setPrimaryColor2(persist.getPrimaryColor2());
data.setPrimaryColor3(persist.getPrimaryColor3());
data.setSecondaryColor(persist.getSecondaryColor());
return data;
}
private @NotNull DefaultUserLocaleTenantConfigurationEntity buildDefaultUserLocaleTenantConfigurationEntity(DefaultUserLocaleTenantConfigurationPersist persist){
DefaultUserLocaleTenantConfigurationEntity data = new DefaultUserLocaleTenantConfigurationEntity();
if (persist == null) return data;
data.setCulture(persist.getCulture());
data.setLanguage(persist.getLanguage());
data.setTimezone(persist.getTimezone());
return data;
}
private @NotNull LogoTenantConfigurationEntity buildLogoTenantConfigurationEntity(LogoTenantConfigurationPersist persist, LogoTenantConfigurationEntity oldValue) throws InvalidApplicationException {
LogoTenantConfigurationEntity data = new LogoTenantConfigurationEntity();
if (persist == null) return data;
data.setStorageFileId(persist.getStorageFileId());
UUID existingFileId = oldValue != null ? oldValue.getStorageFileId() : null;
if (persist.getStorageFileId() != null){
if (!persist.getStorageFileId().equals(existingFileId)) {
StorageFile storageFile = this.storageFileService.copyToStorage(persist.getStorageFileId(), StorageType.Main, true, new BaseFieldSet().ensure(StorageFile._id));
this.storageFileService.updatePurgeAt(storageFile.getId(), null);
if (existingFileId != null) this.storageFileService.updatePurgeAt(existingFileId, Instant.now().minusSeconds(60));
data.setStorageFileId(storageFile.getId());
} else {
data.setStorageFileId(existingFileId);
}
} else {
if (existingFileId != null) this.storageFileService.updatePurgeAt(existingFileId, Instant.now().minusSeconds(60));
data.setStorageFileId(null);
}
return data;
}
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug("deleting dataset: {}", id);
this.authorizationService.authorizeForce(Permission.DeleteTenantConfiguration);
TenantConfigurationEntity data = this.entityManager.find(TenantConfigurationEntity.class, id);
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, TenantConfiguration.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (data.getType().equals(TenantConfigurationType.Logo)){
LogoTenantConfigurationEntity oldValue = this.conventionService.isNullOrEmpty(data.getValue()) ? null : this.jsonHandlingService.fromJsonSafe(LogoTenantConfigurationEntity.class, data.getValue());
if (oldValue != null && oldValue.getStorageFileId() != null) this.storageFileService.updatePurgeAt(oldValue.getStorageFileId(), Instant.now().minusSeconds(60));
}
this.deleterFactory.deleter(TenantConfigurationDeleter.class).deleteAndSaveByIds(List.of(id));
}
}

View File

@ -37,7 +37,7 @@ import java.util.*;
@RequestMapping(path = "api/entity-doi")
public class EntityDoiController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeController.class));
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(EntityDoiController.class));
private final BuilderFactory builderFactory;

View File

@ -0,0 +1,135 @@
package eu.eudat.controllers;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.data.TenantConfigurationEntity;
import eu.eudat.model.DescriptionTemplateType;
import eu.eudat.model.builder.tenantconfiguration.TenantConfigurationBuilder;
import eu.eudat.model.censorship.tenantconfiguration.TenantConfigurationCensor;
import eu.eudat.model.persist.tenantconfiguration.TenantConfigurationPersist;
import eu.eudat.model.result.QueryResult;
import eu.eudat.model.tenantconfiguration.TenantConfiguration;
import eu.eudat.query.TenantConfigurationQuery;
import eu.eudat.query.lookup.TenantConfigurationLookup;
import eu.eudat.service.tenantconfiguration.TenantConfigurationService;
import gr.cite.tools.auditing.AuditService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.ValidationFilterAnnotation;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.management.InvalidApplicationException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.*;
@RestController
@RequestMapping(path = "api/tenant-configuration")
public class TenantConfigurationController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantConfigurationController.class));
private final BuilderFactory builderFactory;
private final AuditService auditService;
private final TenantConfigurationService tenantConfigurationService;
private final CensorFactory censorFactory;
private final QueryFactory queryFactory;
private final MessageSource messageSource;
public TenantConfigurationController(
BuilderFactory builderFactory,
AuditService auditService,
TenantConfigurationService tenantConfigurationService, CensorFactory censorFactory,
QueryFactory queryFactory,
MessageSource messageSource) {
this.builderFactory = builderFactory;
this.auditService = auditService;
this.tenantConfigurationService = tenantConfigurationService;
this.censorFactory = censorFactory;
this.queryFactory = queryFactory;
this.messageSource = messageSource;
}
@PostMapping("query")
public QueryResult<TenantConfiguration> Query(@RequestBody TenantConfigurationLookup lookup) throws MyApplicationException, MyForbiddenException {
logger.debug("querying {}", TenantConfiguration.class.getSimpleName());
this.censorFactory.censor(TenantConfigurationCensor.class).censor(lookup.getProject(), null);
TenantConfigurationQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission);
List<TenantConfigurationEntity> data = query.collectAs(lookup.getProject());
List<TenantConfiguration> models = this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data);
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
this.auditService.track(AuditableAction.TenantConfiguration_Query, "lookup", lookup);
return new QueryResult<>(models, count);
}
@GetMapping("{id}")
public TenantConfiguration Get(@PathVariable("id") UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("retrieving" + TenantConfiguration.class.getSimpleName()).And("id", id).And("fields", fieldSet));
this.censorFactory.censor(TenantConfigurationCensor.class).censor(fieldSet, null);
TenantConfigurationQuery query = this.queryFactory.query(TenantConfigurationQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id);
TenantConfiguration model = this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet));
if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, TenantConfiguration.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.TenantConfiguration_Lookup, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
return model;
}
@PostMapping("persist")
@Transactional
@ValidationFilterAnnotation(validator = TenantConfigurationPersist.TenantConfigurationPersistValidator.ValidatorName, argumentName = "model")
public TenantConfiguration Persist(@RequestBody TenantConfigurationPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
logger.debug(new MapLogEntry("persisting" + DescriptionTemplateType.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
TenantConfiguration persisted = this.tenantConfigurationService.persist(model, fieldSet);
this.auditService.track(AuditableAction.TenantConfiguration_Persist, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
return persisted;
}
@DeleteMapping("{id}")
@Transactional
public void Delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug(new MapLogEntry("retrieving" + TenantConfiguration.class.getSimpleName()).And("id", id));
this.tenantConfigurationService.deleteAndSave(id);
this.auditService.track(AuditableAction.TenantConfiguration_Delete, "id", id);
}
}

View File

@ -86,9 +86,6 @@ public class TenantController {
List<TenantEntity> data = query.collectAs(lookup.getProject());
List<Tenant> models = this.builderFactory.builder(TenantBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).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);
@ -107,8 +104,6 @@ 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)

View File

@ -59,3 +59,7 @@ error-thesaurus:
tenant-tampering:
code: 123
message: Tenant tampering
tenant-configuration-type-can-not-change:
code: 124
message: Tenant configuration type can not change

View File

@ -126,9 +126,9 @@ export class DescriptionService {
//
// tslint:disable-next-line: member-ordering
singleAutocompleteConfiguration: SingleAutoCompleteConfiguration = {
initialItems: (data?: any) => this.query(this.buildAutocompleteLookup()).pipe(map(x => x.items)),
filterFn: (searchQuery: string, data?: any) => this.query(this.buildAutocompleteLookup(searchQuery)).pipe(map(x => x.items)),
getSelectedItem: (selectedItem: any) => this.query(this.buildAutocompleteLookup(null, null, [selectedItem])).pipe(map(x => x.items[0])),
initialItems: (data?: any) => this.query(this.buildAutocompleteLookup([IsActive.Active])).pipe(map(x => x.items)),
filterFn: (searchQuery: string, data?: any) => this.query(this.buildAutocompleteLookup([IsActive.Active], searchQuery)).pipe(map(x => x.items)),
getSelectedItem: (selectedItem: any) => this.query(this.buildAutocompleteLookup([IsActive.Active, IsActive.Inactive], null, null, [selectedItem])).pipe(map(x => x.items[0])),
displayFn: (item: Description) => item.label,
titleFn: (item: Description) => item.label,
valueAssign: (item: Description) => item.id,
@ -136,20 +136,20 @@ export class DescriptionService {
// tslint:disable-next-line: member-ordering
multipleAutocompleteConfiguration: MultipleAutoCompleteConfiguration = {
initialItems: (excludedItems: any[], data?: any) => this.query(this.buildAutocompleteLookup(null, excludedItems ? excludedItems : null)).pipe(map(x => x.items)),
filterFn: (searchQuery: string, excludedItems: any[]) => this.query(this.buildAutocompleteLookup(searchQuery, excludedItems)).pipe(map(x => x.items)),
getSelectedItems: (selectedItems: any[]) => this.query(this.buildAutocompleteLookup(null, null, selectedItems)).pipe(map(x => x.items)),
initialItems: (excludedItems: any[], data?: any) => this.query(this.buildAutocompleteLookup([IsActive.Active], null, excludedItems ? excludedItems : null)).pipe(map(x => x.items)),
filterFn: (searchQuery: string, excludedItems: any[]) => this.query(this.buildAutocompleteLookup([IsActive.Active], searchQuery, excludedItems)).pipe(map(x => x.items)),
getSelectedItems: (selectedItems: any[]) => this.query(this.buildAutocompleteLookup([IsActive.Active, IsActive.Inactive], null, null, selectedItems)).pipe(map(x => x.items)),
displayFn: (item: Description) => item.label,
titleFn: (item: Description) => item.label,
valueAssign: (item: Description) => item.id,
};
public buildAutocompleteLookup(like?: string, excludedIds?: Guid[], ids?: Guid[]): DescriptionLookup {
public buildAutocompleteLookup(isActive: IsActive[], like?: string, excludedIds?: Guid[], ids?: Guid[]): DescriptionLookup {
const lookup: DescriptionLookup = new DescriptionLookup();
lookup.page = { size: 100, offset: 0 };
if (excludedIds && excludedIds.length > 0) { lookup.excludedIds = excludedIds; }
if (ids && ids.length > 0) { lookup.ids = ids; }
lookup.isActive = [IsActive.Active];
lookup.isActive = isActive;
lookup.project = {
fields: [
nameof<Description>(x => x.id),

View File

@ -208,9 +208,9 @@ export class DmpService {
//
// tslint:disable-next-line: member-ordering
singleAutocompleteConfiguration: SingleAutoCompleteConfiguration = {
initialItems: (data?: any) => this.query(this.buildAutocompleteLookup()).pipe(map(x => x.items)),
filterFn: (searchQuery: string, data?: any) => this.query(this.buildAutocompleteLookup(searchQuery)).pipe(map(x => x.items)),
getSelectedItem: (selectedItem: any) => this.query(this.buildAutocompleteLookup(null, null, [selectedItem])).pipe(map(x => x.items[0])),
initialItems: (data?: any) => this.query(this.buildAutocompleteLookup([IsActive.Active])).pipe(map(x => x.items)),
filterFn: (searchQuery: string, data?: any) => this.query(this.buildAutocompleteLookup([IsActive.Active], searchQuery)).pipe(map(x => x.items)),
getSelectedItem: (selectedItem: any) => this.query(this.buildAutocompleteLookup([IsActive.Active, IsActive.Inactive], null, null, [selectedItem])).pipe(map(x => x.items[0])),
displayFn: (item: Dmp) => item.label,
titleFn: (item: Dmp) => item.label,
valueAssign: (item: Dmp) => item.id,
@ -218,20 +218,20 @@ export class DmpService {
// tslint:disable-next-line: member-ordering
multipleAutocompleteConfiguration: MultipleAutoCompleteConfiguration = {
initialItems: (excludedItems: any[], data?: any) => this.query(this.buildAutocompleteLookup(null, excludedItems ? excludedItems : null)).pipe(map(x => x.items)),
filterFn: (searchQuery: string, excludedItems: any[]) => this.query(this.buildAutocompleteLookup(searchQuery, excludedItems)).pipe(map(x => x.items)),
getSelectedItems: (selectedItems: any[]) => this.query(this.buildAutocompleteLookup(null, null, selectedItems)).pipe(map(x => x.items)),
initialItems: (excludedItems: any[], data?: any) => this.query(this.buildAutocompleteLookup([IsActive.Active], null, excludedItems ? excludedItems : null)).pipe(map(x => x.items)),
filterFn: (searchQuery: string, excludedItems: any[]) => this.query(this.buildAutocompleteLookup([IsActive.Active],searchQuery, excludedItems)).pipe(map(x => x.items)),
getSelectedItems: (selectedItems: any[]) => this.query(this.buildAutocompleteLookup([IsActive.Active, IsActive.Inactive], null, null, selectedItems)).pipe(map(x => x.items)),
displayFn: (item: Dmp) => item.label,
titleFn: (item: Dmp) => item.label,
valueAssign: (item: Dmp) => item.id,
};
public buildAutocompleteLookup(like?: string, excludedIds?: Guid[], ids?: Guid[], statuses?: DmpStatus[], dmpDescriptionTemplateSubQuery?: DmpDescriptionTemplateLookup): DmpLookup {
public buildAutocompleteLookup(isActive: IsActive[], like?: string, excludedIds?: Guid[], ids?: Guid[], statuses?: DmpStatus[], dmpDescriptionTemplateSubQuery?: DmpDescriptionTemplateLookup): DmpLookup {
const lookup: DmpLookup = new DmpLookup();
lookup.page = { size: 100, offset: 0 };
if (excludedIds && excludedIds.length > 0) { lookup.excludedIds = excludedIds; }
if (ids && ids.length > 0) { lookup.ids = ids; }
lookup.isActive = [IsActive.Active];
lookup.isActive = isActive;
lookup.statuses = statuses;
lookup.project = {
fields: [

View File

@ -30,6 +30,8 @@ export interface MultipleAutoCompleteConfiguration {
valueAssign?: (selectedItem: any) => any;
// Callback to provide equals function betwen the values
uniqueAssign?: (selectedItem: any) => any;
// Get selected items. Used when valueAssign is used so the full object can be retrieved for presentation.
canRemoveItem?: (selectedItem: any) => { canRemove: boolean, message: string };
// Property formating template
optionTemplate?: TemplateRef<any>;
// Property formatting component
@ -39,8 +41,9 @@ export interface MultipleAutoCompleteConfiguration {
// Display icon that opens popup
popupItemActionIcon?: string;
autoSelectFirstOptionOnBlur?: boolean;
appendClassToItem?: {class: string, applyFunc: (item:any) => boolean}[];
appendClassToItem?: { class: string, applyFunc: (item: any) => boolean }[];
}

View File

@ -4,14 +4,14 @@
<div class="col-12">
<mat-chip-grid #chipList ngDefaultControl class="chip-list">
<ng-container *ngIf="value as values;">
<mat-chip-row *ngFor="let value of values" [disabled]="disabled" [selectable]="selectable" [removable]="removable" [ngClass]="computeClass(value)" class="chip-row">
<mat-chip-row *ngFor="let value of values" [disabled]="disabled" [selectable]="selectable" [removable]="true" [ngClass]="computeClass(value)" class="chip-row">
<ng-container *ngIf="getSelectedItem(value) as selectedItem;">
<ng-template #cellTemplate *ngIf="_selectedValueTemplate(selectedItem)" [ngTemplateOutlet]="_selectedValueTemplate(selectedItem)" [ngTemplateOutletContext]="{
item: selectedItem
}" />
<span *ngIf="!_selectedValueTemplate(selectedItem)" class="chip-text" [title]="_displayFn(selectedItem)">{{_displayFn(selectedItem)}}</span>
</ng-container>
<button matChipRemove *ngIf="!disabled && removable" (click)="_removeSelectedItem(getSelectedItem(value), $event)">
<button matChipRemove *ngIf="!disabled" [disabled]="_canRemoveItem(getSelectedItem(value))"[matTooltipDisabled]="_canRemoveItem(getSelectedItem(value))" [matTooltip]="_canRemoveItemMessage(getSelectedItem(value))" (click)="_removeSelectedItem(getSelectedItem(value), $event)">
<mat-icon>cancel</mat-icon>
</button>
</mat-chip-row>

View File

@ -96,7 +96,6 @@ export class MultipleAutoCompleteComponent extends _CustomComponentMixinBase imp
_selectedItems: Map<string, any> = new Map<any, any>();
_groupedItems: Observable<AutoCompleteGroup[]>;
selectable = false;
removable = true;
selected: boolean = false;
get empty() {
@ -434,6 +433,21 @@ export class MultipleAutoCompleteComponent extends _CustomComponentMixinBase imp
this._items = null;
}
_canRemoveItem(item: any): boolean {
if(this.configuration.canRemoveItem != null) {
return this.configuration.canRemoveItem(item).canRemove;
}
return true;
}
_canRemoveItemMessage(item: any): string {
if(this.configuration.canRemoveItem != null) {
const canRemoveResuslt = this.configuration.canRemoveItem(item);
if (canRemoveResuslt.canRemove) return canRemoveResuslt.message;
}
return null;
}
_removeSelectedItem(item: any, event: MouseEvent): void {
if (event != null) { event.stopPropagation(); }
const valueToDelete = this._valueToAssign(item);

View File

@ -11,6 +11,8 @@ import javax.management.InvalidApplicationException;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
@Component
@RequestScope
public class TenantScope {
public static final String TenantReplaceParameter = "::TenantCode::";
private final MultitenancyProperties multitenancy;
@ -120,6 +122,3 @@ public class TenantScope {
}
}
}

View File

@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import javax.management.InvalidApplicationException;
import java.util.UUID;
public class TenantListener {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantListener.class));
private final TenantScope tenantScope;