updated send notification checks

This commit is contained in:
Francesco Mangiacrapa 2024-03-22 16:22:22 +01:00
parent bab16ad14d
commit 3913019df3
1 changed files with 59 additions and 41 deletions

View File

@ -24,6 +24,8 @@ import org.gcube.application.geoportal.common.model.configuration.Configuration;
import org.gcube.application.geoportal.common.model.document.Project; import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.document.access.Access; import org.gcube.application.geoportal.common.model.document.access.Access;
import org.gcube.application.geoportal.common.model.document.accounting.AccountingInfo; import org.gcube.application.geoportal.common.model.document.accounting.AccountingInfo;
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation.Status;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException; import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.common.model.rest.QueryRequest; import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest; import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
@ -115,16 +117,20 @@ public class ProfiledDocuments {
} }
}.execute().getResult(); }.execute().getResult();
// notifying the Event.PROJECT_CREATED; Status status = theNewProject.getLifecycleInformation().getLastOperationStatus();
ItemObserved<Project> item = new ItemObserved<Project>(); // IF last operation status is not ERROR, notify PROJECT_CREATED event
EventManager.Event event = Event.PROJECT_CREATED; if (status != null && !status.equals(LifecycleInformation.Status.ERROR)) {
AccountingInfo user = UserUtils.getCurrent().asInfo(); // notifying the Event.PROJECT_CREATED;
item.setUserCaller(user.getUser()); ItemObserved<Project> item = new ItemObserved<Project>();
item.setContext(user.getContext()); EventManager.Event event = Event.PROJECT_CREATED;
item.setEvent(event); AccountingInfo user = UserUtils.getCurrent().asInfo();
item.setProject(theNewProject); item.setUserCaller(user.getUser());
log.info("By notifying event ({}, ID {})", event, item.getProjectId()); item.setContext(user.getContext());
eventManager.notify(event, item); item.setEvent(event);
item.setProject(theNewProject);
log.info("By notifying event ({}, ID {})", event, item.getProjectId());
eventManager.notify(event, item);
}
return theNewProject; return theNewProject;
} }
@ -149,15 +155,20 @@ public class ProfiledDocuments {
} }
}.execute().getResult(); }.execute().getResult();
ItemObserved<Project> item = new ItemObserved<Project>(); Status status = theUpdatedProject.getLifecycleInformation().getLastOperationStatus();
EventManager.Event event = Event.PROJECT_UPDATED; // IF last operation status is not ERROR, notify PROJECT_UPDATED event
AccountingInfo user = UserUtils.getCurrent().asInfo(); if (status != null && !status.equals(LifecycleInformation.Status.ERROR)) {
item.setUserCaller(user.getUser());
item.setContext(user.getContext()); ItemObserved<Project> item = new ItemObserved<Project>();
item.setEvent(event); EventManager.Event event = Event.PROJECT_UPDATED;
item.setProject(theUpdatedProject); AccountingInfo user = UserUtils.getCurrent().asInfo();
log.info("By notifying event ({}, ID {})", event, item.getProjectId()); item.setUserCaller(user.getUser());
eventManager.notify(event, item); item.setContext(user.getContext());
item.setEvent(event);
item.setProject(theUpdatedProject);
log.info("By notifying event ({}, ID {})", event, item.getProjectId());
eventManager.notify(event, item);
}
return theUpdatedProject; return theUpdatedProject;
} }
@ -206,19 +217,22 @@ public class ProfiledDocuments {
} }
}.execute().getResult(); }.execute().getResult();
ItemObserved<Project> item = new ItemObserved<Project>(); // IF deleted, notify PROJECT_DELETED event
EventManager.Event event = Event.PROJECT_DELETED; if (deleted) {
AccountingInfo user = UserUtils.getCurrent().asInfo(); ItemObserved<Project> item = new ItemObserved<Project>();
item.setUserCaller(user.getUser()); EventManager.Event event = Event.PROJECT_DELETED;
item.setContext(user.getContext()); AccountingInfo user = UserUtils.getCurrent().asInfo();
item.setEvent(event); item.setUserCaller(user.getUser());
// Referencing delete project item.setContext(user.getContext());
Project deletedProject = new Project(); item.setEvent(event);
deletedProject.setId(id); // Referencing delete project
deletedProject.setProfileID(manager.getUseCaseDescriptor().getId()); Project deletedProject = new Project();
item.setProject(deletedProject); deletedProject.setId(id);
log.info("By notifying event ({}, ID {})", event, item.getProjectId()); deletedProject.setProfileID(manager.getUseCaseDescriptor().getId());
eventManager.notify(event, item); item.setProject(deletedProject);
log.info("By notifying event ({}, ID {})", event, item.getProjectId());
eventManager.notify(event, item);
}
return deleted; return deleted;
} }
@ -298,15 +312,19 @@ public class ProfiledDocuments {
} }
}.execute().getResult(); }.execute().getResult();
ItemObserved<Project> item = new ItemObserved<Project>(); Status status = theProject.getLifecycleInformation().getLastOperationStatus();
EventManager.Event event = Event.LIFECYCLE_STEP_PERFORMED; // IF last operation status is not ERROR, notify LIFECYCLE_STEP_PERFORMED event
AccountingInfo user = UserUtils.getCurrent().asInfo(); if (status != null && !status.equals(LifecycleInformation.Status.ERROR)) {
item.setUserCaller(user.getUser()); ItemObserved<Project> item = new ItemObserved<Project>();
item.setContext(user.getContext()); EventManager.Event event = Event.LIFECYCLE_STEP_PERFORMED;
item.setEvent(event); AccountingInfo user = UserUtils.getCurrent().asInfo();
item.setProject(theProject); item.setUserCaller(user.getUser());
log.info("By notifying event ({}, ID {})", event, item.getProjectId()); item.setContext(user.getContext());
eventManager.notify(event, item); item.setEvent(event);
item.setProject(theProject);
log.info("By notifying event ({}, ID {})", event, item.getProjectId());
eventManager.notify(event, item);
}
return theProject; return theProject;
} }