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
This commit is contained in:
Massimiliano Assante 2015-10-14 15:43:56 +00:00
parent 28c94379d4
commit b05daeb5b2
4 changed files with 36 additions and 8 deletions

View File

@ -16,12 +16,12 @@
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>

View File

@ -0,0 +1,2 @@
disabled=06target
eclipse.preferences.version=1

View File

@ -17,7 +17,7 @@
<description>
gCube Notifications Common Library is a common library containing shared code for Notification of social events to users.
</description>
<name>invites-common-library</name>
<name>notifications-common-library</name>
<scm>
<connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/portal/${project.artifactId}</connection>
<developerConnection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/portal/${project.artifactId}</developerConnection>

View File

@ -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<String> recipientIds;
private List<GenericItemBean> recipients;
private NotificationsManager nm;
public MessageNotificationsThread(List<String> recipientIds, String postId, String subjectText, String messageText, NotificationsManager nm) {
public MessageNotificationsThread(List<GenericItemBean> 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<GenericItemBean> temp = new ArrayList<GenericItemBean>(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<GenericItemBean> toCopy) {
String[] toReturn = new String[toCopy.size()];
int i = 0;
for (GenericItemBean item : toCopy) {
toReturn[i] = item.getAlternativeName();
i++;
}
return toReturn;
}
private List<GenericItemBean> copy(List<GenericItemBean> toCopy) {
List<GenericItemBean> toReturn = new ArrayList<GenericItemBean>();
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.