add annotation events

This commit is contained in:
Efstratios Giannopoulos 2024-05-08 17:55:37 +03:00
parent ebb35ad41c
commit accb6fc772
8 changed files with 205 additions and 32 deletions

View File

@ -150,6 +150,8 @@ public class AuditableAction {
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 Maintenance_SendDmpTouchEvents = new EventId(230003, "Maintenance_SendDmpTouchEvents");
public static final EventId Maintenance_SendDescriptionTouchEvents = new EventId(230004, "Maintenance_SendDescriptionTouchEvents");
public static final EventId Principal_Lookup = new EventId(240000, "Principal_Lookup");
public static final EventId Principal_MyTenants = new EventId(240001, "Principal_MyTenants");

View File

@ -8,4 +8,8 @@ public interface MaintenanceService {
void sendUserTouchEvents() throws InvalidApplicationException;
void sendTenantTouchEvents() throws InvalidApplicationException;
void sendDmpTouchEvents() throws InvalidApplicationException;
void sendDescriptionTouchEvents() throws InvalidApplicationException;
}

View File

@ -6,16 +6,21 @@ import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.Permission;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.data.TenantEntity;
import org.opencdmp.data.TenantEntityManager;
import org.opencdmp.data.UserEntity;
import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.data.*;
import org.opencdmp.integrationevent.outbox.annotationentityremoval.AnnotationEntityRemovalIntegrationEventHandler;
import org.opencdmp.integrationevent.outbox.annotationentitytouch.AnnotationEntityTouchedIntegrationEventHandler;
import org.opencdmp.integrationevent.outbox.tenantremoval.TenantRemovalIntegrationEventHandler;
import org.opencdmp.integrationevent.outbox.tenanttouched.TenantTouchedIntegrationEvent;
import org.opencdmp.integrationevent.outbox.tenanttouched.TenantTouchedIntegrationEventHandler;
import org.opencdmp.integrationevent.outbox.userremoval.UserRemovalIntegrationEventHandler;
import org.opencdmp.integrationevent.outbox.usertouched.UserTouchedIntegrationEventHandler;
import org.opencdmp.model.Tenant;
import org.opencdmp.model.description.Description;
import org.opencdmp.model.dmp.Dmp;
import org.opencdmp.model.user.User;
import org.opencdmp.query.DescriptionQuery;
import org.opencdmp.query.DmpQuery;
import org.opencdmp.query.TenantQuery;
import org.opencdmp.query.UserQuery;
import org.slf4j.LoggerFactory;
@ -23,6 +28,7 @@ import org.springframework.stereotype.Service;
import javax.management.InvalidApplicationException;
import java.util.List;
import java.util.UUID;
@Service
public class MaintenanceServiceImpl implements MaintenanceService {
@ -39,11 +45,14 @@ public class MaintenanceServiceImpl implements MaintenanceService {
private final TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler;
private final TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler;
private final AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler;
private final AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler;
private final TenantScope tenantScope;
public MaintenanceServiceImpl(
TenantEntityManager entityManager, AuthorizationService authorizationService,
QueryFactory queryFactory, UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler, UserRemovalIntegrationEventHandler userRemovalIntegrationEventHandler, TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler, TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler) {
QueryFactory queryFactory, UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler, UserRemovalIntegrationEventHandler userRemovalIntegrationEventHandler, TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler, TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, TenantScope tenantScope) {
this.entityManager = entityManager;
this.authorizationService = authorizationService;
this.queryFactory = queryFactory;
@ -51,6 +60,9 @@ public class MaintenanceServiceImpl implements MaintenanceService {
this.userRemovalIntegrationEventHandler = userRemovalIntegrationEventHandler;
this.tenantTouchedIntegrationEventHandler = tenantTouchedIntegrationEventHandler;
this.tenantRemovalIntegrationEventHandler = tenantRemovalIntegrationEventHandler;
this.annotationEntityRemovalIntegrationEventHandler = annotationEntityRemovalIntegrationEventHandler;
this.annotationEntityTouchedIntegrationEventHandler = annotationEntityTouchedIntegrationEventHandler;
this.tenantScope = tenantScope;
}
@ -109,5 +121,74 @@ public class MaintenanceServiceImpl implements MaintenanceService {
this.tenantRemovalIntegrationEventHandler.handle(tenant.getId());
}
}
@Override
public void sendDmpTouchEvents() throws InvalidApplicationException {
logger.debug("send user touch queue events");
this.authorizationService.authorizeForce(Permission.ManageQueueEvents);
List<TenantEntity> tenants = this.getTenants();
this.sendTenantDmpTouchEvents(null, this.tenantScope.getDefaultTenantCode());
if (tenants != null){
for (TenantEntity tenant : tenants){
this.sendTenantDmpTouchEvents(tenant.getId(), tenant.getCode());
}
}
}
private void sendTenantDmpTouchEvents(UUID tenantId, String tenantCode) throws InvalidApplicationException {
try {
this.tenantScope.setTempTenant(this.entityManager.getEntityManager(), tenantId, tenantCode);
List<DmpEntity> items = this.queryFactory.query(DmpQuery.class).disableTracking().isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(Dmp._id).ensure(Dmp._isActive));
for (DmpEntity item : items) {
if (item.getIsActive().equals(IsActive.Active)) this.annotationEntityTouchedIntegrationEventHandler.handleDmp(item.getId());
else this.annotationEntityRemovalIntegrationEventHandler.handleDmp(item.getId());
}
} finally {
this.tenantScope.removeTempTenant(this.entityManager.getEntityManager());
}
}
@Override
public void sendDescriptionTouchEvents() throws InvalidApplicationException {
logger.debug("send user touch queue events");
this.authorizationService.authorizeForce(Permission.ManageQueueEvents);
List<TenantEntity> tenants = this.getTenants();
this.sendTenantDescriptionTouchEvents(null, this.tenantScope.getDefaultTenantCode());
if (tenants != null){
for (TenantEntity tenant : tenants){
this.sendTenantDescriptionTouchEvents(tenant.getId(), tenant.getCode());
}
}
}
private void sendTenantDescriptionTouchEvents(UUID tenantId, String tenantCode) throws InvalidApplicationException {
try {
this.tenantScope.setTempTenant(this.entityManager.getEntityManager(), tenantId, tenantCode);
List<DescriptionEntity> items = this.queryFactory.query(DescriptionQuery.class).disableTracking().isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(Description._id).ensure(Description._isActive));
for (DescriptionEntity item : items) {
if (item.getIsActive().equals(IsActive.Active)) this.annotationEntityTouchedIntegrationEventHandler.handleDescription(item.getId());
else this.annotationEntityRemovalIntegrationEventHandler.handleDescription(item.getId());
}
} finally {
this.tenantScope.removeTempTenant(this.entityManager.getEntityManager());
}
}
private List<TenantEntity> getTenants() throws InvalidApplicationException {
List<TenantEntity> tenants;
try {
this.entityManager.disableTenantFilters();
tenants = this.queryFactory.query(TenantQuery.class).disableTracking().isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(Tenant._id).ensure(Tenant._code));
} finally {
this.entityManager.enableTenantFilters();
}
return tenants;
}
}

