From 678f5f5f4a8148f5cbb2c8a7056fa0fa02a27df2 Mon Sep 17 00:00:00 2001 From: "costantino.perciante" Date: Fri, 19 Feb 2016 13:05:20 +0000 Subject: [PATCH] Vrename is reported in the email's subject. Changelog update for the new version 0.16.0 git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerSocial@124355 82a268e6-3cf1-43bd-a215-b396298e98cf --- distro/changelog.xml | 20 ++++++-- .../social/mailing/EmailPlugin.java | 49 ++++++++++++++----- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/distro/changelog.xml b/distro/changelog.xml index 977fb5a..0afeafb 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,4 +1,9 @@ + + Added original discussion in email's body + Vre's name is now reported in email's subject + Added message body in notifications for messages @@ -7,17 +12,22 @@ Added Support for user reply via mail to post and comment - notifications + notifications + Added Support for user subscribe/favorite via mail to post - notifications + notifications + Added Notifications support for Tabular Data Manager Revised the way we shorten posts' text when this is very long, - better heuristic used + better heuristic used + Revised the way we format mail notification messages, user - text is now more clear and visible + text is now more clear and visible + Revised the way we provide back links for posts, removed assumption that News Feed is always present the default community - page + page + 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 836df28..116d8d9 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java @@ -174,7 +174,7 @@ public class EmailPlugin { body.append("Dear ").append(userFirstName).append(",") //dear .append("\n").append(sender).append(" ").append(removedMarkup) // has done something .append("\nsee: ").append(portalURL).append(notification2Save.getUri()) - .append(buildPlainTextDiscussion(feed, comments, commentKey)) + .append(buildPlainTextDiscussion(notification2Save, feed, comments, commentKey)) .append("\n----\n") .append("This message was sent to ") .append(email) @@ -199,6 +199,9 @@ public class EmailPlugin { try{ + if(notification2Save.getType().equals(NotificationType.POST_ALERT) || feed == null) + return ""; + String htmlPost = "
" + "
----

Original post:

"; // data formatter Format formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm a"); @@ -272,9 +275,12 @@ public class EmailPlugin { * @param commentKey if not null, when building the discussion stop at this comment. * @return a string representing the discussion */ - private static String buildPlainTextDiscussion(Feed feed, List comments, String commentKey){ + private static String buildPlainTextDiscussion(Notification notification2Save, Feed feed, List comments, String commentKey){ try{ + + if(notification2Save.getType().equals(NotificationType.POST_ALERT) || feed == null) + return ""; // build discussion String discussion = "\n\n----\n\nOriginal post:"; @@ -418,14 +424,31 @@ public class EmailPlugin { msg2Return.setFrom(new InternetAddress(senderEmail, portalName)); msg2Return.addRecipient(Message.RecipientType.TO, new InternetAddress(email)); - msg2Return.setSubject(getSubjectByNotificationType(notification2Save, portalUrl, vreName, user.getFirstName(), hashtags)); + // retrieve post/comments from its id (if possible) + Feed feed = null; + List comments = null; + String commentKey = null; - // retrieve post/comments from its id - String feedId = notification2Save.getSubjectid(); - Feed feed = store.readFeed(feedId); - List comments = store.getAllCommentByFeed(feedId); - Collections.sort(comments); // sort them - String commentKey = notification2Save.getCommentKey(); + try{ + String feedId = notification2Save.getSubjectid(); + feed = store.readFeed(feedId); + comments = store.getAllCommentByFeed(feedId); + Collections.sort(comments); // sort them + commentKey = notification2Save.getCommentKey(); + + // try to set vreName when notification is created in infrastructure scope + String[] splittedVREName = feed.getVreid().split("/"); + if(vreName == null) + vreName = splittedVREName[splittedVREName.length - 1]; + + }catch(Exception e){ + + _log.error("Unable to retrieve feeds/comments", e); + + } + + // set subject + msg2Return.setSubject(getSubjectByNotificationType(notification2Save, portalUrl, vreName, user.getFirstName(), hashtags)); final MimeBodyPart textPart = new MimeBodyPart(); textPart.setContent(getTextEmail(notification2Save, user.getFirstName(), portalUrl, email, feed, comments, commentKey, hashtags), "text/plain; charset=UTF-8"); @@ -454,9 +477,9 @@ public class EmailPlugin { private static String getSubjectByNotificationType(Notification notification2Save, String portalURL, String vreName, String userFirstName, String ...optionalParams) { switch (notification2Save.getType()) { case LIKE: - return notification2Save.getSenderFullName()+" favorited your post"; + return notification2Save.getSenderFullName()+" favorited your post in " + (vreName == null? "" : vreName); case COMMENT: - return notification2Save.getSenderFullName()+" commented on the post"; + return notification2Save.getSenderFullName()+" commented on the post in " + (vreName == null? "" : vreName); case MESSAGE: String messageSubject = (optionalParams != null && optionalParams.length > 0) ? optionalParams[0] : notification2Save.getSenderFullName()+" sent you a message"; @@ -482,9 +505,9 @@ public class EmailPlugin { case WP_ITEM_RENAMED: return notification2Save.getSenderFullName()+ " renamed an item in a shared folder"; case OWN_COMMENT: - return notification2Save.getSenderFullName() + " commented on your post"; + return notification2Save.getSenderFullName() + " commented on your post in " + (vreName == null? "" : vreName); case MENTION: - return notification2Save.getSenderFullName() + " mentioned you"; + return notification2Save.getSenderFullName() + " mentioned you in " + (vreName == null? "" : vreName); case POST_ALERT: String toReturn = notification2Save.getSenderFullName() + " shared a news on " + vreName; if (optionalParams != null) { //in this case optionalParams are the hashtags