Added removal events when the entities (users / tenants) are found inactive on event maintenance tasks controller

This commit is contained in:
Thomas Georgios Giannos 2024-04-04 14:33:04 +03:00
parent 6eed99c1cc
commit fcda984d7e
1 changed files with 30 additions and 7 deletions

View File

@ -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<UserEntity> users = userQuery.collect();
UserQuery userQuery = queryFactory.query(UserQuery.class);
userQuery.isActive(IsActive.Active);
List<UserEntity> activeUsers = userQuery.collect();
userQuery.isActive(IsActive.Inactive);
List<UserEntity> 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<TenantEntity> tenants = tenantQuery.collect();
TenantQuery tenantQuery = queryFactory.query(TenantQuery.class);
tenantQuery.isActive(IsActive.Active);
List<TenantEntity> activeTenants = tenantQuery.collect();
tenantQuery.isActive(IsActive.Inactive);
List<TenantEntity> 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);
}
}