Added removal events when the entities (users / tenants) are found inactive on event maintenance tasks controller
This commit is contained in:
parent
6eed99c1cc
commit
fcda984d7e
|
@ -6,8 +6,10 @@ import eu.eudat.commons.enums.IsActive;
|
||||||
import eu.eudat.data.TenantEntity;
|
import eu.eudat.data.TenantEntity;
|
||||||
import eu.eudat.data.TenantEntityManager;
|
import eu.eudat.data.TenantEntityManager;
|
||||||
import eu.eudat.data.UserEntity;
|
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.TenantTouchedIntegrationEvent;
|
||||||
import eu.eudat.integrationevent.outbox.tenanttouched.TenantTouchedIntegrationEventHandler;
|
import eu.eudat.integrationevent.outbox.tenanttouched.TenantTouchedIntegrationEventHandler;
|
||||||
|
import eu.eudat.integrationevent.outbox.userremoval.UserRemovalIntegrationEventHandler;
|
||||||
import eu.eudat.integrationevent.outbox.usertouched.UserTouchedIntegrationEventHandler;
|
import eu.eudat.integrationevent.outbox.usertouched.UserTouchedIntegrationEventHandler;
|
||||||
import eu.eudat.query.TenantQuery;
|
import eu.eudat.query.TenantQuery;
|
||||||
import eu.eudat.query.UserQuery;
|
import eu.eudat.query.UserQuery;
|
||||||
|
@ -44,8 +46,12 @@ public class MaintenanceController {
|
||||||
|
|
||||||
private final UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler;
|
private final UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler;
|
||||||
|
|
||||||
|
private final UserRemovalIntegrationEventHandler userRemovalIntegrationEventHandler;
|
||||||
|
|
||||||
private final TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler;
|
private final TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler;
|
||||||
|
|
||||||
|
private final TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public MaintenanceController(
|
public MaintenanceController(
|
||||||
AuthorizationService authorizationService,
|
AuthorizationService authorizationService,
|
||||||
|
@ -54,14 +60,18 @@ public class MaintenanceController {
|
||||||
QueryFactory queryFactory,
|
QueryFactory queryFactory,
|
||||||
TenantEntityManager entityManager,
|
TenantEntityManager entityManager,
|
||||||
UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler,
|
UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler,
|
||||||
TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler) {
|
UserRemovalIntegrationEventHandler userRemovalIntegrationEventHandler,
|
||||||
|
TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler,
|
||||||
|
TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler) {
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
this.elasticService = elasticService;
|
this.elasticService = elasticService;
|
||||||
this.auditService = auditService;
|
this.auditService = auditService;
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
this.userTouchedIntegrationEventHandler = userTouchedIntegrationEventHandler;
|
this.userTouchedIntegrationEventHandler = userTouchedIntegrationEventHandler;
|
||||||
|
this.userRemovalIntegrationEventHandler = userRemovalIntegrationEventHandler;
|
||||||
this.tenantTouchedIntegrationEventHandler = tenantTouchedIntegrationEventHandler;
|
this.tenantTouchedIntegrationEventHandler = tenantTouchedIntegrationEventHandler;
|
||||||
|
this.tenantRemovalIntegrationEventHandler = tenantRemovalIntegrationEventHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/index/elastic"})
|
@RequestMapping(method = RequestMethod.POST, value = {"/index/elastic"})
|
||||||
|
@ -92,13 +102,19 @@ public class MaintenanceController {
|
||||||
this.authorizationService.authorizeForce(Permission.ManageQueueEvents);
|
this.authorizationService.authorizeForce(Permission.ManageQueueEvents);
|
||||||
|
|
||||||
this.entityManager.disableTenantFilters();
|
this.entityManager.disableTenantFilters();
|
||||||
UserQuery userQuery = queryFactory.query(UserQuery.class).isActive(IsActive.Active);
|
UserQuery userQuery = queryFactory.query(UserQuery.class);
|
||||||
List<UserEntity> users = userQuery.collect();
|
userQuery.isActive(IsActive.Active);
|
||||||
|
List<UserEntity> activeUsers = userQuery.collect();
|
||||||
|
userQuery.isActive(IsActive.Inactive);
|
||||||
|
List<UserEntity> inactiveUsers = userQuery.collect();
|
||||||
this.entityManager.enableTenantFilters();
|
this.entityManager.enableTenantFilters();
|
||||||
|
|
||||||
for(UserEntity user : users)
|
for(UserEntity user : activeUsers)
|
||||||
this.userTouchedIntegrationEventHandler.handle(user.getId());
|
this.userTouchedIntegrationEventHandler.handle(user.getId());
|
||||||
|
|
||||||
|
for(UserEntity user : inactiveUsers)
|
||||||
|
this.userRemovalIntegrationEventHandler.handle(user.getId());
|
||||||
|
|
||||||
this.auditService.track(AuditableAction.Maintenance_SendUserTouchEvents);
|
this.auditService.track(AuditableAction.Maintenance_SendUserTouchEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,17 +124,24 @@ public class MaintenanceController {
|
||||||
this.authorizationService.authorizeForce(Permission.ManageQueueEvents);
|
this.authorizationService.authorizeForce(Permission.ManageQueueEvents);
|
||||||
|
|
||||||
this.entityManager.disableTenantFilters();
|
this.entityManager.disableTenantFilters();
|
||||||
TenantQuery tenantQuery = queryFactory.query(TenantQuery.class).isActive(IsActive.Active);
|
TenantQuery tenantQuery = queryFactory.query(TenantQuery.class);
|
||||||
List<TenantEntity> tenants = tenantQuery.collect();
|
tenantQuery.isActive(IsActive.Active);
|
||||||
|
List<TenantEntity> activeTenants = tenantQuery.collect();
|
||||||
|
tenantQuery.isActive(IsActive.Inactive);
|
||||||
|
List<TenantEntity> inactiveTenants = tenantQuery.collect();
|
||||||
this.entityManager.enableTenantFilters();
|
this.entityManager.enableTenantFilters();
|
||||||
|
|
||||||
for (TenantEntity tenant : tenants) {
|
for (TenantEntity tenant : activeTenants) {
|
||||||
TenantTouchedIntegrationEvent event = new TenantTouchedIntegrationEvent();
|
TenantTouchedIntegrationEvent event = new TenantTouchedIntegrationEvent();
|
||||||
event.setId(tenant.getId());
|
event.setId(tenant.getId());
|
||||||
event.setCode(tenant.getCode());
|
event.setCode(tenant.getCode());
|
||||||
this.tenantTouchedIntegrationEventHandler.handle(event);
|
this.tenantTouchedIntegrationEventHandler.handle(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (TenantEntity tenant : inactiveTenants) {
|
||||||
|
this.tenantRemovalIntegrationEventHandler.handle(tenant.getId());
|
||||||
|
}
|
||||||
|
|
||||||
this.auditService.track(AuditableAction.Maintenance_SendTenantTouchEvents);
|
this.auditService.track(AuditableAction.Maintenance_SendTenantTouchEvents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue