diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/InboxRepositoryImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/InboxRepositoryImpl.java index f13222728..b7b88006c 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/InboxRepositoryImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/InboxRepositoryImpl.java @@ -9,9 +9,9 @@ import gr.cite.annotation.integrationevent.TrackedEvent; import gr.cite.annotation.integrationevent.inbox.annotationentitiesremoval.AnnotationEntitiesRemovalIntegrationEventHandler; import gr.cite.annotation.integrationevent.inbox.annotationentitiestouch.AnnotationEntitiesTouchedIntegrationEventHandler; import gr.cite.annotation.integrationevent.inbox.tenantremoval.TenantRemovalIntegrationEventHandler; -import gr.cite.annotation.integrationevent.inbox.tenanttouch.TenantTouchedIntegrationEventHandler; +import gr.cite.annotation.integrationevent.inbox.tenanttouched.TenantTouchedIntegrationEventHandler; import gr.cite.annotation.integrationevent.inbox.userremoval.UserRemovalIntegrationEventHandler; -import gr.cite.annotation.integrationevent.inbox.usertouch.UserTouchedIntegrationEventHandler; +import gr.cite.annotation.integrationevent.inbox.usertouched.UserTouchedIntegrationEventHandler; import gr.cite.annotation.query.QueueInboxQuery; import gr.cite.queueinbox.entity.QueueInbox; import gr.cite.queueinbox.entity.QueueInboxStatus; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenantremoval/TenantRemovalIntegrationEventHandler.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenantremoval/TenantRemovalIntegrationEventHandler.java index 201a15af6..e79af0ecf 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenantremoval/TenantRemovalIntegrationEventHandler.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenantremoval/TenantRemovalIntegrationEventHandler.java @@ -1,5 +1,6 @@ package gr.cite.annotation.integrationevent.inbox.tenantremoval; + import gr.cite.annotation.integrationevent.inbox.IntegrationEventHandler; public interface TenantRemovalIntegrationEventHandler extends IntegrationEventHandler { diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenantremoval/TenantRemovalIntegrationEventHandlerImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenantremoval/TenantRemovalIntegrationEventHandlerImpl.java index 161694ab9..12b249333 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenantremoval/TenantRemovalIntegrationEventHandlerImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenantremoval/TenantRemovalIntegrationEventHandlerImpl.java @@ -1,5 +1,7 @@ package gr.cite.annotation.integrationevent.inbox.tenantremoval; +import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver; +import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties; import gr.cite.annotation.audit.AuditableAction; import gr.cite.annotation.common.JsonHandlingService; import gr.cite.annotation.data.TenantEntityManager; @@ -7,8 +9,6 @@ import gr.cite.annotation.integrationevent.inbox.EventProcessingStatus; import gr.cite.annotation.integrationevent.inbox.InboxPrincipal; import gr.cite.annotation.integrationevent.inbox.IntegrationEventProperties; import gr.cite.annotation.service.tenant.TenantService; -import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver; -import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties; import gr.cite.tools.auditing.AuditService; import gr.cite.tools.logging.LoggerService; import org.slf4j.LoggerFactory; @@ -34,12 +34,12 @@ public class TenantRemovalIntegrationEventHandlerImpl implements TenantRemovalIn private final TenantRemovalConsistencyHandler tenantRemovalConsistencyHandler; public TenantRemovalIntegrationEventHandlerImpl(JsonHandlingService jsonHandlingService, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, TenantService tenantService, AuditService auditService, TenantEntityManager tenantEntityManager, TenantRemovalConsistencyHandler tenantRemovalConsistencyHandler) { this.jsonHandlingService = jsonHandlingService; - this.currentPrincipalResolver = currentPrincipalResolver; - this.claimExtractorProperties = claimExtractorProperties; - this.tenantService = tenantService; - this.auditService = auditService; - this.tenantEntityManager = tenantEntityManager; - this.tenantRemovalConsistencyHandler = tenantRemovalConsistencyHandler; + this.currentPrincipalResolver = currentPrincipalResolver; + this.claimExtractorProperties = claimExtractorProperties; + this.tenantService = tenantService; + this.auditService = auditService; + this.tenantEntityManager = tenantEntityManager; + this.tenantRemovalConsistencyHandler = tenantRemovalConsistencyHandler; } @Override diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEvent.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEvent.java similarity index 87% rename from annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEvent.java rename to annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEvent.java index 11a47a881..9ba322ca5 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEvent.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEvent.java @@ -1,4 +1,5 @@ -package gr.cite.annotation.integrationevent.inbox.tenanttouch; +package gr.cite.annotation.integrationevent.inbox.tenanttouched; + import gr.cite.annotation.integrationevent.TrackedEvent; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEventHandler.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEventHandler.java similarity index 71% rename from annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEventHandler.java rename to annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEventHandler.java index e0843267a..2e5391235 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEventHandler.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEventHandler.java @@ -1,4 +1,4 @@ -package gr.cite.annotation.integrationevent.inbox.tenanttouch; +package gr.cite.annotation.integrationevent.inbox.tenanttouched; import gr.cite.annotation.integrationevent.inbox.IntegrationEventHandler; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEventHandlerImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEventHandlerImpl.java similarity index 98% rename from annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEventHandlerImpl.java rename to annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEventHandlerImpl.java index a3e8edbaa..3be6e60b2 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEventHandlerImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEventHandlerImpl.java @@ -1,5 +1,7 @@ -package gr.cite.annotation.integrationevent.inbox.tenanttouch; +package gr.cite.annotation.integrationevent.inbox.tenanttouched; +import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver; +import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties; import gr.cite.annotation.audit.AuditableAction; import gr.cite.annotation.common.JsonHandlingService; import gr.cite.annotation.data.TenantEntityManager; @@ -8,8 +10,6 @@ import gr.cite.annotation.integrationevent.inbox.InboxPrincipal; import gr.cite.annotation.integrationevent.inbox.IntegrationEventProperties; import gr.cite.annotation.model.persist.TenantTouchedIntegrationEventPersist; import gr.cite.annotation.service.tenant.TenantService; -import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver; -import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties; import gr.cite.tools.auditing.AuditService; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.validation.ValidatorFactory; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/userremoval/UserRemovalConsistencyPredicates.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/userremoval/UserRemovalConsistencyPredicates.java index cfc98997c..226caa447 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/userremoval/UserRemovalConsistencyPredicates.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/userremoval/UserRemovalConsistencyPredicates.java @@ -1,5 +1,6 @@ package gr.cite.annotation.integrationevent.inbox.userremoval; + import gr.cite.annotation.integrationevent.inbox.ConsistencyPredicates; import java.util.UUID; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/userremoval/UserRemovalIntegrationEventHandler.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/userremoval/UserRemovalIntegrationEventHandler.java index e9e641f35..52060c66b 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/userremoval/UserRemovalIntegrationEventHandler.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/userremoval/UserRemovalIntegrationEventHandler.java @@ -1,5 +1,6 @@ package gr.cite.annotation.integrationevent.inbox.userremoval; + import gr.cite.annotation.integrationevent.inbox.IntegrationEventHandler; public interface UserRemovalIntegrationEventHandler extends IntegrationEventHandler { diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/userremoval/UserRemovalIntegrationEventHandlerImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/userremoval/UserRemovalIntegrationEventHandlerImpl.java index 08287a076..b741f9f2a 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/userremoval/UserRemovalIntegrationEventHandlerImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/userremoval/UserRemovalIntegrationEventHandlerImpl.java @@ -1,23 +1,18 @@ package gr.cite.annotation.integrationevent.inbox.userremoval; +import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver; +import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties; import gr.cite.annotation.audit.AuditableAction; import gr.cite.annotation.common.JsonHandlingService; import gr.cite.annotation.common.scope.tenant.TenantScope; -import gr.cite.annotation.data.TenantEntity; import gr.cite.annotation.data.TenantEntityManager; import gr.cite.annotation.errorcode.ErrorThesaurusProperties; import gr.cite.annotation.integrationevent.inbox.EventProcessingStatus; import gr.cite.annotation.integrationevent.inbox.InboxPrincipal; import gr.cite.annotation.integrationevent.inbox.IntegrationEventProperties; -import gr.cite.annotation.model.Tenant; -import gr.cite.annotation.query.TenantQuery; import gr.cite.annotation.service.user.UserService; -import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver; -import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties; import gr.cite.tools.auditing.AuditService; -import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyValidationException; -import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.logging.LoggerService; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -26,7 +21,6 @@ import org.springframework.context.annotation.Scope; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Component; -import javax.management.InvalidApplicationException; import java.util.AbstractMap; import java.util.Map; @@ -42,7 +36,6 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr private final ErrorThesaurusProperties errors; private final MessageSource messageSource; - private final QueryFactory queryFactory; private final TenantScope tenantScope; private final CurrentPrincipalResolver currentPrincipalResolver; private final ClaimExtractorProperties claimExtractorProperties; @@ -52,21 +45,20 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr private final TenantEntityManager tenantEntityManager; public UserRemovalIntegrationEventHandlerImpl( - JsonHandlingService jsonHandlingService, - ErrorThesaurusProperties errors, - MessageSource messageSource, QueryFactory queryFactory, TenantScope tenantScope, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, UserRemovalConsistencyHandler userRemovalConsistencyHandler, UserService userService, AuditService auditService, TenantEntityManager tenantEntityManager + JsonHandlingService jsonHandlingService, + ErrorThesaurusProperties errors, + MessageSource messageSource, TenantScope tenantScope, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, UserRemovalConsistencyHandler userRemovalConsistencyHandler, UserService userService, AuditService auditService, TenantEntityManager tenantEntityManager ) { this.jsonHandlingService = jsonHandlingService; this.errors = errors; this.messageSource = messageSource; - this.queryFactory = queryFactory; - this.tenantScope = tenantScope; - this.currentPrincipalResolver = currentPrincipalResolver; - this.claimExtractorProperties = claimExtractorProperties; - this.userRemovalConsistencyHandler = userRemovalConsistencyHandler; - this.userService = userService; - this.auditService = auditService; - this.tenantEntityManager = tenantEntityManager; + this.tenantScope = tenantScope; + this.currentPrincipalResolver = currentPrincipalResolver; + this.claimExtractorProperties = claimExtractorProperties; + this.userRemovalConsistencyHandler = userRemovalConsistencyHandler; + this.userService = userService; + this.auditService = auditService; + this.tenantEntityManager = tenantEntityManager; } @Override @@ -81,29 +73,21 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr EventProcessingStatus status = EventProcessingStatus.Success; try { - if (this.tenantScope.isMultitenant() && properties.getTenantId() != null) { - TenantEntity tenant = queryFactory.query(TenantQuery.class).disableTracking().ids(properties.getTenantId()).firstAs(new BaseFieldSet().ensure(Tenant._id).ensure(Tenant._code)); - if (tenant == null) { - logger.error("missing tenant from event message"); - return EventProcessingStatus.Error; - } - this.tenantScope.setTempTenant(tenantEntityManager, properties.getTenantId(), tenant.getCode()); - } else if (this.tenantScope.isMultitenant()) { -// logger.error("missing tenant from event message"); -// return EventProcessingStatus.Error; - this.tenantScope.setTempTenant(tenantEntityManager, null, this.tenantScope.getDefaultTenantCode()); - } - currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties)); - if (!(userRemovalConsistencyHandler.isConsistent(new UserRemovalConsistencyPredicates(event.getUserId())))) { - status = EventProcessingStatus.Postponed; - currentPrincipalResolver.pop(); - tenantScope.removeTempTenant(this.tenantEntityManager); - return status; - } - - userService.deleteAndSave(event.getUserId()); + try{ + this.tenantEntityManager.disableTenantFilters(); + if (!(userRemovalConsistencyHandler.isConsistent(new UserRemovalConsistencyPredicates(event.getUserId())))) { + status = EventProcessingStatus.Postponed; + currentPrincipalResolver.pop(); + tenantScope.removeTempTenant(this.tenantEntityManager); + return status; + } + + userService.deleteAndSave(event.getUserId()); + } finally { + this.tenantEntityManager.reloadTenantFilters(); + } auditService.track(AuditableAction.User_Delete, Map.ofEntries( new AbstractMap.SimpleEntry("id", event.getUserId()) @@ -114,11 +98,6 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex); } finally { currentPrincipalResolver.pop(); - try { - tenantScope.removeTempTenant(this.tenantEntityManager); - } catch (InvalidApplicationException e) { - logger.error( e.getMessage(), e); - } } return status; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEvent.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEvent.java similarity index 94% rename from annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEvent.java rename to annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEvent.java index 56db5fd7d..889786041 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEvent.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEvent.java @@ -1,11 +1,10 @@ -package gr.cite.annotation.integrationevent.inbox.usertouch; +package gr.cite.annotation.integrationevent.inbox.usertouched; import gr.cite.annotation.common.enums.ContactInfoType; import gr.cite.annotation.common.validation.BaseValidator; import gr.cite.annotation.convention.ConventionService; import gr.cite.annotation.errorcode.ErrorThesaurusProperties; import gr.cite.annotation.integrationevent.TrackedEvent; -import gr.cite.annotation.model.persist.UserTouchedIntegrationEventPersist; import gr.cite.tools.validation.ValidatorFactory; import gr.cite.tools.validation.specification.Specification; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -162,7 +161,7 @@ public class UserTouchedIntegrationEvent extends TrackedEvent { this.ordinal = ordinal; } - @Component(UserTouchedIntegrationEvent.UserContactInfo.UserTouchedIntegrationUserContactInfoEventValidator.ValidatorName) + @Component(UserTouchedIntegrationUserContactInfoEventValidator.ValidatorName) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public static class UserTouchedIntegrationUserContactInfoEventValidator extends BaseValidator { @@ -211,7 +210,7 @@ public class UserTouchedIntegrationEvent extends TrackedEvent { this.subjectId = subjectId; } - @Component(UserCredential.UserTouchedIntegrationUserCredentialEventValidator.ValidatorName) + @Component(UserTouchedIntegrationUserCredentialEventValidator.ValidatorName) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public static class UserTouchedIntegrationUserCredentialEventValidator extends BaseValidator { @@ -253,7 +252,7 @@ public class UserTouchedIntegrationEvent extends TrackedEvent { this.tenant = tenant; } - @Component(TenantUser.UserTouchedIntegrationTenantUserEventValidator.ValidatorName) + @Component(UserTouchedIntegrationTenantUserEventValidator.ValidatorName) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public static class UserTouchedIntegrationTenantUserEventValidator extends BaseValidator { @@ -282,7 +281,7 @@ public class UserTouchedIntegrationEvent extends TrackedEvent { } } - @Component(UserTouchedIntegrationEvent.UserTouchedIntegrationEventValidator.ValidatorName) + @Component(UserTouchedIntegrationEventValidator.ValidatorName) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public static class UserTouchedIntegrationEventValidator extends BaseValidator { @@ -315,7 +314,7 @@ public class UserTouchedIntegrationEvent extends TrackedEvent { .failOn(UserTouchedIntegrationEvent._name).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserTouchedIntegrationEvent._name}, LocaleContextHolder.getLocale())), this.spec() .iff(() -> !this.isEmpty(item.getName())) - .must(() -> this.lessEqualLength(item.getName(), UserTouchedIntegrationEventPersist._nameLength)) + .must(() -> this.lessEqualLength(item.getName(), UserTouchedIntegrationEvent._nameLength)) .failOn(UserTouchedIntegrationEvent._name).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{UserTouchedIntegrationEvent._name}, LocaleContextHolder.getLocale())), this.navSpec() .iff(() -> !this.isListNullOrEmpty(item.getUserContactInfo())) diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEventHandler.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEventHandler.java similarity index 72% rename from annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEventHandler.java rename to annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEventHandler.java index dd36fad10..e9c38baef 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEventHandler.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEventHandler.java @@ -1,4 +1,5 @@ -package gr.cite.annotation.integrationevent.inbox.usertouch; +package gr.cite.annotation.integrationevent.inbox.usertouched; + import gr.cite.annotation.integrationevent.inbox.IntegrationEventHandler; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEventHandlerImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEventHandlerImpl.java similarity index 60% rename from annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEventHandlerImpl.java rename to annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEventHandlerImpl.java index a7d87971b..9d6db50fb 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEventHandlerImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEventHandlerImpl.java @@ -1,21 +1,17 @@ -package gr.cite.annotation.integrationevent.inbox.usertouch; +package gr.cite.annotation.integrationevent.inbox.usertouched; -import gr.cite.annotation.data.TenantEntityManager; import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver; +import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties; import gr.cite.annotation.audit.AuditableAction; import gr.cite.annotation.common.JsonHandlingService; import gr.cite.annotation.common.scope.tenant.TenantScope; -import gr.cite.annotation.data.TenantEntity; +import gr.cite.annotation.data.TenantEntityManager; import gr.cite.annotation.integrationevent.inbox.EventProcessingStatus; import gr.cite.annotation.integrationevent.inbox.InboxPrincipal; import gr.cite.annotation.integrationevent.inbox.IntegrationEventProperties; -import gr.cite.annotation.model.Tenant; -import gr.cite.annotation.query.TenantQuery; import gr.cite.annotation.service.user.UserService; -import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties; import gr.cite.tools.auditing.AuditService; import gr.cite.tools.data.query.QueryFactory; -import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.validation.ValidatorFactory; import org.slf4j.LoggerFactory; @@ -23,7 +19,6 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -import javax.management.InvalidApplicationException; import java.util.AbstractMap; import java.util.Map; @@ -46,17 +41,17 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr private final TenantEntityManager tenantEntityManager; public UserTouchedIntegrationEventHandlerImpl( - JsonHandlingService jsonHandlingService, - ValidatorFactory validatorFactory, QueryFactory queryFactory, TenantScope tenantScope, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, UserService userService, AuditService auditService, TenantEntityManager tenantEntityManager) { + JsonHandlingService jsonHandlingService, + ValidatorFactory validatorFactory, QueryFactory queryFactory, TenantScope tenantScope, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, UserService userService, AuditService auditService, TenantEntityManager tenantEntityManager) { this.jsonHandlingService = jsonHandlingService; this.validatorFactory = validatorFactory; - this.queryFactory = queryFactory; - this.tenantScope = tenantScope; - this.currentPrincipalResolver = currentPrincipalResolver; - this.claimExtractorProperties = claimExtractorProperties; - this.userService = userService; - this.auditService = auditService; - this.tenantEntityManager = tenantEntityManager; + this.queryFactory = queryFactory; + this.tenantScope = tenantScope; + this.currentPrincipalResolver = currentPrincipalResolver; + this.claimExtractorProperties = claimExtractorProperties; + this.userService = userService; + this.auditService = auditService; + this.tenantEntityManager = tenantEntityManager; } @Override @@ -71,23 +66,14 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr EventProcessingStatus status = EventProcessingStatus.Success; try { - if (this.tenantScope.isMultitenant() && properties.getTenantId() != null) { - TenantEntity tenant = queryFactory.query(TenantQuery.class).disableTracking().ids(properties.getTenantId()).firstAs(new BaseFieldSet().ensure(Tenant._id).ensure(Tenant._code)); - if (tenant == null) { - logger.error("missing tenant from event message"); - return EventProcessingStatus.Error; - } - this.tenantScope.setTempTenant(tenantEntityManager, properties.getTenantId(), tenant.getCode()); - } else if (this.tenantScope.isMultitenant()) { -// logger.error("missing tenant from event message"); -// return EventProcessingStatus.Error; - this.tenantScope.setTempTenant(tenantEntityManager, null, this.tenantScope.getDefaultTenantCode()); - } currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties)); - - userService.persist(event, null); - + try { + this.tenantEntityManager.disableTenantFilters(); + userService.persist(event, null); + } finally { + this.tenantEntityManager.reloadTenantFilters(); + } auditService.track(AuditableAction.User_Persist, Map.ofEntries( new AbstractMap.SimpleEntry("model", event) )); @@ -97,13 +83,8 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex); } finally { currentPrincipalResolver.pop(); - try { - tenantScope.removeTempTenant(this.tenantEntityManager); - } catch (InvalidApplicationException e) { - logger.error(e.getMessage(), e); - } } return status; } -} \ No newline at end of file +} diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/model/persist/UserTouchedIntegrationEventPersist.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/model/persist/UserTouchedIntegrationEventPersist.java index 1c184d609..da06b8cee 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/model/persist/UserTouchedIntegrationEventPersist.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/model/persist/UserTouchedIntegrationEventPersist.java @@ -3,7 +3,7 @@ package gr.cite.annotation.model.persist; import gr.cite.annotation.common.validation.BaseValidator; import gr.cite.annotation.convention.ConventionService; import gr.cite.annotation.errorcode.ErrorThesaurusProperties; -import gr.cite.annotation.integrationevent.inbox.usertouch.UserTouchedIntegrationEvent; +import gr.cite.annotation.integrationevent.inbox.usertouched.UserTouchedIntegrationEvent; import gr.cite.tools.validation.specification.Specification; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.MessageSource; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserService.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserService.java index e29fcd36b..8d32d3d12 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserService.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserService.java @@ -1,7 +1,7 @@ package gr.cite.annotation.service.user; import com.fasterxml.jackson.core.JsonProcessingException; -import gr.cite.annotation.integrationevent.inbox.usertouch.UserTouchedIntegrationEvent; +import gr.cite.annotation.integrationevent.inbox.usertouched.UserTouchedIntegrationEvent; import gr.cite.annotation.model.User; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyForbiddenException; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserServiceImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserServiceImpl.java index 9c1339f2c..9898a97dc 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserServiceImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserServiceImpl.java @@ -8,7 +8,7 @@ import gr.cite.annotation.common.enums.IsActive; import gr.cite.annotation.common.scope.tenant.TenantScope; import gr.cite.annotation.convention.ConventionService; import gr.cite.annotation.data.*; -import gr.cite.annotation.integrationevent.inbox.usertouch.UserTouchedIntegrationEvent; +import gr.cite.annotation.integrationevent.inbox.usertouched.UserTouchedIntegrationEvent; import gr.cite.annotation.model.Tenant; import gr.cite.annotation.model.User; import gr.cite.annotation.model.builder.UserBuilder; diff --git a/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/annotationentityremoval/AnnotationEntityRemovalIntegrationEventHandlerImpl.java b/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/annotationentityremoval/AnnotationEntityRemovalIntegrationEventHandlerImpl.java index 9ba6f13de..2e678baf6 100644 --- a/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/annotationentityremoval/AnnotationEntityRemovalIntegrationEventHandlerImpl.java +++ b/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/annotationentityremoval/AnnotationEntityRemovalIntegrationEventHandlerImpl.java @@ -5,16 +5,18 @@ import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.logging.LoggerService; import org.opencdmp.commons.scope.tenant.TenantScope; import org.opencdmp.data.DescriptionEntity; +import org.opencdmp.data.DmpEntity; import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent; import org.opencdmp.integrationevent.outbox.OutboxService; import org.opencdmp.model.description.Description; +import org.opencdmp.model.dmp.Dmp; import org.opencdmp.query.DescriptionQuery; +import org.opencdmp.query.DmpQuery; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -import javax.management.InvalidApplicationException; import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -28,41 +30,44 @@ public class AnnotationEntityRemovalIntegrationEventHandlerImpl implements Annot private final OutboxService outboxService; private final QueryFactory queryFactory; - private final TenantScope tenantScope; public AnnotationEntityRemovalIntegrationEventHandlerImpl(OutboxService outboxService, QueryFactory queryFactory, TenantScope tenantScope) { this.outboxService = outboxService; this.queryFactory = queryFactory; - this.tenantScope = tenantScope; } - private void handle(AnnotationEntitiesRemovalIntegrationEvent event) throws InvalidApplicationException { + private void handle(AnnotationEntitiesRemovalIntegrationEvent event, UUID tenantId) { OutboxIntegrationEvent message = new OutboxIntegrationEvent(); message.setMessageId(UUID.randomUUID()); message.setType(OutboxIntegrationEvent.ANNOTATION_ENTITY_REMOVE); message.setEvent(event); - if (this.tenantScope.isSet()) message.setTenantId(this.tenantScope.getTenant()); this.outboxService.publish(message); } @Override - public void handleDescription(UUID descriptionId) throws InvalidApplicationException { - AnnotationEntitiesRemovalIntegrationEvent event = new AnnotationEntitiesRemovalIntegrationEvent(); + public void handleDescription(UUID descriptionId) { + DescriptionEntity description = this.queryFactory.query(DescriptionQuery.class).disableTracking().ids(descriptionId).firstAs(new BaseFieldSet().ensure(Description._id).ensure(DescriptionEntity._tenantId)); + if (description == null) return; + + AnnotationEntitiesRemovalIntegrationEvent event = new AnnotationEntitiesRemovalIntegrationEvent(); event.setEntityIds(List.of(descriptionId)); - this.handle(event); + this.handle(event, description.getTenantId()); } @Override - public void handleDmp(UUID dmpId) throws InvalidApplicationException { + public void handleDmp(UUID dmpId) { + DmpEntity dmp = this.queryFactory.query(DmpQuery.class).disableTracking().ids(dmpId).firstAs(new BaseFieldSet().ensure(Dmp._id).ensure(DmpEntity._tenantId)); + if(dmp == null) return; + List descriptionEntities = this.queryFactory.query(DescriptionQuery.class).disableTracking().dmpIds(dmpId).collectAs(new BaseFieldSet().ensure(Description._id)); - + AnnotationEntitiesRemovalIntegrationEvent event = new AnnotationEntitiesRemovalIntegrationEvent(); event.setEntityIds(new ArrayList<>()); event.getEntityIds().add(dmpId); for (DescriptionEntity description : descriptionEntities) event.getEntityIds().add(description.getId()); - this.handle(event); + this.handle(event, dmp.getTenantId()); } } diff --git a/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/annotationentitytouch/AnnotationEntitiesTouchedIntegrationEvent.java b/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/annotationentitytouch/AnnotationEntitiesTouchedIntegrationEvent.java index a913e53fd..9862776b2 100644 --- a/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/annotationentitytouch/AnnotationEntitiesTouchedIntegrationEvent.java +++ b/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/annotationentitytouch/AnnotationEntitiesTouchedIntegrationEvent.java @@ -10,7 +10,7 @@ public class AnnotationEntitiesTouchedIntegrationEvent extends TrackedEvent { private List events; public List getEvents() { - return events; + return this.events; } public void setEvents(List events) { @@ -24,7 +24,7 @@ public class AnnotationEntitiesTouchedIntegrationEvent extends TrackedEvent { private List userIds; public UUID getEntityId() { - return entityId; + return this.entityId; } public void setEntityId(UUID entityId) { @@ -32,7 +32,7 @@ public class AnnotationEntitiesTouchedIntegrationEvent extends TrackedEvent { } public List getUserIds() { - return userIds; + return this.userIds; } public void setUserIds(List userIds) { diff --git a/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/notification/NotifyIntegrationEventHandlerImpl.java b/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/notification/NotifyIntegrationEventHandlerImpl.java index f58ae8ace..596e3020a 100644 --- a/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/notification/NotifyIntegrationEventHandlerImpl.java +++ b/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/notification/NotifyIntegrationEventHandlerImpl.java @@ -3,8 +3,6 @@ package org.opencdmp.integrationevent.outbox.notification; import org.opencdmp.commons.scope.tenant.TenantScope; import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent; import org.opencdmp.integrationevent.outbox.OutboxService; -import gr.cite.tools.logging.LoggerService; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; @@ -16,8 +14,6 @@ import java.util.UUID; @RequestScope public class NotifyIntegrationEventHandlerImpl implements NotifyIntegrationEventHandler { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(NotifyIntegrationEventHandlerImpl.class)); - private final OutboxService outboxService; private final TenantScope tenantScope; @@ -34,7 +30,7 @@ public class NotifyIntegrationEventHandlerImpl implements NotifyIntegrationEvent message.setMessageId(UUID.randomUUID()); message.setType(OutboxIntegrationEvent.NOTIFY); message.setEvent(event); - if (this.tenantScope.isSet()) message.setTenantId(tenantScope.getTenant()); + if (this.tenantScope.isSet()) message.setTenantId(this.tenantScope.getTenant()); this.outboxService.publish(message); } } diff --git a/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/tenantdefaultlocaleremoval/TenantDefaultLocaleRemovalIntegrationEventHandlerImpl.java b/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/tenantdefaultlocaleremoval/TenantDefaultLocaleRemovalIntegrationEventHandlerImpl.java index 1930ec4fe..ce1fa5a97 100644 --- a/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/tenantdefaultlocaleremoval/TenantDefaultLocaleRemovalIntegrationEventHandlerImpl.java +++ b/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/tenantdefaultlocaleremoval/TenantDefaultLocaleRemovalIntegrationEventHandlerImpl.java @@ -1,9 +1,8 @@ package org.opencdmp.integrationevent.outbox.tenantdefaultlocaleremoval; -import org.opencdmp.commons.scope.tenant.TenantScope; +import gr.cite.tools.logging.LoggerService; import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent; import org.opencdmp.integrationevent.outbox.OutboxService; -import gr.cite.tools.logging.LoggerService; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -19,13 +18,11 @@ public class TenantDefaultLocaleRemovalIntegrationEventHandlerImpl implements Te private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantDefaultLocaleRemovalIntegrationEventHandlerImpl.class)); private final OutboxService outboxService; - private final TenantScope tenantScope; @Autowired public TenantDefaultLocaleRemovalIntegrationEventHandlerImpl( - OutboxService outboxService, TenantScope tenantScope) { + OutboxService outboxService) { this.outboxService = outboxService; - this.tenantScope = tenantScope; } @Override @@ -34,7 +31,7 @@ public class TenantDefaultLocaleRemovalIntegrationEventHandlerImpl implements Te message.setMessageId(UUID.randomUUID()); message.setType(OutboxIntegrationEvent.TENANT_DEFAULT_LOCALE_REMOVAL); message.setEvent(event); - if (this.tenantScope.isSet()) message.setTenantId(tenantScope.getTenant()); + message.setTenantId(event.getTenantId()); this.outboxService.publish(message); } } diff --git a/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/tenantdefaultlocaletouched/TenantDefaultLocaleTouchedIntegrationEventHandlerImpl.java b/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/tenantdefaultlocaletouched/TenantDefaultLocaleTouchedIntegrationEventHandlerImpl.java index ea3a48043..624771881 100644 --- a/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/tenantdefaultlocaletouched/TenantDefaultLocaleTouchedIntegrationEventHandlerImpl.java +++ b/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/tenantdefaultlocaletouched/TenantDefaultLocaleTouchedIntegrationEventHandlerImpl.java @@ -1,9 +1,8 @@ package org.opencdmp.integrationevent.outbox.tenantdefaultlocaletouched; -import org.opencdmp.commons.scope.tenant.TenantScope; +import gr.cite.tools.logging.LoggerService; import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent; import org.opencdmp.integrationevent.outbox.OutboxService; -import gr.cite.tools.logging.LoggerService; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -19,13 +18,11 @@ public class TenantDefaultLocaleTouchedIntegrationEventHandlerImpl implements Te private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantDefaultLocaleTouchedIntegrationEventHandlerImpl.class)); private final OutboxService outboxService; - private final TenantScope tenantScope; @Autowired public TenantDefaultLocaleTouchedIntegrationEventHandlerImpl( - OutboxService outboxService, TenantScope tenantScope) { + OutboxService outboxService) { this.outboxService = outboxService; - this.tenantScope = tenantScope; } @Override @@ -34,7 +31,7 @@ public class TenantDefaultLocaleTouchedIntegrationEventHandlerImpl implements Te message.setMessageId(UUID.randomUUID()); message.setType(OutboxIntegrationEvent.TENANT_DEFAULT_LOCALE_TOUCHED); message.setEvent(event); - if (this.tenantScope.isSet()) message.setTenantId(tenantScope.getTenant()); + message.setTenantId(event.getTenantId()); this.outboxService.publish(message); } } diff --git a/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/userremoval/UserRemovalIntegrationEventHandlerImpl.java b/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/userremoval/UserRemovalIntegrationEventHandlerImpl.java index dc0a65b33..19e604044 100644 --- a/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/userremoval/UserRemovalIntegrationEventHandlerImpl.java +++ b/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/userremoval/UserRemovalIntegrationEventHandlerImpl.java @@ -1,9 +1,8 @@ package org.opencdmp.integrationevent.outbox.userremoval; -import org.opencdmp.commons.scope.tenant.TenantScope; +import gr.cite.tools.logging.LoggerService; import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent; import org.opencdmp.integrationevent.outbox.OutboxService; -import gr.cite.tools.logging.LoggerService; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.ApplicationContext; @@ -14,7 +13,7 @@ import javax.management.InvalidApplicationException; import java.util.UUID; @Component("outboxuserremovalintegrationeventhandler") -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegrationEventHandler { private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserRemovalIntegrationEventHandlerImpl.class)); @@ -22,12 +21,10 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr private final OutboxService outboxService; private final ApplicationContext applicationContext; - private final TenantScope tenantScope; - public UserRemovalIntegrationEventHandlerImpl(OutboxService outboxService, ApplicationContext applicationContext, TenantScope tenantScope) { + public UserRemovalIntegrationEventHandlerImpl(OutboxService outboxService, ApplicationContext applicationContext) { this.outboxService = outboxService; this.applicationContext = applicationContext; - this.tenantScope = tenantScope; } @Override @@ -39,7 +36,6 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr OutboxIntegrationEvent message = new OutboxIntegrationEvent(); message.setMessageId(UUID.randomUUID()); message.setType(OutboxIntegrationEvent.USER_REMOVE); - if (this.tenantScope.isSet()) message.setTenantId(tenantScope.getTenant()); UserRemovalIntegrationEvent event = new UserRemovalIntegrationEvent(); event.setUserId(userId); message.setEvent(event); diff --git a/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/usertouched/UserTouchedIntegrationEventHandlerImpl.java b/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/usertouched/UserTouchedIntegrationEventHandlerImpl.java index 285a38624..2c20d3d3e 100644 --- a/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/usertouched/UserTouchedIntegrationEventHandlerImpl.java +++ b/backend/core/src/main/java/org/opencdmp/integrationevent/outbox/usertouched/UserTouchedIntegrationEventHandlerImpl.java @@ -5,7 +5,6 @@ import gr.cite.tools.exception.MyNotFoundException; import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.logging.LoggerService; import org.opencdmp.commons.JsonHandlingService; -import org.opencdmp.commons.scope.tenant.TenantScope; import org.opencdmp.commons.types.user.AdditionalInfoEntity; import org.opencdmp.data.*; import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent; @@ -39,16 +38,14 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr private final OutboxService outboxService; private final JsonHandlingService jsonHandlingService; private final MessageSource messageSource; - private final TenantScope tenantScope; private final TenantEntityManager entityManager; private final QueryFactory queryFactory; public UserTouchedIntegrationEventHandlerImpl( - OutboxService outboxService, JsonHandlingService jsonHandlingService, MessageSource messageSource, TenantScope tenantScope, TenantEntityManager entityManager, QueryFactory queryFactory) { + OutboxService outboxService, JsonHandlingService jsonHandlingService, MessageSource messageSource, TenantEntityManager entityManager, QueryFactory queryFactory) { this.outboxService = outboxService; this.jsonHandlingService = jsonHandlingService; this.messageSource = messageSource; - this.tenantScope = tenantScope; this.entityManager = entityManager; this.queryFactory = queryFactory; } @@ -58,7 +55,6 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr OutboxIntegrationEvent message = new OutboxIntegrationEvent(); message.setMessageId(UUID.randomUUID()); message.setType(OutboxIntegrationEvent.USER_TOUCH); - if (this.tenantScope.isSet()) message.setTenantId(this.tenantScope.getTenant()); try { this.entityManager.disableTenantFilters(); diff --git a/backend/core/src/main/java/org/opencdmp/query/DmpQuery.java b/backend/core/src/main/java/org/opencdmp/query/DmpQuery.java index e7388f0a7..2f65125cb 100644 --- a/backend/core/src/main/java/org/opencdmp/query/DmpQuery.java +++ b/backend/core/src/main/java/org/opencdmp/query/DmpQuery.java @@ -428,6 +428,8 @@ public class DmpQuery extends QueryBase { return DmpEntity._publicAfter; else if (item.match(Dmp._versionStatus)) return DmpEntity._versionStatus; + else if (item.match(DmpEntity._tenantId)) + return DmpEntity._tenantId; else if (item.match(Dmp._belongsToCurrentTenant)) return DmpEntity._tenantId; else diff --git a/backend/core/src/main/java/org/opencdmp/service/tenant/TenantServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/tenant/TenantServiceImpl.java index 6a10e1bb4..5a0e845dc 100644 --- a/backend/core/src/main/java/org/opencdmp/service/tenant/TenantServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/tenant/TenantServiceImpl.java @@ -163,32 +163,34 @@ public class TenantServiceImpl implements TenantService { List existingItems; List userCredentialEntities; try { - this.tenantScope.setTempTenant(this.entityManager, null, this.tenantScope.getDefaultTenantCode()); + this.entityManager.disableTenantFilters(); existingItems = this.queryFactory.query(UserRoleQuery.class).disableTracking().tenantIsSet(false).roles(this.authorizationProperties.getGlobalAdminRole()).collect(); userCredentialEntities = this.queryFactory.query(UserCredentialQuery.class).disableTracking().userIds(existingItems.stream().map(UserRoleEntity::getUserId).distinct().toList()).collect(); - } finally { - this.tenantScope.removeTempTenant(this.entityManager); - } - try { - this.tenantScope.setTempTenant(this.entityManager, tenant.getId(), tenant.getCode()); + + List keycloakIdsToAddToTenantGroup = new ArrayList<>(); for (UUID userId : existingItems.stream().map(UserRoleEntity::getUserId).distinct().toList()) { UserCredentialEntity userCredential = userCredentialEntities.stream().filter(x-> !this.conventionService.isNullOrEmpty(x.getExternalId()) && x.getUserId().equals(userId)).findFirst().orElse(null); if (userCredential == null) continue; UserRoleEntity item = new UserRoleEntity(); item.setId(UUID.randomUUID()); item.setUserId(userId); + item.setTenantId(tenant.getId()); item.setRole(this.authorizationProperties.getTenantAdminRole()); item.setCreatedAt(Instant.now()); this.entityManager.persist(item); + keycloakIdsToAddToTenantGroup.add(userCredential.getExternalId()); this.keycloakService.addUserToTenantRoleGroup(userCredential.getExternalId(), this.tenantScope.getTenantCode(), this.authorizationProperties.getTenantAdminRole()); } - } finally { - this.tenantScope.removeTempTenant(this.entityManager); - } - this.entityManager.flush(); - + this.entityManager.flush(); + + for (String externalId : keycloakIdsToAddToTenantGroup) { + this.keycloakService.addUserToTenantRoleGroup(externalId, this.tenantScope.getTenantCode(), this.authorizationProperties.getTenantAdminRole()); + } + } finally { + this.entityManager.reloadTenantFilters(); + } } @Override diff --git a/backend/core/src/main/java/org/opencdmp/service/user/UserServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/user/UserServiceImpl.java index 00e806ac8..026e95def 100644 --- a/backend/core/src/main/java/org/opencdmp/service/user/UserServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/user/UserServiceImpl.java @@ -280,8 +280,12 @@ public class UserServiceImpl implements UserService { logger.debug("deleting User: {}", id); this.authorizationService.authorizeForce(Permission.DeleteUser); - - this.deleterFactory.deleter(UserDeleter.class).deleteAndSaveByIds(List.of(id)); + try { + this.entityManager.disableTenantFilters(); + this.deleterFactory.deleter(UserDeleter.class).deleteAndSaveByIds(List.of(id)); + } finally { + this.entityManager.reloadTenantFilters(); + } this.userRemovalIntegrationEventHandler.handle(id); } @@ -341,7 +345,7 @@ public class UserServiceImpl implements UserService { private void applyGlobalRoles(UUID userId, UserRolePatchPersist model) throws InvalidApplicationException { try { - this.tenantScope.setTempTenant(this.entityManager, null, this.tenantScope.getDefaultTenantCode()); + this.entityManager.disableTenantFilters(); List existingItems = this.queryFactory.query(UserRoleQuery.class).userIds(userId).tenantIsSet(false).roles(this.authorizationProperties.getAllowedGlobalRoles()).collect(); List foundIds = new ArrayList<>(); @@ -365,7 +369,7 @@ public class UserServiceImpl implements UserService { this.entityManager.flush(); } finally { - this.tenantScope.removeTempTenant(this.entityManager); + this.entityManager.reloadTenantFilters(); } } @@ -623,131 +627,155 @@ public class UserServiceImpl implements UserService { } - private void syncKeycloakRoles(UUID userId){ - List userCredentials = this.queryFactory.query(UserCredentialQuery.class).disableTracking().userIds(userId).collect(); - List userRoles = this.queryFactory.query(UserRoleQuery.class).disableTracking().userIds(userId).collect(); - List tenants = this.queryFactory.query(TenantQuery.class).disableTracking().ids(userRoles.stream().map(TenantScopedBaseEntity::getTenantId).filter(Objects::nonNull).toList()).collect(); - - for (UserCredentialEntity userCredential : userCredentials){ - this.keycloakService.removeFromAllGroups(userCredential.getExternalId()); - for (UserRoleEntity userRole : userRoles) { - if (this.authorizationProperties.getAllowedGlobalRoles().contains(userRole.getRole())){ - this.keycloakService.addUserToGlobalRoleGroup(userCredential.getExternalId(), userRole.getRole()); - } else if (this.authorizationProperties.getAllowedTenantRoles().contains(userRole.getRole())){ - String tenantCode = userRole.getTenantId() == null ? this.tenantScope.getDefaultTenantCode() : tenants.stream().filter(x-> x.getId().equals(userRole.getTenantId())).map(TenantEntity::getCode).findFirst().orElse(null); - if (!this.conventionService.isNullOrEmpty(tenantCode)) this.keycloakService.addUserToTenantRoleGroup(userCredential.getExternalId(), tenantCode, userRole.getRole()); + private void syncKeycloakRoles(UUID userId) throws InvalidApplicationException { + try { + this.entityManager.disableTenantFilters(); + List userCredentials = this.queryFactory.query(UserCredentialQuery.class).disableTracking().userIds(userId).collect(); + List userRoles = this.queryFactory.query(UserRoleQuery.class).disableTracking().userIds(userId).collect(); + List tenants = this.queryFactory.query(TenantQuery.class).disableTracking().ids(userRoles.stream().map(TenantScopedBaseEntity::getTenantId).filter(Objects::nonNull).toList()).collect(); + + for (UserCredentialEntity userCredential : userCredentials){ + this.keycloakService.removeFromAllGroups(userCredential.getExternalId()); + for (UserRoleEntity userRole : userRoles) { + if (this.authorizationProperties.getAllowedGlobalRoles().contains(userRole.getRole())){ + this.keycloakService.addUserToGlobalRoleGroup(userCredential.getExternalId(), userRole.getRole()); + } else if (this.authorizationProperties.getAllowedTenantRoles().contains(userRole.getRole())){ + String tenantCode = userRole.getTenantId() == null ? this.tenantScope.getDefaultTenantCode() : tenants.stream().filter(x-> x.getId().equals(userRole.getTenantId())).map(TenantEntity::getCode).findFirst().orElse(null); + if (!this.conventionService.isNullOrEmpty(tenantCode)) this.keycloakService.addUserToTenantRoleGroup(userCredential.getExternalId(), tenantCode, userRole.getRole()); + } } } + + } finally { + this.entityManager.reloadTenantFilters(); } } private void mergeNewUserToOld(UserEntity newUser, UserEntity oldUser) throws IOException, InvalidApplicationException { - List userCredentials = this.queryFactory.query(UserCredentialQuery.class).userIds(oldUser.getId()).collect(); - for (UserCredentialEntity userCredential : userCredentials){ - userCredential.setUserId(newUser.getId()); - this.entityManager.merge(userCredential); - } - - List userContacts = this.queryFactory.query(UserContactInfoQuery.class).userIds(oldUser.getId()).collect(); - UserContactInfoQuery newUserContactInfoQuery = this.queryFactory.query(UserContactInfoQuery.class).userIds(newUser.getId()); - newUserContactInfoQuery.setOrder(new Ordering().addDescending(UserContactInfo._ordinal)); - UserContactInfoEntity newUserContactInfo = newUserContactInfoQuery.first(); - int ordinal = newUserContactInfo == null ? 0 : newUserContactInfo.getOrdinal() + 1; - for (UserContactInfoEntity userContactInfo : userContacts){ - userContactInfo.setUserId(newUser.getId()); - userContactInfo.setOrdinal(ordinal); - this.entityManager.merge(userContactInfo); - ordinal++; - } - - List userRoles = this.queryFactory.query(UserRoleQuery.class).userIds(oldUser.getId()).collect(); - List newUserRoles = this.queryFactory.query(UserRoleQuery.class).userIds(newUser.getId()).collect(); - List rolesToDelete = new ArrayList<>(); - for (UserRoleEntity userRole : userRoles){ - if (newUserRoles.stream().anyMatch(x-> x.getRole().equals(userRole.getRole()))) { - rolesToDelete.add(userRole); - } else { - userRole.setUserId(newUser.getId()); - this.entityManager.merge(userRole); + try { + this.entityManager.disableTenantFilters(); + List userCredentials = this.queryFactory.query(UserCredentialQuery.class).userIds(oldUser.getId()).collect(); + for (UserCredentialEntity userCredential : userCredentials) { + userCredential.setUserId(newUser.getId()); + this.entityManager.merge(userCredential); } - } - this.deleterFactory.deleter(UserRoleDeleter.class).delete(rolesToDelete); - List userSettings = this.queryFactory.query(UserSettingsQuery.class).entityIds(oldUser.getId()).collect(); - List newUserSettings = this.queryFactory.query(UserSettingsQuery.class).entityIds(newUser.getId()).collect(); - List userSettingsToDelete = new ArrayList<>(); - for (UserSettingsEntity userSetting : userSettings){ - if (newUserSettings.stream().anyMatch(x-> x.getKey().equals(userSetting.getKey()))) { - userSettingsToDelete.add(userSetting); - } else { - userSetting.setEntityId(newUser.getId()); - this.entityManager.merge(userSetting); + List userContacts = this.queryFactory.query(UserContactInfoQuery.class).userIds(oldUser.getId()).collect(); + UserContactInfoQuery newUserContactInfoQuery = this.queryFactory.query(UserContactInfoQuery.class).userIds(newUser.getId()); + newUserContactInfoQuery.setOrder(new Ordering().addDescending(UserContactInfo._ordinal)); + UserContactInfoEntity newUserContactInfo = newUserContactInfoQuery.first(); + int ordinal = newUserContactInfo == null ? 0 : newUserContactInfo.getOrdinal() + 1; + for (UserContactInfoEntity userContactInfo : userContacts) { + userContactInfo.setUserId(newUser.getId()); + userContactInfo.setOrdinal(ordinal); + this.entityManager.merge(userContactInfo); + ordinal++; } - } - this.deleterFactory.deleter(UserSettingsSettingsDeleter.class).delete(userSettingsToDelete); - List tags = this.queryFactory.query(TagQuery.class).createdByIds(oldUser.getId()).collect(); - for (TagEntity tag : tags){ - tag.setCreatedById(newUser.getId()); - this.entityManager.merge(tag); - } + List userRoles = this.queryFactory.query(UserRoleQuery.class).userIds(oldUser.getId()).collect(); + List newUserRoles = this.queryFactory.query(UserRoleQuery.class).userIds(newUser.getId()).collect(); + List rolesToDelete = new ArrayList<>(); + for (UserRoleEntity userRole : userRoles) { + if (newUserRoles.stream().anyMatch(x -> Objects.equals(x.getTenantId(), userRole.getTenantId()) && x.getRole().equals(userRole.getRole()))) { + rolesToDelete.add(userRole); + } else { + userRole.setUserId(newUser.getId()); + this.entityManager.merge(userRole); + } + } + this.deleterFactory.deleter(UserRoleDeleter.class).delete(rolesToDelete); - List storageFiles = this.queryFactory.query(StorageFileQuery.class).ownerIds(oldUser.getId()).collect(); - for (StorageFileEntity storageFile : storageFiles){ - storageFile.setOwnerId(newUser.getId()); - this.entityManager.merge(storageFile); - } + List userTenantUsers = this.queryFactory.query(TenantUserQuery.class).userIds(oldUser.getId()).collect(); + List newTenantUsers = this.queryFactory.query(TenantUserQuery.class).userIds(newUser.getId()).collect(); + List tenantUsersToDelete = new ArrayList<>(); + for (TenantUserEntity userTenantUser : userTenantUsers) { + if (newTenantUsers.stream().anyMatch(x -> Objects.equals(x.getTenantId(), userTenantUser.getTenantId()))) { + tenantUsersToDelete.add(userTenantUser); + } else { + userTenantUser.setUserId(newUser.getId()); + this.entityManager.merge(userTenantUser); + } + } + this.deleterFactory.deleter(TenantUserDeleter.class).delete(tenantUsersToDelete); - List locks = this.queryFactory.query(LockQuery.class).lockedByIds(oldUser.getId()).collect(); - for (LockEntity lock : locks){ - lock.setLockedBy(newUser.getId()); - this.entityManager.merge(lock); - } + List userSettings = this.queryFactory.query(UserSettingsQuery.class).entityIds(oldUser.getId()).collect(); + List newUserSettings = this.queryFactory.query(UserSettingsQuery.class).entityIds(newUser.getId()).collect(); + List userSettingsToDelete = new ArrayList<>(); + for (UserSettingsEntity userSetting : userSettings) { + if (newUserSettings.stream().anyMatch(x -> Objects.equals(x.getTenantId(), userSetting.getTenantId()) &&x.getKey().equals(userSetting.getKey()))) { + userSettingsToDelete.add(userSetting); + } else { + userSetting.setEntityId(newUser.getId()); + this.entityManager.merge(userSetting); + } + } + this.deleterFactory.deleter(UserSettingsSettingsDeleter.class).delete(userSettingsToDelete); - List dmpUsers = this.queryFactory.query(DmpUserQuery.class).userIds(oldUser.getId()).collect(); - for (DmpUserEntity dmpUser : dmpUsers){ - dmpUser.setUserId(newUser.getId()); - this.entityManager.merge(dmpUser); - } + List tags = this.queryFactory.query(TagQuery.class).createdByIds(oldUser.getId()).collect(); + for (TagEntity tag : tags) { + tag.setCreatedById(newUser.getId()); + this.entityManager.merge(tag); + } - List userDescriptionTemplates = this.queryFactory.query(UserDescriptionTemplateQuery.class).userIds(oldUser.getId()).collect(); - for (UserDescriptionTemplateEntity userDescriptionTemplate : userDescriptionTemplates){ - userDescriptionTemplate.setUserId(newUser.getId()); - this.entityManager.merge(userDescriptionTemplate); - } + List storageFiles = this.queryFactory.query(StorageFileQuery.class).ownerIds(oldUser.getId()).collect(); + for (StorageFileEntity storageFile : storageFiles) { + storageFile.setOwnerId(newUser.getId()); + this.entityManager.merge(storageFile); + } - List dmps = this.queryFactory.query(DmpQuery.class).creatorIds(oldUser.getId()).collect(); - for (DmpEntity dmp : dmps){ - dmp.setCreatorId(newUser.getId()); - this.entityManager.merge(dmp); - } + List locks = this.queryFactory.query(LockQuery.class).lockedByIds(oldUser.getId()).collect(); + for (LockEntity lock : locks) { + lock.setLockedBy(newUser.getId()); + this.entityManager.merge(lock); + } - List descriptions = this.queryFactory.query(DescriptionQuery.class).createdByIds(oldUser.getId()).collect(); - for (DescriptionEntity description : descriptions){ - description.setCreatedById(newUser.getId()); - this.entityManager.merge(description); - } - - oldUser.setIsActive(IsActive.Inactive); + List dmpUsers = this.queryFactory.query(DmpUserQuery.class).userIds(oldUser.getId()).collect(); + for (DmpUserEntity dmpUser : dmpUsers) { + dmpUser.setUserId(newUser.getId()); + this.entityManager.merge(dmpUser); + } - this.entityManager.merge(oldUser); - - this.entityManager.flush(); + List userDescriptionTemplates = this.queryFactory.query(UserDescriptionTemplateQuery.class).userIds(oldUser.getId()).collect(); + for (UserDescriptionTemplateEntity userDescriptionTemplate : userDescriptionTemplates) { + userDescriptionTemplate.setUserId(newUser.getId()); + this.entityManager.merge(userDescriptionTemplate); + } - for (DmpEntity dmp : dmps){ - this.elasticService.persistDmp(dmp); - } + List dmps = this.queryFactory.query(DmpQuery.class).creatorIds(oldUser.getId()).collect(); + for (DmpEntity dmp : dmps) { + dmp.setCreatorId(newUser.getId()); + this.entityManager.merge(dmp); + } - for (DescriptionEntity description : descriptions){ - this.elasticService.persistDescription(description); - } + List descriptions = this.queryFactory.query(DescriptionQuery.class).createdByIds(oldUser.getId()).collect(); + for (DescriptionEntity description : descriptions) { + description.setCreatedById(newUser.getId()); + this.entityManager.merge(description); + } - for (DmpEntity dmp : dmps){ - this.annotationEntityTouchedIntegrationEventHandler.handleDmp(dmp.getId()); - } + oldUser.setIsActive(IsActive.Inactive); - for (DescriptionEntity description : descriptions){ - this.annotationEntityTouchedIntegrationEventHandler.handleDescription(description.getId()); + this.entityManager.merge(oldUser); + + this.entityManager.flush(); + + for (DmpEntity dmp : dmps) { + this.elasticService.persistDmp(dmp); + } + + for (DescriptionEntity description : descriptions) { + this.elasticService.persistDescription(description); + } + + for (DmpEntity dmp : dmps) { + this.annotationEntityTouchedIntegrationEventHandler.handleDmp(dmp.getId()); + } + + for (DescriptionEntity description : descriptions) { + this.annotationEntityTouchedIntegrationEventHandler.handleDescription(description.getId()); + } + } finally { + this.entityManager.reloadTenantFilters(); } } diff --git a/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor.component.html b/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor.component.html index b2bd9df84..5fff60e2c 100644 --- a/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor.component.html +++ b/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor.component.html @@ -111,7 +111,7 @@ add{{'DMP-EDITOR.ACTIONS.ADD-DESCRIPTION-IN-SECTION' | translate}} - + diff --git a/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/userremoval/UserRemovalIntegrationEventHandlerImpl.java b/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/userremoval/UserRemovalIntegrationEventHandlerImpl.java index 35b51d981..1ecfcd781 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/userremoval/UserRemovalIntegrationEventHandlerImpl.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/userremoval/UserRemovalIntegrationEventHandlerImpl.java @@ -42,7 +42,6 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr private final ErrorThesaurusProperties errors; private final MessageSource messageSource; - private final QueryFactory queryFactory; private final TenantScope tenantScope; private final CurrentPrincipalResolver currentPrincipalResolver; private final ClaimExtractorProperties claimExtractorProperties; @@ -54,12 +53,11 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr public UserRemovalIntegrationEventHandlerImpl( JsonHandlingService jsonHandlingService, ErrorThesaurusProperties errors, - MessageSource messageSource, QueryFactory queryFactory, TenantScope tenantScope, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, UserRemovalConsistencyHandler userRemovalConsistencyHandler, UserService userService, AuditService auditService, TenantEntityManager tenantEntityManager + MessageSource messageSource, TenantScope tenantScope, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, UserRemovalConsistencyHandler userRemovalConsistencyHandler, UserService userService, AuditService auditService, TenantEntityManager tenantEntityManager ) { this.jsonHandlingService = jsonHandlingService; this.errors = errors; this.messageSource = messageSource; - this.queryFactory = queryFactory; this.tenantScope = tenantScope; this.currentPrincipalResolver = currentPrincipalResolver; this.claimExtractorProperties = claimExtractorProperties; @@ -81,29 +79,21 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr EventProcessingStatus status = EventProcessingStatus.Success; try { - if (this.tenantScope.isMultitenant() && properties.getTenantId() != null) { - TenantEntity tenant = queryFactory.query(TenantQuery.class).disableTracking().ids(properties.getTenantId()).firstAs(new BaseFieldSet().ensure(Tenant._id).ensure(Tenant._code)); - if (tenant == null) { - logger.error("missing tenant from event message"); - return EventProcessingStatus.Error; - } - this.tenantScope.setTempTenant(tenantEntityManager, properties.getTenantId(), tenant.getCode()); - } else if (this.tenantScope.isMultitenant()) { -// logger.error("missing tenant from event message"); -// return EventProcessingStatus.Error; - this.tenantScope.setTempTenant(tenantEntityManager, null, this.tenantScope.getDefaultTenantCode()); - } - currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties)); - if (!(userRemovalConsistencyHandler.isConsistent(new UserRemovalConsistencyPredicates(event.getUserId())))) { - status = EventProcessingStatus.Postponed; - currentPrincipalResolver.pop(); - tenantScope.removeTempTenant(this.tenantEntityManager); - return status; - } - - userService.deleteAndSave(event.getUserId()); + try{ + this.tenantEntityManager.disableTenantFilters(); + if (!(userRemovalConsistencyHandler.isConsistent(new UserRemovalConsistencyPredicates(event.getUserId())))) { + status = EventProcessingStatus.Postponed; + currentPrincipalResolver.pop(); + tenantScope.removeTempTenant(this.tenantEntityManager); + return status; + } + + userService.deleteAndSave(event.getUserId()); + } finally { + this.tenantEntityManager.reloadTenantFilters(); + } auditService.track(AuditableAction.User_Delete, Map.ofEntries( new AbstractMap.SimpleEntry("id", event.getUserId()) @@ -114,11 +104,6 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex); } finally { currentPrincipalResolver.pop(); - try { - tenantScope.removeTempTenant(this.tenantEntityManager); - } catch (InvalidApplicationException e) { - logger.error( e.getMessage(), e); - } } return status; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/usertouched/UserTouchedIntegrationEventHandlerImpl.java b/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/usertouched/UserTouchedIntegrationEventHandlerImpl.java index db45e748b..2f08f5386 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/usertouched/UserTouchedIntegrationEventHandlerImpl.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/usertouched/UserTouchedIntegrationEventHandlerImpl.java @@ -71,23 +71,14 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr EventProcessingStatus status = EventProcessingStatus.Success; try { - if (this.tenantScope.isMultitenant() && properties.getTenantId() != null) { - TenantEntity tenant = queryFactory.query(TenantQuery.class).disableTracking().ids(properties.getTenantId()).firstAs(new BaseFieldSet().ensure(Tenant._id).ensure(Tenant._code)); - if (tenant == null) { - logger.error("missing tenant from event message"); - return EventProcessingStatus.Error; - } - this.tenantScope.setTempTenant(tenantEntityManager, properties.getTenantId(), tenant.getCode()); - } else if (this.tenantScope.isMultitenant()) { -// logger.error("missing tenant from event message"); -// return EventProcessingStatus.Error; - this.tenantScope.setTempTenant(tenantEntityManager, null, this.tenantScope.getDefaultTenantCode()); - } currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties)); - - userService.persist(event, null); - + try { + this.tenantEntityManager.disableTenantFilters(); + userService.persist(event, null); + } finally { + this.tenantEntityManager.reloadTenantFilters(); + } auditService.track(AuditableAction.User_Persist, Map.ofEntries( new AbstractMap.SimpleEntry("model", event) )); @@ -97,11 +88,6 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex); } finally { currentPrincipalResolver.pop(); - try { - tenantScope.removeTempTenant(this.tenantEntityManager); - } catch (InvalidApplicationException e) { - logger.error( e.getMessage(), e); - } } return status; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/user/UserServiceImpl.java b/notification-service/notification/src/main/java/gr/cite/notification/service/user/UserServiceImpl.java index 86008e739..43af4ed3f 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/user/UserServiceImpl.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/user/UserServiceImpl.java @@ -88,7 +88,7 @@ public class UserServiceImpl implements UserService { public User persist(UserTouchedIntegrationEvent model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException { logger.debug(new MapLogEntry("persisting user").And("model", model).And("fields", fields)); -// this.authorizationService.authorizeAtLeastOneForce(model.getId() != null ? List.of(new OwnedResource(model.getId())) : null, Permission.EditUser); + this.authorizationService.authorize(Permission.EditUser); Boolean isValid = this.conventionService.isValidGuid(model.getId());