tenant configuration changes

This commit is contained in:
Efstratios Giannopoulos 2024-04-22 11:42:07 +03:00
parent 378f3c957b
commit e90e49b4f1
11 changed files with 342 additions and 49 deletions

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

@ -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

@ -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() {
@ -55,6 +57,8 @@ public class TenantConfigurationLookup extends Lookup {
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

@ -0,0 +1,21 @@
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.management.InvalidApplicationException;
import java.util.UUID;
public interface TenantConfigurationService {
TenantConfiguration persist(TenantConfigurationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException;
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
}

View File

@ -0,0 +1,210 @@
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.EntityType;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.types.deposit.DepositSourceEntity;
import eu.eudat.commons.types.dmp.DmpPropertiesEntity;
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.builder.tenantconfiguration.TenantConfigurationBuilder;
import eu.eudat.model.deleter.TenantConfigurationDeleter;
import eu.eudat.model.persist.deposit.DepositSourcePersist;
import eu.eudat.model.persist.dmpproperties.DmpBlueprintValuePersist;
import eu.eudat.model.persist.dmpproperties.DmpContactPersist;
import eu.eudat.model.persist.dmpproperties.DmpPropertiesPersist;
import eu.eudat.model.persist.filetransformer.FileTransformerSourcePersist;
import eu.eudat.model.persist.tenantconfiguration.*;
import eu.eudat.model.tenantconfiguration.TenantConfiguration;
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.management.InvalidApplicationException;
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;
@Autowired
public TenantConfigurationServiceImpl(
TenantEntityManager entityManager,
AuthorizationService authorizationService,
DeleterFactory deleterFactory,
BuilderFactory builderFactory,
ConventionService conventionService,
ErrorThesaurusProperties errors,
MessageSource messageSource, JsonHandlingService jsonHandlingService) {
this.entityManager = entityManager;
this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory;
this.builderFactory = builderFactory;
this.conventionService = conventionService;
this.errors = errors;
this.messageSource = messageSource;
this.jsonHandlingService = jsonHandlingService;
}
public TenantConfiguration persist(TenantConfigurationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException {
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 -> data.setValue(this.jsonHandlingService.toJson(this.buildLogoTenantConfigurationEntity(model.getLogo())));
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){
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) {
DepositSourceEntity depositSourceEntity = new DepositSourceEntity();
depositSourceEntity.setClientId(depositSourcePersist.getClientId());
depositSourceEntity.setClientSecret(depositSourcePersist.getClientSecret());
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){
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) {
FileTransformerSourceEntity depositSourceEntity = new FileTransformerSourceEntity();
depositSourceEntity.setClientId(depositSourcePersist.getClientId());
depositSourceEntity.setClientSecret(depositSourcePersist.getClientSecret());
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 data = new LogoTenantConfigurationEntity();
if (persist == null) return data;
data.setStorageFileId(persist.getStorageFileId());
//TODO
return data;
}
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug("deleting dataset: {}", id);
this.authorizationService.authorizeForce(Permission.DeleteTenantConfiguration);
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

@ -1,19 +1,18 @@
package eu.eudat.controllers;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags;
import gr.cite.tools.validation.ValidationFilterAnnotation;
import eu.eudat.data.EntityDoiEntity;
import eu.eudat.data.TenantConfigurationEntity;
import eu.eudat.model.DescriptionTemplateType;
import eu.eudat.model.EntityDoi;
import eu.eudat.model.builder.EntityDoiBuilder;
import eu.eudat.model.censorship.EntityDoiCensor;
import eu.eudat.model.persist.EntityDoiPersist;
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.query.EntityDoiQuery;
import eu.eudat.query.lookup.EntityDoiLookup;
import eu.eudat.service.deposit.DepositService;
import eu.eudat.service.entitydoi.EntityDoiService;
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;
@ -24,6 +23,7 @@ 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;
@ -34,16 +34,16 @@ import javax.management.InvalidApplicationException;
import java.util.*;
@RestController
@RequestMapping(path = "api/entity-doi")
public class EntityDoiController {
@RequestMapping(path = "api/tenant-configuration")
public class TenantConfigurationController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeController.class));
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantConfigurationController.class));
private final BuilderFactory builderFactory;
private final AuditService auditService;
private final EntityDoiService entityDoiService;
private final TenantConfigurationService tenantConfigurationService;
private final CensorFactory censorFactory;
@ -51,49 +51,49 @@ public class EntityDoiController {
private final MessageSource messageSource;
public EntityDoiController(
public TenantConfigurationController(
BuilderFactory builderFactory,
AuditService auditService,
EntityDoiService entityDoiService, CensorFactory censorFactory,
TenantConfigurationService tenantConfigurationService, CensorFactory censorFactory,
QueryFactory queryFactory,
MessageSource messageSource) {
this.builderFactory = builderFactory;
this.auditService = auditService;
this.entityDoiService = entityDoiService;
this.tenantConfigurationService = tenantConfigurationService;
this.censorFactory = censorFactory;
this.queryFactory = queryFactory;
this.messageSource = messageSource;
}
@PostMapping("query")
public QueryResult<EntityDoi> Query(@RequestBody EntityDoiLookup lookup) throws MyApplicationException, MyForbiddenException {
logger.debug("querying {}", EntityDoi.class.getSimpleName());
public QueryResult<TenantConfiguration> Query(@RequestBody TenantConfigurationLookup lookup) throws MyApplicationException, MyForbiddenException {
logger.debug("querying {}", TenantConfiguration.class.getSimpleName());
this.censorFactory.censor(EntityDoiCensor.class).censor(lookup.getProject(), null);
this.censorFactory.censor(TenantConfigurationCensor.class).censor(lookup.getProject(), null);
EntityDoiQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission);
TenantConfigurationQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission);
List<EntityDoiEntity> data = query.collectAs(lookup.getProject());
List<EntityDoi> models = this.builderFactory.builder(EntityDoiBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data);
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.EntityDoi_Query, "lookup", lookup);
this.auditService.track(AuditableAction.TenantConfiguration_Query, "lookup", lookup);
return new QueryResult<>(models, count);
}
@GetMapping("{id}")
public EntityDoi Get(@PathVariable("id") UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("retrieving" + EntityDoi.class.getSimpleName()).And("id", id).And("fields", fieldSet));
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(EntityDoiCensor.class).censor(fieldSet, null);
this.censorFactory.censor(TenantConfigurationCensor.class).censor(fieldSet, null);
EntityDoiQuery query = this.queryFactory.query(EntityDoiQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id);
EntityDoi model = this.builderFactory.builder(EntityDoiBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet));
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, EntityDoi.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, TenantConfiguration.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.EntityDoi_Lookup, Map.ofEntries(
this.auditService.track(AuditableAction.TenantConfiguration_Lookup, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
@ -103,12 +103,12 @@ public class EntityDoiController {
@PostMapping("persist")
@Transactional
@ValidationFilterAnnotation(validator = EntityDoiPersist.EntityDoiPersistValidator.ValidatorName, argumentName = "model")
public EntityDoi Persist(@RequestBody EntityDoiPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
@ValidationFilterAnnotation(validator = TenantConfigurationPersist.TenantConfigurationPersistValidator.ValidatorName, argumentName = "model")
public TenantConfiguration Persist(@RequestBody TenantConfigurationPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException {
logger.debug(new MapLogEntry("persisting" + DescriptionTemplateType.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
EntityDoi persisted = this.entityDoiService.persist(model, fieldSet);
TenantConfiguration persisted = this.tenantConfigurationService.persist(model, fieldSet);
this.auditService.track(AuditableAction.EntityDoi_Persist, Map.ofEntries(
this.auditService.track(AuditableAction.TenantConfiguration_Persist, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
@ -119,11 +119,11 @@ public class EntityDoiController {
@DeleteMapping("{id}")
@Transactional
public void Delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug(new MapLogEntry("retrieving" + EntityDoi.class.getSimpleName()).And("id", id));
logger.debug(new MapLogEntry("retrieving" + TenantConfiguration.class.getSimpleName()).And("id", id));
this.entityDoiService.deleteAndSave(id);
this.tenantConfigurationService.deleteAndSave(id);
this.auditService.track(AuditableAction.EntityDoi_Delete, "id", id);
this.auditService.track(AuditableAction.TenantConfiguration_Delete, "id", id);
}
}

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