From b05daeb5b23d8d7cae2434132b2acbb3a7358601 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Wed, 14 Oct 2015 15:43:56 +0000 Subject: [PATCH] Added support for messages reply via email git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/notifications-common-library@119768 82a268e6-3cf1-43bd-a215-b396298e98cf --- .project | 4 +-- .settings/org.eclipse.wst.validation.prefs | 2 ++ pom.xml | 2 +- .../thread/MessageNotificationsThread.java | 36 ++++++++++++++++--- 4 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 .settings/org.eclipse.wst.validation.prefs diff --git a/.project b/.project index ff7e935..c32be37 100644 --- a/.project +++ b/.project @@ -16,12 +16,12 @@ - org.eclipse.m2e.core.maven2Builder + org.eclipse.wst.validation.validationbuilder - org.eclipse.wst.validation.validationbuilder + org.eclipse.m2e.core.maven2Builder diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/pom.xml b/pom.xml index abd01e9..600cb91 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ gCube Notifications Common Library is a common library containing shared code for Notification of social events to users. - invites-common-library + notifications-common-library scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/portal/${project.artifactId} scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/portal/${project.artifactId} diff --git a/src/main/java/org/gcube/portal/notifications/thread/MessageNotificationsThread.java b/src/main/java/org/gcube/portal/notifications/thread/MessageNotificationsThread.java index 3d32d6a..2155158 100644 --- a/src/main/java/org/gcube/portal/notifications/thread/MessageNotificationsThread.java +++ b/src/main/java/org/gcube/portal/notifications/thread/MessageNotificationsThread.java @@ -1,8 +1,11 @@ package org.gcube.portal.notifications.thread; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.gcube.applicationsupportlayer.social.NotificationsManager; +import org.gcube.portal.notifications.bean.GenericItemBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,15 +20,15 @@ public class MessageNotificationsThread implements Runnable { private String messageText; private String messageId; private String subjectText; - private List recipientIds; + private List recipients; private NotificationsManager nm; - public MessageNotificationsThread(List recipientIds, String postId, String subjectText, String messageText, NotificationsManager nm) { + public MessageNotificationsThread(List recipients, String postId, String subjectText, String messageText, NotificationsManager nm) { super(); this.messageId = postId; this.messageText = messageText; this.subjectText = subjectText; - this.recipientIds = recipientIds; + this.recipients = recipients; this.nm = nm; } @@ -33,8 +36,14 @@ public class MessageNotificationsThread implements Runnable { public void run() { try { String checkedText = escapeHtmlAndTransformNewlines(messageText); - for (String userIdToNotify : recipientIds) { - if (nm.notifyMessageReceived(userIdToNotify, messageId, subjectText, checkedText)) + for (GenericItemBean userToNotify : recipients) { + String userIdToNotify = userToNotify.getName(); + List temp = new ArrayList(recipients.size()); + temp = copy(recipients); + temp.remove(userToNotify); + String[] otherRecipientsFullNames = getFullNamesOnly(temp); + + if (nm.notifyMessageReceived(userIdToNotify, messageId, subjectText, checkedText, otherRecipientsFullNames)) _log.trace("Sending message notifications to: " + userIdToNotify + " OK"); } } catch (Exception e) { @@ -42,6 +51,23 @@ public class MessageNotificationsThread implements Runnable { } } + private String[] getFullNamesOnly(List toCopy) { + String[] toReturn = new String[toCopy.size()]; + int i = 0; + for (GenericItemBean item : toCopy) { + toReturn[i] = item.getAlternativeName(); + i++; + } + return toReturn; + } + + private List copy(List toCopy) { + List toReturn = new ArrayList(); + for (GenericItemBean genericItemBean : toCopy) { + toReturn.add(genericItemBean); + } + return toReturn; + } /** * Escape an html string. Escaping data received from the client helps to * prevent cross-site script vulnerabilities.