in progress

This commit is contained in:
Francesco Mangiacrapa 2024-02-01 16:28:03 +01:00
parent a0c77b4e68
commit a45afc6424
3 changed files with 148 additions and 6 deletions

View File

@ -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,10 +350,16 @@ public class NotificationsPlugin extends AbstractPlugin implements EventListener
*/
@Override
public void doAction(ItemObserved<Project> itemObserved) {
log.debug("doAction called...");
if (checkIfSubscribedEvent(itemObserved)) {
boolean isSubscribedEvent = checkIfSubscribedEvent(itemObserved);
//Map (UCD_ID, Notification)
log.info("Is the event {} subscribed in notification plugin configured in the UCD: {} ",
itemObserved.getEvent(), isSubscribedEvent);
if (isSubscribedEvent) {
// Map (UCD_ID, Notification)
Map<String, NotificationEventsSubscribedConfig> notificationMapPerContext = getNotificationBindingMapPerContext();
NotificationEventsSubscribedConfig subscribedConfig = notificationMapPerContext
@ -365,6 +371,9 @@ public class NotificationsPlugin extends AbstractPlugin implements EventListener
List<SubscribeNotificationEvent> 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<NotificationFor> listNotificationFor = subscribeNotificationEvent.getNotificationFor();

View File

@ -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<SubscribeNotificationEvent> listSubscribedNotification;
private ItemObserved<Project> itemObserved;
/**
* Instantiates a new manage do action notification.
*
* @param itemObserved the item observed
* @param filterList the filter list
*/
public ManageDoActionNotification(ItemObserved<Project> itemObserved, List<SubscribeNotificationEvent> 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<NotificationFor> listNotificationFor = subscribeNotificationEvent.getNotificationFor();
String itemPhase = itemObserved.getProject().getLifecycleInformation().getPhase();
for (NotificationFor notificationFor : listNotificationFor) {
// Filtering notifications on phase according to item itemObserved phase
List<NotificationWhen> 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<UserMock> 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<UserMock> getListUserCompliantToRoles(NotificationFor notificationFor) {
List<String> notifyUserWithRoles = notificationFor.getRoles();
List<UserMock> notifyUsers = new ArrayList<UserMock>();
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;
}
}

View File

@ -0,0 +1,10 @@
package org.gcube.application.cms.notifications.manage;
public class ManageNotifyUser {
public ManageNotifyUser() {
// TODO Auto-generated constructor stub
}
}