View File

@ -1,25 +1,12 @@
package org.opencdmp.controllers;
import org.opencdmp.audit.AuditableAction;
import org.opencdmp.authorization.Permission;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.data.TenantEntity;
import org.opencdmp.data.TenantEntityManager;
import org.opencdmp.data.UserEntity;
import org.opencdmp.integrationevent.outbox.tenantremoval.TenantRemovalIntegrationEventHandler;
import org.opencdmp.integrationevent.outbox.tenanttouched.TenantTouchedIntegrationEvent;
import org.opencdmp.integrationevent.outbox.tenanttouched.TenantTouchedIntegrationEventHandler;
import org.opencdmp.integrationevent.outbox.userremoval.UserRemovalIntegrationEventHandler;
import org.opencdmp.integrationevent.outbox.usertouched.UserTouchedIntegrationEventHandler;
import org.opencdmp.query.TenantQuery;
import org.opencdmp.query.UserQuery;
import org.opencdmp.service.elastic.ElasticService;
import org.opencdmp.service.maintenance.MaintenanceService;
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.opencdmp.audit.AuditableAction;
import org.opencdmp.authorization.Permission;
import org.opencdmp.service.elastic.ElasticService;
import org.opencdmp.service.maintenance.MaintenanceService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
@ -27,7 +14,6 @@ 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")
@ -54,29 +40,29 @@ public class MaintenanceController {
this.maintenanceService = maintenanceService;
}
@RequestMapping(method = RequestMethod.POST, value = {"/index/elastic"})
@RequestMapping(method = RequestMethod.POST, value = "/index/elastic")
public void generateIndex() throws Exception {
logger.debug("generate elastic ");
this.authorizationService.authorizeForce(Permission.ManageElastic);
elasticService.resetDmpIndex();
elasticService.resetDescriptionIndex();
this.elasticService.resetDmpIndex();
this.elasticService.resetDescriptionIndex();
this.auditService.track(AuditableAction.Maintenance_GenerateElastic);
}
@RequestMapping(method = RequestMethod.DELETE, value = {"/index/elastic"})
@RequestMapping(method = RequestMethod.DELETE, value = "/index/elastic")
public void clearIndex() throws Exception {
logger.debug("clear elastic");
this.authorizationService.authorizeForce(Permission.ManageElastic);
elasticService.deleteDescriptionIndex();
elasticService.deleteDmpIndex();
this.elasticService.deleteDescriptionIndex();
this.elasticService.deleteDmpIndex();
this.auditService.track(AuditableAction.Maintenance_ClearElastic);
}
@RequestMapping(method = RequestMethod.POST, 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);
@ -86,7 +72,7 @@ public class MaintenanceController {
this.auditService.track(AuditableAction.Maintenance_SendUserTouchEvents);
}
@RequestMapping(method = RequestMethod.POST, 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);
@ -95,4 +81,24 @@ public class MaintenanceController {
this.auditService.track(AuditableAction.Maintenance_SendTenantTouchEvents);
}
@RequestMapping(method = RequestMethod.POST, value = "/events/dmps/touch")
public void sendDmpTouchEvents() throws InvalidApplicationException {
logger.debug("send dmp touch queue events");
this.authorizationService.authorizeForce(Permission.ManageQueueEvents);
this.maintenanceService.sendDmpTouchEvents();
this.auditService.track(AuditableAction.Maintenance_SendDmpTouchEvents);
}
@RequestMapping(method = RequestMethod.POST, value = "/events/descriptions/touch")
public void sendDescriptionTouchEvents() throws InvalidApplicationException {
logger.debug("send dmp touch queue events");
this.authorizationService.authorizeForce(Permission.ManageQueueEvents);
this.maintenanceService.sendDescriptionTouchEvents();
this.auditService.track(AuditableAction.Maintenance_SendDescriptionTouchEvents);
}
}

