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
This commit is contained in:
costantino.perciante 2016-06-16 09:08:37 +00:00
parent 1013df1f25
commit 38a879a189
2 changed files with 13 additions and 4 deletions

View File

@ -85,6 +85,7 @@ public class NotificationMail {
Feed feed = null; Feed feed = null;
List<Comment> comments = null; List<Comment> comments = null;
String commentKey = null; String commentKey = null;
String vreNameFromFeed = null;
if (notification2Send.getType() != NotificationType.MESSAGE) { if (notification2Send.getType() != NotificationType.MESSAGE) {
try{ try{
@ -98,20 +99,29 @@ public class NotificationMail {
String[] splittedVREName = feed.getVreid().split("/"); String[] splittedVREName = feed.getVreid().split("/");
if(vreName == null) if(vreName == null)
vreName = splittedVREName[splittedVREName.length - 1]; 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){ } catch(Exception e){
_log.error("Unable to retrieve feeds/comments", 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 // 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(); final MimeBodyPart textPart = new MimeBodyPart();
textPart.setContent(SocialMailingUtil.getTextEmail(notification2Send, user.getFirstName(), portalURL, siteLandingPagePath, email, feed, comments, commentKey, hashtags), "text/plain; charset=UTF-8"); textPart.setContent(SocialMailingUtil.getTextEmail(notification2Send, user.getFirstName(), portalURL, siteLandingPagePath, email, feed, comments, commentKey, hashtags), "text/plain; charset=UTF-8");
final MimeBodyPart htmlPart = new MimeBodyPart(); 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"); final Multipart mp = new MimeMultipart("alternative");
mp.addBodyPart(textPart); mp.addBodyPart(textPart);

View File

@ -45,7 +45,6 @@ public class SocialMailingUtil {
String portalURL, String portalURL,
String siteLandingPagePath, String siteLandingPagePath,
String email, String email,
String vreName,
Feed feed, Feed feed,
List<Comment> comments, List<Comment> comments,
String commentKey, String commentKey,
@ -198,7 +197,7 @@ public class SocialMailingUtil {
* @param vreName * @param vreName
* @return * @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()) { switch (notification2Save.getType()) {
case LIKE: case LIKE:
return notification2Save.getSenderFullName()+" favorited your post in " + (vreName == null? "" : vreName); return notification2Save.getSenderFullName()+" favorited your post in " + (vreName == null? "" : vreName);