add mapping to CatalogueEvent
This commit is contained in:
parent
27126d1c9f
commit
45164a02da
|
@ -11,7 +11,7 @@ public class NotificationGenericConstants {
|
||||||
};
|
};
|
||||||
|
|
||||||
public static enum NOTIFICATION_TYPE {
|
public static enum NOTIFICATION_TYPE {
|
||||||
USER_MESSAGE, EMAIL, VRE_POST
|
USER_POST, EMAIL, VRE_POST
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.gcube.application.cms.notifications.config.NotificationFor;
|
||||||
import org.gcube.application.cms.notifications.config.NotificationWhen;
|
import org.gcube.application.cms.notifications.config.NotificationWhen;
|
||||||
import org.gcube.application.cms.notifications.config.SubscribeNotificationEvent;
|
import org.gcube.application.cms.notifications.config.SubscribeNotificationEvent;
|
||||||
import org.gcube.application.cms.notifications.gis.GisClient;
|
import org.gcube.application.cms.notifications.gis.GisClient;
|
||||||
|
import org.gcube.application.cms.notifications.manage.mapping.MappingToCatalogue;
|
||||||
import org.gcube.application.cms.notifications.social.SocialClients;
|
import org.gcube.application.cms.notifications.social.SocialClients;
|
||||||
import org.gcube.application.cms.notifications.substitutor.NMessagesPlaceholdersSubstitutorUtil;
|
import org.gcube.application.cms.notifications.substitutor.NMessagesPlaceholdersSubstitutorUtil;
|
||||||
import org.gcube.application.cms.notifications.substitutor.SubstitutorMessagesMap;
|
import org.gcube.application.cms.notifications.substitutor.SubstitutorMessagesMap;
|
||||||
|
@ -20,9 +21,8 @@ import org.gcube.application.cms.plugins.events.ItemObserved;
|
||||||
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.accounting.User;
|
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||||
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManager;
|
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
|
||||||
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder.RESOLVE_AS;
|
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder.RESOLVE_AS;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEventType;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ public class ManageDoActionNotification {
|
||||||
String lastInvokedStep = lInfo.getLastInvokedStep();
|
String lastInvokedStep = lInfo.getLastInvokedStep();
|
||||||
log.debug("ItemObserved phase is: {}, lastInvokedStep is: {}", itemPhase, lastInvokedStep);
|
log.debug("ItemObserved phase is: {}, lastInvokedStep is: {}", itemPhase, lastInvokedStep);
|
||||||
|
|
||||||
final SecretManager cm = SecretManagerProvider.instance.get();
|
//final SecretManager cm = SecretManagerProvider.instance.get();
|
||||||
|
|
||||||
for (final NotificationFor notificationFor : listNotificationFor) {
|
for (final NotificationFor notificationFor : listNotificationFor) {
|
||||||
// Filtering notifications on 'phase' and 'lastInvokedStep' according to item
|
// Filtering notifications on 'phase' and 'lastInvokedStep' according to item
|
||||||
|
@ -100,39 +100,23 @@ public class ManageDoActionNotification {
|
||||||
|
|
||||||
if (notificationsCompliantToPhase != null && notificationsCompliantToPhase.size() > 0) {
|
if (notificationsCompliantToPhase != null && notificationsCompliantToPhase.size() > 0) {
|
||||||
// GET LIST USER COMPLIANT TO ROLES
|
// GET LIST USER COMPLIANT TO ROLES
|
||||||
List<User> notifyUsers = getListUserCompliantToRoles(notificationFor, itemObserved);
|
List<User> notifyUsers = getListUserCompliantToRoles(notificationFor, itemObserved, true);
|
||||||
final SocialClients socialClients = new SocialClients();
|
final SocialClients socialClients = new SocialClients();
|
||||||
|
CatalogueEventType catalogueEventType = MappingToCatalogue.toCatalogueEventType(itemPhase, lastInvokedStep);
|
||||||
|
|
||||||
if (notifyUsers.size() > 0) {
|
if (notifyUsers.size() > 0) {
|
||||||
log.info("Users compliant to role are: {}", notifyUsers.size());
|
log.info("Users compliant to role are: {}", notifyUsers.size());
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
notifyUsers.stream().forEach(u -> log.debug("user: " + u));
|
notifyUsers.stream().forEach(u -> log.debug("notifying user: " + u));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final User user : notifyUsers) {
|
try {
|
||||||
try {
|
NotifyUser mnu = new NotifyUser(socialClients, notificationsCompliantToPhase,
|
||||||
|
nMPlaceholdersS, notifyUsers, catalogueEventType);
|
||||||
NotifyUser mnu = new NotifyUser(socialClients, notificationsCompliantToPhase,
|
mnu.send();
|
||||||
nMPlaceholdersS, user);
|
} catch (Exception e) {
|
||||||
mnu.send();
|
log.error("Error occurred when send notify: ", e);
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Error occurred when send notify: ", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* for (final User user : notifyUsers) { Thread notificationT = new Thread() {
|
|
||||||
* public void run() { SecretManagerProvider.instance.set(cm); NotifyUser mnu =
|
|
||||||
* new NotifyUser(socialClients, notificationsCompliantToPhase, nMPlaceholdersS,
|
|
||||||
* user); try { mnu.send(); } catch (Exception e) {
|
|
||||||
* log.error("Error occurred when send notify: ", e); } };
|
|
||||||
*
|
|
||||||
* };
|
|
||||||
*
|
|
||||||
* notificationT.start(); }
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,7 +134,8 @@ public class ManageDoActionNotification {
|
||||||
for (NotificationWhen notificationWhen : notificationFor.getWhen()) {
|
for (NotificationWhen notificationWhen : notificationFor.getWhen()) {
|
||||||
log.info(++i + ") notificationWhen target phases: {} and last_invoked_step: {}",
|
log.info(++i + ") notificationWhen target phases: {} and last_invoked_step: {}",
|
||||||
notificationWhen.getTarget_phase(), notificationWhen.getLast_invoked_step());
|
notificationWhen.getTarget_phase(), notificationWhen.getLast_invoked_step());
|
||||||
if (notificationWhen.getTarget_phase().contains(itemPhase)) {
|
if (notificationWhen.getTarget_phase().contains(itemPhase) || notificationWhen.getTarget_phase()
|
||||||
|
.contains(NotificationGenericConstants.CUSTOM_TARGET_PHASE.Any.name())) {
|
||||||
if (notificationWhen.getLast_invoked_step() == null) {
|
if (notificationWhen.getLast_invoked_step() == null) {
|
||||||
// no filtering on lastInvokedStep
|
// no filtering on lastInvokedStep
|
||||||
filteredList.add(notificationWhen);
|
filteredList.add(notificationWhen);
|
||||||
|
@ -171,24 +156,33 @@ public class ManageDoActionNotification {
|
||||||
/**
|
/**
|
||||||
* Gets the list user compliant to roles.
|
* Gets the list user compliant to roles.
|
||||||
*
|
*
|
||||||
* @param notificationFor the notification for
|
* @param notificationFor the notification for
|
||||||
* @param itemObserved the item observed
|
* @param itemObserved the item observed
|
||||||
|
* @param ignoreUserCaller the ignore user caller
|
||||||
* @return the list user compliant to roles
|
* @return the list user compliant to roles
|
||||||
*/
|
*/
|
||||||
// GET LIST USER COMPLIANT TO ROLES
|
// GET LIST USER COMPLIANT TO ROLES, ignore USER caller
|
||||||
public List<User> getListUserCompliantToRoles(NotificationFor notificationFor, ItemObserved<Project> itemObserved) {
|
public List<User> getListUserCompliantToRoles(NotificationFor notificationFor, ItemObserved<Project> itemObserved,
|
||||||
log.debug("getListUserCompliantToRoles called for scope: {}", UserUtils.getCurrent().getContext());
|
boolean ignoreUserCaller) {
|
||||||
|
log.debug("getListUserCompliantToRoles called for scope: {}, ignore user caller: {}", itemObserved.getContext(),
|
||||||
|
ignoreUserCaller);
|
||||||
|
|
||||||
List<String> notifyUserWithRoles = notificationFor.getRoles();
|
List<String> notifyUserWithRoles = notificationFor.getRoles();
|
||||||
List<User> notifyUsers = new ArrayList<User>();
|
List<User> notifyUsers = new ArrayList<User>();
|
||||||
String anyRole = NotificationGenericConstants.CUSTOM_USER_ROLES.Any.name();
|
String anyRole = NotificationGenericConstants.CUSTOM_USER_ROLES.Any.name();
|
||||||
SocialClients socialClients = new SocialClients();
|
SocialClients socialClients = new SocialClients();
|
||||||
|
User userCaller = itemObserved.getUserCaller();
|
||||||
if (notifyUserWithRoles.contains(anyRole)) {
|
if (notifyUserWithRoles.contains(anyRole)) {
|
||||||
try {
|
try {
|
||||||
// String token = AccessTokenProvider.instance.set(s);
|
// String token = AccessTokenProvider.instance.set(s);
|
||||||
List<String> listUsername = socialClients.getUsernamesByScope();
|
List<String> listUsername = socialClients.getUsernamesByScope();
|
||||||
notifyUsers.addAll(
|
notifyUsers.addAll(
|
||||||
listUsername.stream().map(username -> new User(username, null)).collect(Collectors.toList()));
|
listUsername.stream().map(username -> new User(username, null)).collect(Collectors.toList()));
|
||||||
|
|
||||||
|
if (ignoreUserCaller) {
|
||||||
|
notifyUsers.removeIf(u -> u.equals(userCaller));
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error on reading users from scope {}: ", UserUtils.getCurrent().getContext(), e);
|
log.error("Error on reading users from scope {}: ", UserUtils.getCurrent().getContext(), e);
|
||||||
}
|
}
|
||||||
|
@ -198,7 +192,6 @@ public class ManageDoActionNotification {
|
||||||
|
|
||||||
// We need to create the list of users that must be notified
|
// We need to create the list of users that must be notified
|
||||||
for (String role : notifyUserWithRoles) {
|
for (String role : notifyUserWithRoles) {
|
||||||
// Reading the list of users in the VRE with specific role
|
|
||||||
// Creator of the item
|
// Creator of the item
|
||||||
String itemCreatorRole = NotificationGenericConstants.CUSTOM_USER_ROLES.Item_Creator.name();
|
String itemCreatorRole = NotificationGenericConstants.CUSTOM_USER_ROLES.Item_Creator.name();
|
||||||
if (role.compareTo(itemCreatorRole) == 0) {
|
if (role.compareTo(itemCreatorRole) == 0) {
|
||||||
|
@ -213,12 +206,17 @@ public class ManageDoActionNotification {
|
||||||
UserUtils.getCurrent().getContext(), e);
|
UserUtils.getCurrent().getContext(), e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Reading the list of users in the VRE with specific role
|
||||||
try {
|
try {
|
||||||
List<String> listUsernameForRole = socialClients.getUsernamesByRole(role);
|
List<String> listUsernameForRole = socialClients.getUsernamesByRole(role);
|
||||||
notifyUsers.addAll(listUsernameForRole.stream()
|
notifyUsers.addAll(listUsernameForRole.stream()
|
||||||
.map(username -> new User(username,
|
.map(username -> new User(username,
|
||||||
Stream.of(role).collect(Collectors.toCollection(HashSet::new))))
|
Stream.of(role).collect(Collectors.toCollection(HashSet::new))))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
|
if (ignoreUserCaller) {
|
||||||
|
notifyUsers.removeIf(u -> u.equals(userCaller));
|
||||||
|
}
|
||||||
log.info("added {} users for role {}", notifyUsers.size(), role);
|
log.info("added {} users for role {}", notifyUsers.size(), role);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error on reading users from scope {}: ", UserUtils.getCurrent().getContext(), e);
|
log.error("Error on reading users from scope {}: ", UserUtils.getCurrent().getContext(), e);
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.gcube.application.cms.notifications.manage;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -11,11 +10,11 @@ import org.gcube.application.cms.notifications.config.Notify;
|
||||||
import org.gcube.application.cms.notifications.social.SocialClients;
|
import org.gcube.application.cms.notifications.social.SocialClients;
|
||||||
import org.gcube.application.cms.notifications.substitutor.NMessagesPlaceholdersSubstitutorUtil;
|
import org.gcube.application.cms.notifications.substitutor.NMessagesPlaceholdersSubstitutorUtil;
|
||||||
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||||
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
||||||
import org.gcube.portal.databook.shared.Post;
|
import org.gcube.portal.databook.shared.Post;
|
||||||
import org.gcube.social_networking.social_networking_client_library.NotificationClient;
|
import org.gcube.social_networking.social_networking_client_library.NotificationClient;
|
||||||
import org.gcube.social_networking.socialnetworking.model.beans.PostInputBean;
|
import org.gcube.social_networking.socialnetworking.model.beans.PostInputBean;
|
||||||
import org.gcube.social_networking.socialnetworking.model.beans.Recipient;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEvent;
|
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEvent;
|
||||||
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEventType;
|
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEventType;
|
||||||
|
|
||||||
|
@ -24,54 +23,44 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class NotifyUser {
|
public class NotifyUser {
|
||||||
|
|
||||||
private User recipientUser;
|
private List<User> recipientUsers;
|
||||||
private NMessagesPlaceholdersSubstitutorUtil nMPlaceholdersSUtil;
|
private NMessagesPlaceholdersSubstitutorUtil nMPlaceholdersSUtil;
|
||||||
private List<NotificationWhen> listNotificationWhen;
|
private List<NotificationWhen> listNotificationWhen;
|
||||||
private SocialClients socialClients;
|
private SocialClients socialClients;
|
||||||
|
private CatalogueEventType catalogueEventType;
|
||||||
|
|
||||||
public NotifyUser(SocialClients socialClients, List<NotificationWhen> listWhen,
|
public NotifyUser(SocialClients socialClients, List<NotificationWhen> listWhen,
|
||||||
NMessagesPlaceholdersSubstitutorUtil nMPlaceholdersSUtil, User recipientUser) {
|
NMessagesPlaceholdersSubstitutorUtil nMPlaceholdersSUtil, List<User> recipientUsers, CatalogueEventType catalogueEventType) {
|
||||||
this.socialClients = socialClients;
|
this.socialClients = socialClients;
|
||||||
this.listNotificationWhen = listWhen;
|
this.listNotificationWhen = listWhen;
|
||||||
this.recipientUser = recipientUser;
|
this.recipientUsers = recipientUsers;
|
||||||
this.nMPlaceholdersSUtil = nMPlaceholdersSUtil;
|
this.nMPlaceholdersSUtil = nMPlaceholdersSUtil;
|
||||||
|
this.catalogueEventType = catalogueEventType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void send() throws Exception {
|
public void send() throws Exception {
|
||||||
log.info("send call...");
|
log.info("send notify...");
|
||||||
List<Notify> listNotifies = toNotify();
|
List<Notify> listNotifies = toNotify();
|
||||||
|
|
||||||
// TODO
|
|
||||||
// NotificationClient client = new NotificationClient();
|
|
||||||
// client.send ??????
|
|
||||||
|
|
||||||
for (Notify notify : listNotifies) {
|
for (Notify notify : listNotifies) {
|
||||||
switch (notify.getType()) {
|
switch (notify.getType()) {
|
||||||
case USER_MESSAGE:
|
case USER_POST:
|
||||||
log.info("Notification type {}, send: {}", notify.getType(), notify.getSend());
|
log.info("Notification type {}, send: {}", notify.getType(), notify.getSend());
|
||||||
if (notify.getSend()) {
|
if (notify.getSend()) {
|
||||||
log.debug("Building message...");
|
log.debug("Building message...");
|
||||||
String subject = "Message";
|
String subject = "Message";
|
||||||
String body = null;
|
String body = null;
|
||||||
|
|
||||||
// PostClient postClient = socialClients.getPostClient();
|
|
||||||
// PostInputBean postInputBean = new PostInputBean();
|
|
||||||
// postInputBean.setEnablenotification(true);
|
|
||||||
// postInputBean.setText(message);
|
|
||||||
//
|
|
||||||
// socialClients.writeUserPost(null)
|
|
||||||
|
|
||||||
subject = nMPlaceholdersSUtil.replacePlaceholder(notify.getPlaceholder_title());
|
subject = nMPlaceholdersSUtil.replacePlaceholder(notify.getPlaceholder_title());
|
||||||
body = nMPlaceholdersSUtil.replacePlaceholder(notify.getPlaceholder_msg());
|
body = nMPlaceholdersSUtil.replacePlaceholder(notify.getPlaceholder_msg());
|
||||||
|
|
||||||
log.debug("subject: {}", subject);
|
log.debug("subject: {}", subject);
|
||||||
log.debug("body: {}", body);
|
log.debug("body: {}", body);
|
||||||
List<Recipient> rec = Arrays.asList(new Recipient(recipientUser.getUsername()));
|
log.info("Sending message to users: {}", recipientUsers);
|
||||||
log.info("Sending message to users: {}", rec);
|
|
||||||
|
postMessage(subject, body, catalogueEventType);
|
||||||
|
|
||||||
// sendNotification(null);
|
|
||||||
// MessageInputBean message = new MessageInputBean(subject, body, new ArrayList<Recipient>(rec));
|
|
||||||
// String idMessage = socialClients.writeMessage(message);
|
|
||||||
// log.info("Message sent with id: {}", idMessage);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case VRE_POST:
|
case VRE_POST:
|
||||||
|
@ -92,12 +81,61 @@ public class NotifyUser {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Notify> toNotify() {
|
||||||
|
List<Notify> listNotifies = new ArrayList<Notify>();
|
||||||
|
for (NotificationWhen notificationWhen : listNotificationWhen) {
|
||||||
|
listNotifies.addAll(notificationWhen.getNotify().stream().filter(n -> n.getSend() == true)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
return listNotifies;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void postMessage(String subject, String bodyMessage, CatalogueEventType catalogueEventType) throws Exception {
|
||||||
|
CatalogueEvent catalogueEvent = getCatalogueEvent(subject, bodyMessage);
|
||||||
|
SecretManager secretManager = SecretManagerProvider.instance.get();
|
||||||
|
|
||||||
|
//GET geoportal SECRET
|
||||||
|
|
||||||
|
// Secret secret = Constants.getCatalogueSecret();
|
||||||
|
// if(notificationSentByGCat) {
|
||||||
|
// secretManager.startSession(secret);
|
||||||
|
// }
|
||||||
|
// try {
|
||||||
|
// sendNotification(catalogueEvent);
|
||||||
|
// }finally {
|
||||||
|
// if(notificationSentByGCat) {
|
||||||
|
// secretManager.endSession();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
sendNotification(catalogueEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CatalogueEvent getCatalogueEvent(String subject, String bodyMessage) throws Exception {
|
||||||
|
CatalogueEvent catalogueEvent = new CatalogueEvent();
|
||||||
|
catalogueEvent.setType(catalogueEventType);
|
||||||
|
catalogueEvent.setNotifyText(bodyMessage);
|
||||||
|
catalogueEvent.setItemId(subject);
|
||||||
|
String itemURL = nMPlaceholdersSUtil.getPlaceholderMapValues().getGisLink();
|
||||||
|
if(itemURL!=null) {
|
||||||
|
catalogueEvent.setItemURL(new URL(itemURL));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adding recipient users
|
||||||
|
String[] usersToNotify = recipientUsers.stream().map(u -> u.getUsername()).toArray(String[]::new);
|
||||||
|
catalogueEvent.setIdsToNotify(usersToNotify);
|
||||||
|
catalogueEvent.setIdsAsGroup(false);
|
||||||
|
|
||||||
|
return catalogueEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void sendNotification(CatalogueEvent catalogueEvent) throws Exception {
|
protected void sendNotification(CatalogueEvent catalogueEvent) throws Exception {
|
||||||
Thread thread = new Thread() {
|
Thread thread = new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
log.trace("{} is going to send the following notification {}", SecretManagerProvider.instance.get().getUser().getUsername(), catalogueEvent);
|
log.trace("{} is going to send the following notification {}", SecretManagerProvider.instance.get().getUser().getUsername(), catalogueEvent);
|
||||||
NotificationClient nc = new NotificationClient();
|
NotificationClient nc = socialClients.getNotificationClient();
|
||||||
nc.sendCatalogueEvent(catalogueEvent);
|
nc.sendCatalogueEvent(catalogueEvent);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
log.error("Error while sending notification.", e);
|
log.error("Error while sending notification.", e);
|
||||||
|
@ -122,13 +160,6 @@ public class NotifyUser {
|
||||||
return catalogueEvent;
|
return catalogueEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Notify> toNotify() {
|
|
||||||
List<Notify> listNotifies = new ArrayList<Notify>();
|
|
||||||
for (NotificationWhen notificationWhen : listNotificationWhen) {
|
|
||||||
listNotifies.addAll(notificationWhen.getNotify().stream().filter(n -> n.getSend() == true)
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
return listNotifies;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,10 @@ public class MappingToCatalogue {
|
||||||
|
|
||||||
// SimpleLifeCycleManager
|
// SimpleLifeCycleManager
|
||||||
if (itemPhase.equals(SimpleLifeCycleManager.Phases.PUBLISHED)
|
if (itemPhase.equals(SimpleLifeCycleManager.Phases.PUBLISHED)
|
||||||
&& lastInvokedStep.equals(SimpleLifeCycleManager.Steps.PUBLISH.getId())) {
|
&& (lastInvokedStep == null || lastInvokedStep.equals(SimpleLifeCycleManager.Steps.PUBLISH.getId()))) {
|
||||||
return CatalogueEventType.ITEM_SUBMITTED;
|
return CatalogueEventType.ITEM_SUBMITTED;
|
||||||
} else if (itemPhase.equals(SimpleLifeCycleManager.Phases.UNPUBLISHED)
|
} else if (itemPhase.equals(SimpleLifeCycleManager.Phases.UNPUBLISHED) && (lastInvokedStep == null
|
||||||
&& lastInvokedStep.equals(SimpleLifeCycleManager.Steps.UNPUBLISH.getId())) {
|
|| lastInvokedStep.equals(SimpleLifeCycleManager.Steps.UNPUBLISH.getId()))) {
|
||||||
// TODO
|
// TODO
|
||||||
// Missing ITEM UNPUBLISHED;
|
// Missing ITEM UNPUBLISHED;
|
||||||
|
|
||||||
|
@ -22,16 +22,16 @@ public class MappingToCatalogue {
|
||||||
|
|
||||||
// Default3PhaseManager
|
// Default3PhaseManager
|
||||||
if (itemPhase.equals(Default3PhaseManager.Phases.PENDING_APPROVAL)
|
if (itemPhase.equals(Default3PhaseManager.Phases.PENDING_APPROVAL)
|
||||||
&& lastInvokedStep.equals(Default3PhaseManager.STEPS.SUBMIT.getId())) {
|
&& (lastInvokedStep == null || lastInvokedStep.equals(Default3PhaseManager.STEPS.SUBMIT.getId()))) {
|
||||||
return CatalogueEventType.ITEM_SUBMITTED;
|
return CatalogueEventType.ITEM_SUBMITTED;
|
||||||
} else if (itemPhase.equals(Default3PhaseManager.Phases.PUBLISHED)
|
} else if (itemPhase.equals(Default3PhaseManager.Phases.PUBLISHED)
|
||||||
&& lastInvokedStep.equals(Default3PhaseManager.STEPS.APPROVE.getId())) {
|
&& (lastInvokedStep == null || lastInvokedStep.equals(Default3PhaseManager.STEPS.APPROVE.getId()))) {
|
||||||
return CatalogueEventType.ITEM_PUBLISHED;
|
return CatalogueEventType.ITEM_PUBLISHED;
|
||||||
} else if (itemPhase.equals(LifecycleInformation.CommonPhases.DRAFT_PHASE)
|
} else if (itemPhase.equals(LifecycleInformation.CommonPhases.DRAFT_PHASE)
|
||||||
&& lastInvokedStep.equals(Default3PhaseManager.STEPS.REJECT.getId())) {
|
&& (lastInvokedStep == null || lastInvokedStep.equals(Default3PhaseManager.STEPS.REJECT.getId()))) {
|
||||||
return CatalogueEventType.ITEM_REJECTED;
|
return CatalogueEventType.ITEM_REJECTED;
|
||||||
} else if (itemPhase.equals(LifecycleInformation.CommonPhases.DRAFT_PHASE)
|
} else if (itemPhase.equals(LifecycleInformation.CommonPhases.DRAFT_PHASE)
|
||||||
&& lastInvokedStep.equals(Default3PhaseManager.STEPS.UNPUBLISH.getId())) {
|
&& (lastInvokedStep == null || lastInvokedStep.equals(Default3PhaseManager.STEPS.UNPUBLISH.getId()))) {
|
||||||
// TODO
|
// TODO
|
||||||
// Missing ITEM UNPUBLISHED;
|
// Missing ITEM UNPUBLISHED;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.gcube.portal.databook.shared.Post;
|
import org.gcube.portal.databook.shared.Post;
|
||||||
import org.gcube.social_networking.social_networking_client_library.MessageClient;
|
import org.gcube.social_networking.social_networking_client_library.MessageClient;
|
||||||
|
import org.gcube.social_networking.social_networking_client_library.NotificationClient;
|
||||||
import org.gcube.social_networking.social_networking_client_library.PostClient;
|
import org.gcube.social_networking.social_networking_client_library.PostClient;
|
||||||
import org.gcube.social_networking.social_networking_client_library.UserClient;
|
import org.gcube.social_networking.social_networking_client_library.UserClient;
|
||||||
import org.gcube.social_networking.socialnetworking.model.beans.MessageInputBean;
|
import org.gcube.social_networking.socialnetworking.model.beans.MessageInputBean;
|
||||||
|
@ -25,6 +26,7 @@ public class SocialClients {
|
||||||
private PostClient postClient;
|
private PostClient postClient;
|
||||||
private MessageClient messagesClient;
|
private MessageClient messagesClient;
|
||||||
private UserClient userClient;
|
private UserClient userClient;
|
||||||
|
private NotificationClient notificationClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new social util.
|
* Instantiates a new social util.
|
||||||
|
@ -47,6 +49,12 @@ public class SocialClients {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error on instacing {}: ", UserClient.class.getSimpleName(), e);
|
log.error("Error on instacing {}: ", UserClient.class.getSimpleName(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.notificationClient = new NotificationClient();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error on instacing {}: ", NotificationClient.class.getSimpleName(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,5 +114,9 @@ public class SocialClients {
|
||||||
public UserClient getUserClient() {
|
public UserClient getUserClient() {
|
||||||
return userClient;
|
return userClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NotificationClient getNotificationClient() {
|
||||||
|
return notificationClient;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,5 +64,9 @@ public class NMessagesPlaceholdersSubstitutorUtil {
|
||||||
log.info("placeholderMapValues is null, returning source: {}", notificationPlaceholder);
|
log.info("placeholderMapValues is null, returning source: {}", notificationPlaceholder);
|
||||||
return notificationPlaceholder;
|
return notificationPlaceholder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SubstitutorMessagesMap getPlaceholderMapValues() {
|
||||||
|
return placeholderMapValues;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package org.gcube.application.cms.notifications.substitutor;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class SubstitutorMessagesMap extends HashMap<String, String> {
|
public class SubstitutorMessagesMap extends HashMap<String, String> {
|
||||||
|
|
||||||
public static final String PROJECT_ID = "project_id";
|
public static final String PROJECT_ID = "project_id";
|
||||||
public static final String GIS_LINK = "gis_link";
|
public static final String GIS_LINK = "gis_link";
|
||||||
public static final String PROJECT_NAME = "project_name";
|
public static final String PROJECT_NAME = "project_name";
|
||||||
|
@ -35,5 +35,8 @@ public class SubstitutorMessagesMap extends HashMap<String, String> {
|
||||||
public String putProjectId(String projectId) {
|
public String putProjectId(String projectId) {
|
||||||
return super.put(PROJECT_ID, projectId);
|
return super.put(PROJECT_ID, projectId);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
public String getGisLink() {
|
||||||
|
return super.get(GIS_LINK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue