diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/maintenance/MaintenanceService.java b/dmp-backend/core/src/main/java/eu/eudat/service/maintenance/MaintenanceService.java new file mode 100644 index 000000000..ea7dbcd56 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/service/maintenance/MaintenanceService.java @@ -0,0 +1,29 @@ +package eu.eudat.service.maintenance; + +import eu.eudat.model.Description; +import eu.eudat.model.Prefilling; +import eu.eudat.model.PrefillingSource; +import eu.eudat.model.persist.DescriptionProfilingRequest; +import eu.eudat.model.persist.PrefillingSearchRequest; +import eu.eudat.model.persist.PrefillingSourcePersist; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.exception.MyForbiddenException; +import gr.cite.tools.exception.MyNotFoundException; +import gr.cite.tools.exception.MyValidationException; +import gr.cite.tools.fieldset.FieldSet; +import jakarta.xml.bind.JAXBException; +import org.xml.sax.SAXException; + +import javax.management.InvalidApplicationException; +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; +import java.util.List; +import java.util.UUID; + +public interface MaintenanceService { + + + void sendUserTouchEvents() throws InvalidApplicationException; + + void sendTenantTouchEvents() throws InvalidApplicationException; +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/maintenance/MaintenanceServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/maintenance/MaintenanceServiceImpl.java new file mode 100644 index 000000000..8cb031bee --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/service/maintenance/MaintenanceServiceImpl.java @@ -0,0 +1,113 @@ +package eu.eudat.service.maintenance; + +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.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.model.Tenant; +import eu.eudat.model.User; +import eu.eudat.query.TenantQuery; +import eu.eudat.query.UserQuery; +import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.fieldset.BaseFieldSet; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.management.InvalidApplicationException; +import java.util.List; + +@Service +public class MaintenanceServiceImpl implements MaintenanceService { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(MaintenanceServiceImpl.class)); + private final TenantEntityManager entityManager; + private final AuthorizationService authorizationService; + private final QueryFactory queryFactory; + + private final UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler; + + private final UserRemovalIntegrationEventHandler userRemovalIntegrationEventHandler; + + private final TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler; + + private final TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler; + + + public MaintenanceServiceImpl( + TenantEntityManager entityManager, AuthorizationService authorizationService, + QueryFactory queryFactory, UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler, UserRemovalIntegrationEventHandler userRemovalIntegrationEventHandler, TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler, TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler) { + this.entityManager = entityManager; + this.authorizationService = authorizationService; + this.queryFactory = queryFactory; + this.userTouchedIntegrationEventHandler = userTouchedIntegrationEventHandler; + this.userRemovalIntegrationEventHandler = userRemovalIntegrationEventHandler; + this.tenantTouchedIntegrationEventHandler = tenantTouchedIntegrationEventHandler; + this.tenantRemovalIntegrationEventHandler = tenantRemovalIntegrationEventHandler; + } + + + @Override + public void sendUserTouchEvents() throws InvalidApplicationException { + logger.debug("send user touch queue events"); + this.authorizationService.authorizeForce(Permission.ManageQueueEvents); + + List activeUsers; + List inactiveUsers; + try { + this.entityManager.disableTenantFilters(); + UserQuery userQuery = queryFactory.query(UserQuery.class); + userQuery.isActive(IsActive.Active); + activeUsers = userQuery.collectAs(new BaseFieldSet().ensure(User._id)); + userQuery.isActive(IsActive.Inactive); + inactiveUsers = userQuery.collectAs(new BaseFieldSet().ensure(User._id)); + this.entityManager.enableTenantFilters(); + + } finally { + this.entityManager.enableTenantFilters(); + } + for(UserEntity user : activeUsers) + this.userTouchedIntegrationEventHandler.handle(user.getId()); + + for(UserEntity user : inactiveUsers) + this.userRemovalIntegrationEventHandler.handle(user.getId()); + } + + @Override + public void sendTenantTouchEvents() throws InvalidApplicationException { + logger.debug("send tenant touch queue events"); + this.authorizationService.authorizeForce(Permission.ManageQueueEvents); + + List activeTenants; + List inactiveTenants; + try { + this.entityManager.disableTenantFilters(); + TenantQuery tenantQuery = queryFactory.query(TenantQuery.class); + tenantQuery.isActive(IsActive.Active); + activeTenants = tenantQuery.collectAs(new BaseFieldSet().ensure(Tenant._id).ensure(Tenant._code)); + tenantQuery.isActive(IsActive.Inactive); + inactiveTenants = tenantQuery.collectAs(new BaseFieldSet().ensure(Tenant._id).ensure(Tenant._code)); + + } finally { + this.entityManager.enableTenantFilters(); + } + 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()); + } + } + +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/MaintenanceController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/MaintenanceController.java index 5db770c5d..a520a102a 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/MaintenanceController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/MaintenanceController.java @@ -14,6 +14,7 @@ import eu.eudat.integrationevent.outbox.usertouched.UserTouchedIntegrationEventH import eu.eudat.query.TenantQuery; import eu.eudat.query.UserQuery; import eu.eudat.service.elastic.ElasticService; +import eu.eudat.service.maintenance.MaintenanceService; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.auditing.AuditService; import gr.cite.tools.data.query.QueryFactory; @@ -40,38 +41,17 @@ public class MaintenanceController { private final AuditService auditService; - private final QueryFactory queryFactory; - - private final TenantEntityManager entityManager; - - private final UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler; - - private final UserRemovalIntegrationEventHandler userRemovalIntegrationEventHandler; - - private final TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler; - - private final TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler; - + private final MaintenanceService maintenanceService; @Autowired public MaintenanceController( - AuthorizationService authorizationService, - ElasticService elasticService, - AuditService auditService, - QueryFactory queryFactory, - TenantEntityManager entityManager, - UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler, - UserRemovalIntegrationEventHandler userRemovalIntegrationEventHandler, - TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler, - TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler) { + AuthorizationService authorizationService, + ElasticService elasticService, + AuditService auditService, + MaintenanceService maintenanceService) { 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; + this.maintenanceService = maintenanceService; } @RequestMapping(method = RequestMethod.POST, value = {"/index/elastic"}) @@ -96,51 +76,22 @@ public class MaintenanceController { this.auditService.track(AuditableAction.Maintenance_ClearElastic); } - @RequestMapping(method = RequestMethod.DELETE, value = {"/events/users/touch"}) + @RequestMapping(method = RequestMethod.POST, 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); - userQuery.isActive(IsActive.Active); - List activeUsers = userQuery.collect(); - userQuery.isActive(IsActive.Inactive); - List inactiveUsers = userQuery.collect(); - this.entityManager.enableTenantFilters(); - - for(UserEntity user : activeUsers) - this.userTouchedIntegrationEventHandler.handle(user.getId()); - - for(UserEntity user : inactiveUsers) - this.userRemovalIntegrationEventHandler.handle(user.getId()); - + this.maintenanceService.sendUserTouchEvents(); + this.auditService.track(AuditableAction.Maintenance_SendUserTouchEvents); } - @RequestMapping(method = RequestMethod.DELETE, value = {"/events/tenants/touch"}) + @RequestMapping(method = RequestMethod.POST, 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); - tenantQuery.isActive(IsActive.Active); - List activeTenants = tenantQuery.collect(); - tenantQuery.isActive(IsActive.Inactive); - List inactiveTenants = tenantQuery.collect(); - this.entityManager.enableTenantFilters(); - - 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.maintenanceService.sendTenantTouchEvents(); this.auditService.track(AuditableAction.Maintenance_SendTenantTouchEvents); } diff --git a/dmp-frontend/src/app/core/services/maintenance/maintenance.service.ts b/dmp-frontend/src/app/core/services/maintenance/maintenance.service.ts index e25f63371..e325db6cd 100644 --- a/dmp-frontend/src/app/core/services/maintenance/maintenance.service.ts +++ b/dmp-frontend/src/app/core/services/maintenance/maintenance.service.ts @@ -32,14 +32,14 @@ export class MaintenanceService extends BaseService { sendUserTouchEvents(): Observable { const url = `${this.apiBase}/events/users/touch`; return this.http - .delete(url).pipe( + .post(url, null).pipe( catchError((error: any) => throwError(error))); } sendTenantTouchEvents(): Observable { const url = `${this.apiBase}/events/tenants/touch`; return this.http - .delete(url).pipe( + .post(url, null).pipe( catchError((error: any) => throwError(error))); } }