|
|
|
@ -2,33 +2,68 @@ package eu.eudat.controllers;
|
|
|
|
|
|
|
|
|
|
import eu.eudat.audit.AuditableAction;
|
|
|
|
|
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 gr.cite.commons.web.authz.service.AuthorizationService;
|
|
|
|
|
import gr.cite.tools.auditing.AuditService;
|
|
|
|
|
import gr.cite.tools.data.query.QueryFactory;
|
|
|
|
|
import gr.cite.tools.logging.LoggerService;
|
|
|
|
|
import jakarta.persistence.EntityManager;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import javax.management.InvalidApplicationException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping(path = "api/maintenance")
|
|
|
|
|
public class MaintenanceController {
|
|
|
|
|
|
|
|
|
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(MaintenanceController.class));
|
|
|
|
|
|
|
|
|
|
private final AuthorizationService authorizationService;
|
|
|
|
|
|
|
|
|
|
private final ElasticService elasticService;
|
|
|
|
|
|
|
|
|
|
private final AuditService auditService;
|
|
|
|
|
|
|
|
|
|
private final QueryFactory queryFactory;
|
|
|
|
|
|
|
|
|
|
private final TenantEntityManager entityManager;
|
|
|
|
|
|
|
|
|
|
private final UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler;
|
|
|
|
|
|
|
|
|
|
private final TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
public MaintenanceController(AuthorizationService authorizationService, ElasticService elasticService, AuditService auditService) {
|
|
|
|
|
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"})
|
|
|
|
|
public void generateIndex() throws Exception {
|
|
|
|
|
logger.debug("generate elastic ");
|
|
|
|
@ -36,6 +71,7 @@ public class MaintenanceController {
|
|
|
|
|
|
|
|
|
|
elasticService.resetDmpIndex();
|
|
|
|
|
elasticService.resetDescriptionIndex();
|
|
|
|
|
|
|
|
|
|
this.auditService.track(AuditableAction.Maintenance_GenerateElastic);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -46,6 +82,43 @@ public class MaintenanceController {
|
|
|
|
|
|
|
|
|
|
elasticService.deleteDescriptionIndex();
|
|
|
|
|
elasticService.deleteDmpIndex();
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|