From 38a879a189d41ed32c04932a0b5ddc6212d6a582 Mon Sep 17 00:00:00 2001 From: "costantino.perciante" Date: Thu, 16 Jun 2016 09:08:37 +0000 Subject: [PATCH] Fixed email's subject when comments are made at root level in news feed (the vreName is extracted from the feed) git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerSocial@129132 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../social/mailing/NotificationMail.java | 14 ++++++++++++-- .../social/mailing/SocialMailingUtil.java | 3 +-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/NotificationMail.java b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/NotificationMail.java index faaf2b2..b33ff58 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/NotificationMail.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/NotificationMail.java @@ -85,6 +85,7 @@ public class NotificationMail { Feed feed = null; List comments = null; String commentKey = null; + String vreNameFromFeed = null; if (notification2Send.getType() != NotificationType.MESSAGE) { try{ @@ -98,20 +99,29 @@ public class NotificationMail { String[] splittedVREName = feed.getVreid().split("/"); if(vreName == null) vreName = splittedVREName[splittedVREName.length - 1]; + + // if the notification is a comment, extract the vre name from the feed and not from the scope + if(notification2Send.getType().equals(NotificationType.COMMENT) || notification2Send.getType().equals(NotificationType.OWN_COMMENT)) + vreNameFromFeed = splittedVREName[splittedVREName.length - 1]; } catch(Exception e){ _log.error("Unable to retrieve feeds/comments", e); } } + + String vreNameToUse = (vreNameFromFeed == null) ? vreName : vreNameFromFeed; + + _log.debug("VRE Name for the email's subject is going to be " + + vreNameToUse + "[vreNameFromFeed is " + vreNameFromFeed + ", vreName is " + vreName + "]"); // set subject - msg2Return.setSubject(SocialMailingUtil.getSubjectByNotificationType(notification2Send, vreName, user.getFirstName(), hashtags)); + msg2Return.setSubject(SocialMailingUtil.getSubjectByNotificationType(notification2Send, vreNameToUse, user.getFirstName(), hashtags)); final MimeBodyPart textPart = new MimeBodyPart(); textPart.setContent(SocialMailingUtil.getTextEmail(notification2Send, user.getFirstName(), portalURL, siteLandingPagePath, email, feed, comments, commentKey, hashtags), "text/plain; charset=UTF-8"); final MimeBodyPart htmlPart = new MimeBodyPart(); - htmlPart.setContent(SocialMailingUtil.getHTMLEmail(notification2Send, user.getFirstName(), portalURL, siteLandingPagePath, email, vreName, feed, comments, commentKey, hashtags), "text/html; charset=UTF-8"); + htmlPart.setContent(SocialMailingUtil.getHTMLEmail(notification2Send, user.getFirstName(), portalURL, siteLandingPagePath, email, feed, comments, commentKey, hashtags), "text/html; charset=UTF-8"); final Multipart mp = new MimeMultipart("alternative"); mp.addBodyPart(textPart); diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java index 270bd6e..be4d2e0 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java @@ -45,7 +45,6 @@ public class SocialMailingUtil { String portalURL, String siteLandingPagePath, String email, - String vreName, Feed feed, List comments, String commentKey, @@ -198,7 +197,7 @@ public class SocialMailingUtil { * @param vreName * @return */ - protected static String getSubjectByNotificationType(Notification notification2Save, String vreName, String userFirstName, String ...optionalParams) { + protected static String getSubjectByNotificationType(Notification notification2Save, String vreName, String userFirstName, String ...optionalParams) { switch (notification2Save.getType()) { case LIKE: return notification2Save.getSenderFullName()+" favorited your post in " + (vreName == null? "" : vreName);