From a45afc6424f14129788977afd6f0e47a3ba8bc46 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 1 Feb 2024 16:28:03 +0100 Subject: [PATCH] in progress --- .../notifications/NotificationsPlugin.java | 21 ++- .../manage/ManageDoActionNotification.java | 123 ++++++++++++++++++ .../manage/ManageNotifyUser.java | 10 ++ 3 files changed, 148 insertions(+), 6 deletions(-) create mode 100644 notifications-plugins/src/main/java/org/gcube/application/cms/notifications/manage/ManageDoActionNotification.java create mode 100644 notifications-plugins/src/main/java/org/gcube/application/cms/notifications/manage/ManageNotifyUser.java diff --git a/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/NotificationsPlugin.java b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/NotificationsPlugin.java index 1e77564..d97e302 100644 --- a/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/NotificationsPlugin.java +++ b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/NotificationsPlugin.java @@ -1,7 +1,6 @@ package org.gcube.application.cms.notifications; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -12,6 +11,7 @@ import org.bson.Document; import org.gcube.application.cms.implementations.utils.UserUtils; import org.gcube.application.cms.notifications.config.NotificationFor; import org.gcube.application.cms.notifications.config.SubscribeNotificationEvent; +import org.gcube.application.cms.notifications.manage.ManageDoActionNotification; import org.gcube.application.cms.plugins.EventListenerPluginInterface; import org.gcube.application.cms.plugins.events.EventListener; import org.gcube.application.cms.plugins.events.EventManager; @@ -350,12 +350,18 @@ public class NotificationsPlugin extends AbstractPlugin implements EventListener */ @Override public void doAction(ItemObserved itemObserved) { + log.debug("doAction called..."); + + boolean isSubscribedEvent = checkIfSubscribedEvent(itemObserved); - if (checkIfSubscribedEvent(itemObserved)) { + log.info("Is the event {} subscribed in notification plugin configured in the UCD: {} ", + itemObserved.getEvent(), isSubscribedEvent); - //Map (UCD_ID, Notification) + if (isSubscribedEvent) { + + // Map (UCD_ID, Notification) Map notificationMapPerContext = getNotificationBindingMapPerContext(); - + NotificationEventsSubscribedConfig subscribedConfig = notificationMapPerContext .get(itemObserved.getUCD_Id()); @@ -365,11 +371,14 @@ public class NotificationsPlugin extends AbstractPlugin implements EventListener List filterList = list.stream() .filter(sne -> sne.getEvent().equals(itemObserved.getEvent())).collect(Collectors.toList()); + log.debug(linkToFileWithMessages); + ManageDoActionNotification mdoact = new ManageDoActionNotification(itemObserved, filterList); + for (SubscribeNotificationEvent subscribeNotificationEvent : filterList) { List listNotificationFor = subscribeNotificationEvent.getNotificationFor(); - UserUtils.getCurrent().getRoles(); - + UserUtils.getCurrent().getRoles(); + for (NotificationFor notificationFor : listNotificationFor) { notificationFor.getRoles(); } diff --git a/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/manage/ManageDoActionNotification.java b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/manage/ManageDoActionNotification.java new file mode 100644 index 0000000..ec8fb6d --- /dev/null +++ b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/manage/ManageDoActionNotification.java @@ -0,0 +1,123 @@ +package org.gcube.application.cms.notifications.manage; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import org.gcube.application.cms.implementations.utils.UserUtils; +import org.gcube.application.cms.notifications.config.NotificationFor; +import org.gcube.application.cms.notifications.config.NotificationWhen; +import org.gcube.application.cms.notifications.config.SubscribeNotificationEvent; +import org.gcube.application.cms.plugins.events.ItemObserved; +import org.gcube.application.geoportal.common.model.document.Project; + +import lombok.extern.slf4j.Slf4j; + +/** + * The Class ManageDoActionNotification. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Feb 1, 2024 + */ +@Slf4j +public class ManageDoActionNotification { + + private List listSubscribedNotification; + private ItemObserved itemObserved; + + /** + * Instantiates a new manage do action notification. + * + * @param itemObserved the item observed + * @param filterList the filter list + */ + public ManageDoActionNotification(ItemObserved itemObserved, List filterList) { + this.listSubscribedNotification = filterList; + this.itemObserved = itemObserved; + } + + /** + * Manage. + */ + public void manage() { + log.debug("manage called..."); + + if (listSubscribedNotification == null || listSubscribedNotification.isEmpty()) + return; + + for (SubscribeNotificationEvent subscribeNotificationEvent : listSubscribedNotification) { + List listNotificationFor = subscribeNotificationEvent.getNotificationFor(); + + String itemPhase = itemObserved.getProject().getLifecycleInformation().getPhase(); + + for (NotificationFor notificationFor : listNotificationFor) { + // Filtering notifications on phase according to item itemObserved phase + List notificationsCompliantToPhase = notificationFor.getWhen().stream() + .filter(when -> when.getTarget_phase().contains(itemPhase)).collect(Collectors.toList()); + + log.debug("Filtered notification on phase {} are: {}", itemPhase, notificationsCompliantToPhase); + + if (notificationsCompliantToPhase != null && notificationsCompliantToPhase.size() > 0) { + // GET LIST USER COMPLIANT TO ROLES + List notifyUsers = getListUserCompliantToRoles(notificationFor); + + if (notifyUsers.size() > 0) { + } + } + } + } + + } + + /** + * The Class UserMock. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Feb 1, 2024 + */ + // MOCK + public class UserMock { + + } + + /** + * Gets the list user compliant to roles. + * + * @param notificationFor the notification for + * @return the list user compliant to roles + */ + // GET LIST USER COMPLIANT TO ROLES + public List getListUserCompliantToRoles(NotificationFor notificationFor) { + + List notifyUserWithRoles = notificationFor.getRoles(); + + List notifyUsers = new ArrayList(); + + String scope = UserUtils.getCurrent().getContext(); + + if (notifyUserWithRoles.contains("Any")) { + // All user in the VRE + // read and return them + } + + // We need to create the list of users that must be notified + for (String role : notifyUserWithRoles) { + // Reading the list of users in the VRE with specific role + + // Creator of the item + if (role.compareTo("Item_Creator") == 0) { + // add to list of users to notify; + } else { + // Reading the list of users in the VRE with specific role + } + + } + + // return the list of users that must be notified; + + return notifyUsers; + } + +} diff --git a/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/manage/ManageNotifyUser.java b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/manage/ManageNotifyUser.java new file mode 100644 index 0000000..f16991d --- /dev/null +++ b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/manage/ManageNotifyUser.java @@ -0,0 +1,10 @@ +package org.gcube.application.cms.notifications.manage; + +public class ManageNotifyUser { + + + public ManageNotifyUser() { + // TODO Auto-generated constructor stub + } + +}