Merge branch 'dmp-refactoring' of code-repo.d4science.org:MaDgiK-CITE/argos into dmp-refactoring

# Conflicts:
#	dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenanttouched/TenantTouchedIntegrationEventHandlerImpl.java
This commit is contained in:
Efstratios Giannopoulos 2024-04-04 12:22:35 +03:00
commit c1a3ac89d6
5 changed files with 98 additions and 12 deletions

View File

@ -145,6 +145,8 @@ public class AuditableAction {
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_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_MyTenants = new EventId(240001, "Principal_MyTenants");

View File

@ -22,6 +22,8 @@ public final class Permission {
public static String PublicBrowseReferenceType = "PublicBrowseReferenceType";
//Elastic
public static String ManageElastic = "ManageElastic";
//Queue Events
public static String ManageQueueEvents = "ManageQueueEvents";
//Deposit

View File

@ -8,16 +8,17 @@ import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Component("outboxtenanttouchedintegrationeventhandler")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantTouchedIntegrationEventHandlerImpl implements TenantTouchedIntegrationEventHandler {
private final OutboxService outboxService;
public TenantTouchedIntegrationEventHandlerImpl(OutboxService outboxService) {
this.outboxService = outboxService;
}
public TenantTouchedIntegrationEventHandlerImpl(OutboxService outboxService) {
this.outboxService = outboxService;
}
@Override
@Override
public void handle(TenantTouchedIntegrationEvent event) {
OutboxIntegrationEvent message = new OutboxIntegrationEvent();
message.setMessageId(UUID.randomUUID());

View File

@ -2,32 +2,67 @@ 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;
@Autowired
public MaintenanceController(AuthorizationService authorizationService, ElasticService elasticService, AuditService auditService) {
this.authorizationService = authorizationService;
this.elasticService = elasticService;
this.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,
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 {
@ -36,6 +71,7 @@ public class MaintenanceController {
elasticService.resetDmpIndex();
elasticService.resetDescriptionIndex();
this.auditService.track(AuditableAction.Maintenance_GenerateElastic);
}
@ -43,9 +79,46 @@ public class MaintenanceController {
public void clearIndex() throws Exception {
logger.debug("clear elastic");
this.authorizationService.authorizeForce(Permission.ManageElastic);
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);
}
}

View File

@ -88,6 +88,14 @@ permissions:
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
# Queue Events
ManageQueueEvents:
roles:
- Admin
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
# Deposit
BrowseDeposit: