From fcda984d7eb3731fa5dfc2101949996e0af508db Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Thu, 4 Apr 2024 14:33:04 +0300 Subject: [PATCH] Added removal events when the entities (users / tenants) are found inactive on event maintenance tasks controller --- .../controllers/MaintenanceController.java | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/MaintenanceController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/MaintenanceController.java index 049cbb992..5db770c5d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/MaintenanceController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/MaintenanceController.java @@ -6,8 +6,10 @@ import eu.eudat.commons.enums.IsActive; import eu.eudat.data.TenantEntity; import eu.eudat.data.TenantEntityManager; import eu.eudat.data.UserEntity; +import eu.eudat.integrationevent.outbox.tenantremoval.TenantRemovalIntegrationEventHandler; import eu.eudat.integrationevent.outbox.tenanttouched.TenantTouchedIntegrationEvent; import eu.eudat.integrationevent.outbox.tenanttouched.TenantTouchedIntegrationEventHandler; +import eu.eudat.integrationevent.outbox.userremoval.UserRemovalIntegrationEventHandler; import eu.eudat.integrationevent.outbox.usertouched.UserTouchedIntegrationEventHandler; import eu.eudat.query.TenantQuery; import eu.eudat.query.UserQuery; @@ -44,8 +46,12 @@ public class MaintenanceController { private final UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler; + private final UserRemovalIntegrationEventHandler userRemovalIntegrationEventHandler; + private final TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler; + private final TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler; + @Autowired public MaintenanceController( AuthorizationService authorizationService, @@ -54,14 +60,18 @@ public class MaintenanceController { QueryFactory queryFactory, TenantEntityManager entityManager, UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler, - TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler) { + UserRemovalIntegrationEventHandler userRemovalIntegrationEventHandler, + TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler, + TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler) { this.authorizationService = authorizationService; this.elasticService = elasticService; this.auditService = auditService; this.queryFactory = queryFactory; this.entityManager = entityManager; this.userTouchedIntegrationEventHandler = userTouchedIntegrationEventHandler; + this.userRemovalIntegrationEventHandler = userRemovalIntegrationEventHandler; this.tenantTouchedIntegrationEventHandler = tenantTouchedIntegrationEventHandler; + this.tenantRemovalIntegrationEventHandler = tenantRemovalIntegrationEventHandler; } @RequestMapping(method = RequestMethod.POST, value = {"/index/elastic"}) @@ -92,13 +102,19 @@ public class MaintenanceController { this.authorizationService.authorizeForce(Permission.ManageQueueEvents); this.entityManager.disableTenantFilters(); - UserQuery userQuery = queryFactory.query(UserQuery.class).isActive(IsActive.Active); - List users = userQuery.collect(); + UserQuery userQuery = queryFactory.query(UserQuery.class); + userQuery.isActive(IsActive.Active); + List activeUsers = userQuery.collect(); + userQuery.isActive(IsActive.Inactive); + List inactiveUsers = userQuery.collect(); this.entityManager.enableTenantFilters(); - for(UserEntity user : users) + for(UserEntity user : activeUsers) this.userTouchedIntegrationEventHandler.handle(user.getId()); + for(UserEntity user : inactiveUsers) + this.userRemovalIntegrationEventHandler.handle(user.getId()); + this.auditService.track(AuditableAction.Maintenance_SendUserTouchEvents); } @@ -108,17 +124,24 @@ public class MaintenanceController { this.authorizationService.authorizeForce(Permission.ManageQueueEvents); this.entityManager.disableTenantFilters(); - TenantQuery tenantQuery = queryFactory.query(TenantQuery.class).isActive(IsActive.Active); - List tenants = tenantQuery.collect(); + TenantQuery tenantQuery = queryFactory.query(TenantQuery.class); + tenantQuery.isActive(IsActive.Active); + List activeTenants = tenantQuery.collect(); + tenantQuery.isActive(IsActive.Inactive); + List inactiveTenants = tenantQuery.collect(); this.entityManager.enableTenantFilters(); - for (TenantEntity tenant : tenants) { + for (TenantEntity tenant : activeTenants) { TenantTouchedIntegrationEvent event = new TenantTouchedIntegrationEvent(); event.setId(tenant.getId()); event.setCode(tenant.getCode()); this.tenantTouchedIntegrationEventHandler.handle(event); } + for (TenantEntity tenant : inactiveTenants) { + this.tenantRemovalIntegrationEventHandler.handle(tenant.getId()); + } + this.auditService.track(AuditableAction.Maintenance_SendTenantTouchEvents); } }