View File

@ -42,4 +42,18 @@ export class MaintenanceService extends BaseService {
.post<any>(url, null).pipe(
catchError((error: any) => throwError(error)));
}
sendDmpTouchEvents(): Observable<any> {
const url = `${this.apiBase}/events/dmps/touch`;
return this.http
.post<any>(url, null).pipe(
catchError((error: any) => throwError(error)));
}
sendDescriptionTouchEvents(): Observable<any> {
const url = `${this.apiBase}/events/descriptions/touch`;
return this.http
.post<any>(url, null).pipe(
catchError((error: any) => throwError(error)));
}
}

View File

@ -39,6 +39,8 @@
<div class="mt-2">
<button mat-raised-button color="primary" (click)="sendUserTouchEvents($event)" class="lightblue-btn button">{{language.instant('MAINTENANCE-TASKS.SECTIONS.EVENTS.ACTIONS.SEND-USER-TOUCH')}}</button>
<button mat-raised-button color="primary" (click)="sendTenantTouchEvents($event)" class="lightblue-btn button">{{language.instant('MAINTENANCE-TASKS.SECTIONS.EVENTS.ACTIONS.SEND-TENANT-TOUCH')}}</button>
<button mat-raised-button color="primary" (click)="sendDmpTouchEvents($event)" class="lightblue-btn button">{{language.instant('MAINTENANCE-TASKS.SECTIONS.EVENTS.ACTIONS.SEND-DMP-TOUCH')}}</button>
<button mat-raised-button color="primary" (click)="sendDescriptionTouchEvents($event)" class="lightblue-btn button">{{language.instant('MAINTENANCE-TASKS.SECTIONS.EVENTS.ACTIONS.SEND-DESCRIPTION-TOUCH')}}</button>
</div>
</mat-expansion-panel>
</mat-accordion>

