diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java
index e3b3f02..6f5ca61 100644
--- a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java
+++ b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java
@@ -72,7 +72,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
* @param notification2Save the notification instance to save
* @return true if the notification was sent ok
*/
- private boolean saveNotification(Notification notification2Save) {
+ private boolean saveNotification(Notification notification2Save, String ... hashtags) {
_log.trace("Trying to send notification to: " + notification2Save.getUserid() + " Type: " + notification2Save.getType());
if (notification2Save.getSenderid().compareTo(notification2Save.getUserid()) == 0) {
_log.trace("Sender and Receiver are the same " + notification2Save.getUserid() + " Notification Stopped");
@@ -93,15 +93,15 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
_log.error("Error While trying to save Notification");
}
if (channels.contains(NotificationChannelType.EMAIL))
- EmailPlugin.getInstance().sendNotification(notification2Save, aslSession.getGroupName(), portalName, senderEmail);
+ EmailPlugin.getInstance().sendNotification(notification2Save, aslSession.getGroupName(), portalName, senderEmail, hashtags);
if (channels.isEmpty()) {
_log.info("Notification was not needed as "+ notification2Save.getUserid() +" decided not to be notified for " + notification2Save.getType());
result = true;
}
return result;
-
}
+
/**
* return the url of the application if exists in the profile
* @return .
@@ -454,10 +454,10 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
* {@inheritDoc}
*/
@Override
- public boolean notifyPost(String userIdToNotify, String feedid, String feedText) {
+ public boolean notifyPost(String userIdToNotify, String feedid, String feedText, String ... hashtags) {
StringBuilder notificationText = new StringBuilder();
- notificationText.append("posted a news on ").append(aslSession.getGroupName()).append(":") // has done something
+ notificationText.append("posted a news on ").append(aslSession.getGroupName()).append(":") // has done something
.append("
").append(escapeHtml(feedText)).append(". ")
.append("
Follow the discussion and comment it. ");
@@ -473,7 +473,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
aslSession.getUsername(),
aslSession.getUserFullName(),
aslSession.getUserAvatarId());
- return saveNotification(not);
+ return saveNotification(not, hashtags);
}
/**
* {@inheritDoc}
diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java
index 416739a..26cb5b7 100644
--- a/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java
+++ b/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java
@@ -171,7 +171,7 @@ public interface NotificationsManager {
* @param feedText the liked feed text or a portion of it
* @return true if the notification is correctly delivered, false otherwise
*/
- boolean notifyPost(String userIdToNotify, String feedid, String feedText);
+ boolean notifyPost(String userIdToNotify, String feedid, String feedText, String ... hashtags);
/**
* use to notify a user that someone commented on his post
*
diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailNotificationsConsumer.java b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailNotificationsConsumer.java
index 558ef2b..95d13fe 100644
--- a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailNotificationsConsumer.java
+++ b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailNotificationsConsumer.java
@@ -133,7 +133,7 @@ public class EmailNotificationsConsumer extends Thread {
//sync method to ensure the producer do not put new emails in the meantime
synchronized(EmailPlugin.BUFFER_EMAILS){
for (NotificationMail mail : EmailPlugin.BUFFER_EMAILS) {
- Message m = EmailPlugin.getMessageNotification(session, mail.getNotification2Send(), mail.getVreName(), mail.getPortalName(), mail.getSenderEmail());
+ Message m = EmailPlugin.getMessageNotification(session, mail.getNotification2Send(), mail.getVreName(), mail.getPortalName(), mail.getSenderEmail(), mail.getHashtags());
if (m != null) {
m.saveChanges();
Address[] addresses = m.getAllRecipients();
diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java
index fa77a4b..6004369 100644
--- a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java
+++ b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java
@@ -37,24 +37,34 @@ public class EmailPlugin {
protected static final int SECONDS2WAIT = 60;
private static EmailPlugin singleton;
-
+
public static EmailPlugin getInstance() {
if (singleton == null)
singleton = new EmailPlugin();
return singleton;
}
-
+
private EmailPlugin() {
new EmailNotificationsConsumer().start();
}
-
+
protected static ArrayList BUFFER_EMAILS = new ArrayList();
-
- private static String getHTMLEmail(Notification notification2Save, String userFirstName, String portalURL, String email) {
+
+ private static String getHTMLEmail(Notification notification2Save, String userFirstName, String portalURL, String email, String ... hashtags) {
String removedMarkup = notification2Save.getDescription().replaceAll("&", "&");
removedMarkup = removedMarkup.replaceAll(">", ">");
removedMarkup = removedMarkup.replaceAll("<", "<");
+
+ if (hashtags != null && hashtags.length > 0) {
+ _log.debug("editing hyperlinks for mail client");
+ //notification2Save uri contains the absoulte path to the feed in the correct channel, e.g. /group/ustore_vre?oid=f1637958-34d0-48fc-b5ad-13b1116e389d
+ String pathToVRE = "/group/data-e-infrastructure-gateway?";
+ if (notification2Save.getUri().split("\\?").length > 0) {
+ pathToVRE = notification2Save.getUri().split("\\?")[0];
+ }
+ removedMarkup = removedMarkup.replace("href=\"?", "href=\""+portalURL + pathToVRE + "?"); //because there is no indication of the portal
+ }
String sender = notification2Save.getSenderFullName();
if (notification2Save.getType() == NotificationType.DOCUMENT_WORKFLOW_STEP_REQUEST_TASK)
@@ -91,11 +101,18 @@ public class EmailPlugin {
}
- private static String getTextEmail(Notification notification2Save, String userFirstName, String portalURL, String email) {
+ private static String getTextEmail(Notification notification2Save, String userFirstName, String portalURL, String email, String[] hashtags) {
String removedMarkup = convertHTML2Text(notification2Save.getDescription());
-
+ if (hashtags != null && hashtags.length > 0) {
+ for (int i = 0; i < hashtags.length; i++) {
+ _log.debug("replacing " + hashtags[i]);
+ removedMarkup = removedMarkup.replace(hashtags[i], " " + hashtags[i] + " "); //because removing html cause trimming we put spaces back
+ }
+ }
+ _log.debug("*****removedMarkup=\n" + removedMarkup);
+
String sender = notification2Save.getSenderFullName();
if (notification2Save.getType() == NotificationType.DOCUMENT_WORKFLOW_STEP_REQUEST_TASK)
sender = "";
@@ -119,9 +136,9 @@ public class EmailPlugin {
return body.toString();
}
-
-
+
+
/**
* Convert html into simple text
*
@@ -135,8 +152,8 @@ public class EmailPlugin {
removedMarkup = removedMarkup.replaceAll("<", "<");
String text = removedMarkup;
try {
- Document document = Jsoup.parse(removedMarkup);
- Element body = document.body();
+ Document document = Jsoup.parse(removedMarkup);
+ Element body = document.body();
text = buildStringFromNode(body).toString();
}
catch (Exception e) {
@@ -145,36 +162,36 @@ public class EmailPlugin {
}
return text;
}
-
+
private static StringBuffer buildStringFromNode(Node node) {
- StringBuffer buffer = new StringBuffer();
+ StringBuffer buffer = new StringBuffer();
- if (node instanceof TextNode) {
- TextNode textNode = (TextNode) node;
- buffer.append(textNode.text().trim());
- }
+ if (node instanceof TextNode) {
+ TextNode textNode = (TextNode) node;
+ buffer.append(textNode.text().trim());
+ }
- for (Node childNode : node.childNodes()) {
- buffer.append(buildStringFromNode(childNode));
- }
+ for (Node childNode : node.childNodes()) {
+ buffer.append(buildStringFromNode(childNode));
+ }
- if (node instanceof Element) {
- Element element = (Element) node;
- String tagName = element.tagName();
- if ("p".equals(tagName) || "br".equals(tagName)) {
- buffer.append("\n");
- }
- }
+ if (node instanceof Element) {
+ Element element = (Element) node;
+ String tagName = element.tagName();
+ if ("p".equals(tagName) || "br".equals(tagName)) {
+ buffer.append("\n");
+ }
+ }
- return buffer;
+ return buffer;
}
private static String getActionLink(Notification notification2Save, String portalURL) {
StringBuilder actionLink = new StringBuilder("