Added maintenance tasks for sending touch events (users and tenants)
This commit is contained in:
parent
ea6ea25116
commit
bc44887675
|
@ -145,6 +145,8 @@ public class AuditableAction {
|
||||||
|
|
||||||
public static final EventId Maintenance_GenerateElastic = new EventId(220000, "Maintenance_GenerateElastic");
|
public static final EventId Maintenance_GenerateElastic = new EventId(220000, "Maintenance_GenerateElastic");
|
||||||
public static final EventId Maintenance_ClearElastic = new EventId(230000, "Maintenance_ClearElastic");
|
public static final EventId Maintenance_ClearElastic = new EventId(230000, "Maintenance_ClearElastic");
|
||||||
|
public static final EventId Maintenance_SendUserTouchEvents = new EventId(230001, "Maintenance_SendUserTouchEvents");
|
||||||
|
public static final EventId Maintenance_SendTenantTouchEvents = new EventId(230002, "Maintenance_SendTenantTouchEvents");
|
||||||
|
|
||||||
public static final EventId Principal_Lookup = new EventId(240000, "Principal_Lookup");
|
public static final EventId Principal_Lookup = new EventId(240000, "Principal_Lookup");
|
||||||
public static final EventId Principal_MyTenants = new EventId(240001, "Principal_MyTenants");
|
public static final EventId Principal_MyTenants = new EventId(240001, "Principal_MyTenants");
|
||||||
|
|
|
@ -22,6 +22,8 @@ public final class Permission {
|
||||||
public static String PublicBrowseReferenceType = "PublicBrowseReferenceType";
|
public static String PublicBrowseReferenceType = "PublicBrowseReferenceType";
|
||||||
//Elastic
|
//Elastic
|
||||||
public static String ManageElastic = "ManageElastic";
|
public static String ManageElastic = "ManageElastic";
|
||||||
|
//Queue Events
|
||||||
|
public static String ManageQueueEvents = "ManageQueueEvents";
|
||||||
|
|
||||||
|
|
||||||
//Deposit
|
//Deposit
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package eu.eudat.integrationevent.outbox.tenanttouched;
|
package eu.eudat.integrationevent.outbox.tenanttouched;
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
|
||||||
|
|
||||||
public interface TenantTouchedIntegrationEventHandler {
|
public interface TenantTouchedIntegrationEventHandler {
|
||||||
|
|
||||||
void handle(TenantTouchedIntegrationEvent event);
|
void handle(TenantTouchedIntegrationEvent event);
|
||||||
|
|
|
@ -1,18 +1,24 @@
|
||||||
package eu.eudat.integrationevent.outbox.tenanttouched;
|
package eu.eudat.integrationevent.outbox.tenanttouched;
|
||||||
|
|
||||||
import eu.eudat.commons.scope.tenant.TenantScope;
|
|
||||||
import eu.eudat.integrationevent.outbox.OutboxIntegrationEvent;
|
import eu.eudat.integrationevent.outbox.OutboxIntegrationEvent;
|
||||||
import eu.eudat.integrationevent.outbox.OutboxService;
|
import eu.eudat.integrationevent.outbox.OutboxService;
|
||||||
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Component("outboxtenanttouchedintegrationeventhandler")
|
||||||
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
public class TenantTouchedIntegrationEventHandlerImpl implements TenantTouchedIntegrationEventHandler {
|
public class TenantTouchedIntegrationEventHandlerImpl implements TenantTouchedIntegrationEventHandler {
|
||||||
|
|
||||||
private final OutboxService outboxService;
|
private final OutboxService outboxService;
|
||||||
|
|
||||||
public TenantTouchedIntegrationEventHandlerImpl(OutboxService outboxService) {
|
public TenantTouchedIntegrationEventHandlerImpl(OutboxService outboxService) {
|
||||||
this.outboxService = outboxService;
|
this.outboxService = outboxService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(TenantTouchedIntegrationEvent event) {
|
public void handle(TenantTouchedIntegrationEvent event) {
|
||||||
OutboxIntegrationEvent message = new OutboxIntegrationEvent();
|
OutboxIntegrationEvent message = new OutboxIntegrationEvent();
|
||||||
message.setMessageId(UUID.randomUUID());
|
message.setMessageId(UUID.randomUUID());
|
||||||
|
|
|
@ -2,32 +2,67 @@ package eu.eudat.controllers;
|
||||||
|
|
||||||
import eu.eudat.audit.AuditableAction;
|
import eu.eudat.audit.AuditableAction;
|
||||||
import eu.eudat.authorization.Permission;
|
import eu.eudat.authorization.Permission;
|
||||||
|
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.tenanttouched.TenantTouchedIntegrationEvent;
|
||||||
|
import eu.eudat.integrationevent.outbox.tenanttouched.TenantTouchedIntegrationEventHandler;
|
||||||
|
import eu.eudat.integrationevent.outbox.usertouched.UserTouchedIntegrationEventHandler;
|
||||||
|
import eu.eudat.query.TenantQuery;
|
||||||
|
import eu.eudat.query.UserQuery;
|
||||||
import eu.eudat.service.elastic.ElasticService;
|
import eu.eudat.service.elastic.ElasticService;
|
||||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||||
import gr.cite.tools.auditing.AuditService;
|
import gr.cite.tools.auditing.AuditService;
|
||||||
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.management.InvalidApplicationException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(path = "api/maintenance")
|
@RequestMapping(path = "api/maintenance")
|
||||||
public class MaintenanceController {
|
public class MaintenanceController {
|
||||||
|
|
||||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(MaintenanceController.class));
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(MaintenanceController.class));
|
||||||
|
|
||||||
private final AuthorizationService authorizationService;
|
private final AuthorizationService authorizationService;
|
||||||
|
|
||||||
private final ElasticService elasticService;
|
private final ElasticService elasticService;
|
||||||
|
|
||||||
private final AuditService auditService;
|
private final AuditService auditService;
|
||||||
|
|
||||||
@Autowired
|
private final QueryFactory queryFactory;
|
||||||
public MaintenanceController(AuthorizationService authorizationService, ElasticService elasticService, AuditService auditService) {
|
|
||||||
this.authorizationService = authorizationService;
|
|
||||||
this.elasticService = elasticService;
|
|
||||||
this.auditService = auditService;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
private final TenantEntityManager entityManager;
|
||||||
|
|
||||||
|
private final UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler;
|
||||||
|
|
||||||
|
private final TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public MaintenanceController(
|
||||||
|
AuthorizationService authorizationService,
|
||||||
|
ElasticService elasticService,
|
||||||
|
AuditService auditService,
|
||||||
|
QueryFactory queryFactory,
|
||||||
|
TenantEntityManager entityManager,
|
||||||
|
UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler,
|
||||||
|
TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler) {
|
||||||
|
this.authorizationService = authorizationService;
|
||||||
|
this.elasticService = elasticService;
|
||||||
|
this.auditService = auditService;
|
||||||
|
this.queryFactory = queryFactory;
|
||||||
|
this.entityManager = entityManager;
|
||||||
|
this.userTouchedIntegrationEventHandler = userTouchedIntegrationEventHandler;
|
||||||
|
this.tenantTouchedIntegrationEventHandler = tenantTouchedIntegrationEventHandler;
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/index/elastic"})
|
@RequestMapping(method = RequestMethod.POST, value = {"/index/elastic"})
|
||||||
public void generateIndex() throws Exception {
|
public void generateIndex() throws Exception {
|
||||||
|
@ -36,6 +71,7 @@ public class MaintenanceController {
|
||||||
|
|
||||||
elasticService.resetDmpIndex();
|
elasticService.resetDmpIndex();
|
||||||
elasticService.resetDescriptionIndex();
|
elasticService.resetDescriptionIndex();
|
||||||
|
|
||||||
this.auditService.track(AuditableAction.Maintenance_GenerateElastic);
|
this.auditService.track(AuditableAction.Maintenance_GenerateElastic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,9 +79,46 @@ public class MaintenanceController {
|
||||||
public void clearIndex() throws Exception {
|
public void clearIndex() throws Exception {
|
||||||
logger.debug("clear elastic");
|
logger.debug("clear elastic");
|
||||||
this.authorizationService.authorizeForce(Permission.ManageElastic);
|
this.authorizationService.authorizeForce(Permission.ManageElastic);
|
||||||
|
|
||||||
elasticService.deleteDescriptionIndex();
|
elasticService.deleteDescriptionIndex();
|
||||||
elasticService.deleteDmpIndex();
|
elasticService.deleteDmpIndex();
|
||||||
|
|
||||||
this.auditService.track(AuditableAction.Maintenance_ClearElastic);
|
this.auditService.track(AuditableAction.Maintenance_ClearElastic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.DELETE, value = {"/events/users/touch"})
|
||||||
|
public void sendUserTouchEvents() throws InvalidApplicationException {
|
||||||
|
logger.debug("send user touch queue events");
|
||||||
|
this.authorizationService.authorizeForce(Permission.ManageQueueEvents);
|
||||||
|
|
||||||
|
this.entityManager.disableTenantFilters();
|
||||||
|
UserQuery userQuery = queryFactory.query(UserQuery.class).isActive(IsActive.Active);
|
||||||
|
List<UserEntity> users = userQuery.collect();
|
||||||
|
this.entityManager.enableTenantFilters();
|
||||||
|
|
||||||
|
for(UserEntity user : users)
|
||||||
|
this.userTouchedIntegrationEventHandler.handle(user.getId());
|
||||||
|
|
||||||
|
this.auditService.track(AuditableAction.Maintenance_SendUserTouchEvents);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.DELETE, value = {"/events/tenants/touch"})
|
||||||
|
public void sendTenantTouchEvents() throws InvalidApplicationException {
|
||||||
|
logger.debug("send tenant touch queue events");
|
||||||
|
this.authorizationService.authorizeForce(Permission.ManageQueueEvents);
|
||||||
|
|
||||||
|
this.entityManager.disableTenantFilters();
|
||||||
|
TenantQuery tenantQuery = queryFactory.query(TenantQuery.class).isActive(IsActive.Active);
|
||||||
|
List<TenantEntity> tenants = tenantQuery.collect();
|
||||||
|
this.entityManager.enableTenantFilters();
|
||||||
|
|
||||||
|
for (TenantEntity tenant : tenants) {
|
||||||
|
TenantTouchedIntegrationEvent event = new TenantTouchedIntegrationEvent();
|
||||||
|
event.setId(tenant.getId());
|
||||||
|
event.setCode(tenant.getCode());
|
||||||
|
this.tenantTouchedIntegrationEventHandler.handle(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.auditService.track(AuditableAction.Maintenance_SendTenantTouchEvents);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,14 @@ permissions:
|
||||||
clients: [ ]
|
clients: [ ]
|
||||||
allowAnonymous: false
|
allowAnonymous: false
|
||||||
allowAuthenticated: false
|
allowAuthenticated: false
|
||||||
|
|
||||||
|
# Queue Events
|
||||||
|
ManageQueueEvents:
|
||||||
|
roles:
|
||||||
|
- Admin
|
||||||
|
clients: [ ]
|
||||||
|
allowAnonymous: false
|
||||||
|
allowAuthenticated: false
|
||||||
|
|
||||||
# Deposit
|
# Deposit
|
||||||
BrowseDeposit:
|
BrowseDeposit:
|
||||||
|
|
Loading…
Reference in New Issue