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