View File

@ -182,6 +182,68 @@ export class MaintenanceTasksComponent extends BaseComponent implements OnInit {
);
}
sendDmpTouchEvents(ev: Event) {
this.dialog.open(ConfirmationDialogComponent, {
data: {
message: this.language.instant('MAINTENANCE-TASKS.CONFIRMATION.MESSAGE'),
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'),
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL')
},
maxWidth: '30em'
})
.afterClosed()
.subscribe(confirm => {
if (confirm) {
this.doSendDmpTouchEvents(ev);
}
});
}
private doSendDmpTouchEvents(ev: Event) {
(ev.target as HTMLButtonElement).disabled = true;
this.maintenanceService.sendDmpTouchEvents().pipe(takeUntil(this._destroyed)).subscribe(
_ => {
(ev.target as HTMLButtonElement).disabled = false;
this.onCallbackSuccess();
},
error => {
(ev.target as HTMLButtonElement).disabled = false;
this.onCallbackError(error);
}
);
}
sendDescriptionTouchEvents(ev: Event) {
this.dialog.open(ConfirmationDialogComponent, {
data: {
message: this.language.instant('MAINTENANCE-TASKS.CONFIRMATION.MESSAGE'),
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'),
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL')
},
maxWidth: '30em'
})
.afterClosed()
.subscribe(confirm => {
if (confirm) {
this.doSendDescriptionTouchEvents(ev);
}
});
}
private doSendDescriptionTouchEvents(ev: Event) {
(ev.target as HTMLButtonElement).disabled = true;
this.maintenanceService.sendDescriptionTouchEvents().pipe(takeUntil(this._destroyed)).subscribe(
_ => {
(ev.target as HTMLButtonElement).disabled = false;
this.onCallbackSuccess();
},
error => {
(ev.target as HTMLButtonElement).disabled = false;
this.onCallbackError(error);
}
);
}
onCallbackSuccess(): void {
this.uiNotificationService.snackBarNotification(this.translate.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
this.router.navigate(['/reload']).then(() => this.router.navigate(['/maintenance-tasks']));

View File

@ -306,7 +306,9 @@
"DESCRIPTION": "From here you can manage the Message Queue events",
"ACTIONS": {
"SEND-USER-TOUCH": "Send user touch events",
"SEND-TENANT-TOUCH": "Send tenant touch events"
"SEND-TENANT-TOUCH": "Send tenant touch events",
"SEND-DMP-TOUCH": "Send dmp touch events",
"SEND-DESCRIPTION-TOUCH": "Send description touch events"
}
}
},
@ -1143,7 +1145,7 @@
},
"NOTIFICATION-TEMPLATE-EDITOR": {
"NEW": "New Notification Template",
"TITLE-EDIT-NOTIFICATION-TEMPLATE": "Editing Notification Template",
"TITLE-EDIT-NOTIFICATION-TEMPLATE": "Editing Notification Template",
"FIELDS": {
"NOTIFICATION-TYPE": "Notification Type",
"LANGUAGE": "Language",