From 54db46f5f4b67d4c35af9fc9dc1c7f4668038ff0 Mon Sep 17 00:00:00 2001 From: "costantino.perciante" Date: Fri, 20 Jan 2017 13:45:53 +0000 Subject: [PATCH] Added support to job notifications. Added support for ticket #6342. Moved back to version 1.2.0 in pom.xml. Added a new notifyPost method that accepts set types for hashtags and mentioned vre groups to avoid duplicates. git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerSocial@141666 82a268e6-3cf1-43bd-a215-b396298e98cf --- distro/changelog.xml | 2 + pom.xml | 2 +- .../ApplicationNotificationsManager.java | 179 +++++++++++++--- .../social/NotificationsManager.java | 20 +- .../social/mailing/EmailPlugin.java | 5 +- .../social/mailing/NotificationMail.java | 15 +- .../social/mailing/SocialMailingUtil.java | 201 +++++++++--------- 7 files changed, 292 insertions(+), 132 deletions(-) diff --git a/distro/changelog.xml b/distro/changelog.xml index 94fda66..4117e65 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -2,6 +2,8 @@ partially removed portal context dependency (where possible) + added support to job notifications + added support for ticket #6342 diff --git a/pom.xml b/pom.xml index 63919a3..a45eb49 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.applicationsupportlayer aslsocial - 1.3.0-SNAPSHOT + 1.2.0-SNAPSHOT jar Social Portal ASL Extension diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java index 37484b6..2024b7c 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java @@ -3,6 +3,7 @@ package org.gcube.applicationsupportlayer.social; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; +import java.util.Set; import java.util.UUID; import org.gcube.applicationsupportlayer.social.mailing.EmailPlugin; @@ -11,7 +12,6 @@ import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder; -import org.gcube.portal.databook.shared.ApplicationProfile; import org.gcube.portal.databook.shared.Notification; import org.gcube.portal.databook.shared.NotificationChannelType; import org.gcube.portal.databook.shared.NotificationType; @@ -40,7 +40,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen public static final String USER_WORKSPACE_FRIENDLY_URL = "/workspace"; public static final String USER_MESSAGES_FRIENDLY_URL = "/messages"; public static final String USER_NOTIFICATION_FRIENDLY_URL = "/notifications"; - + private String portalName; private String senderEmail; private String portalURL; @@ -60,7 +60,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen userManager = new LiferayUserManager(); _log.warn("Asked for Simple Notification (without redirect to creator)"); } - + /** *

* Use this constructor if your artifact is not deployed on the portal and do not need notifications to point back to your applications @@ -127,6 +127,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen _log.info("senderEmail: " + senderEmail); _log.info("portalName: " + senderEmail); } + /** * actually save the notification to the store * @param notification2Save the notification instance to save @@ -153,7 +154,42 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen _log.error("Error While trying to save Notification"); } if (channels.contains(NotificationChannelType.EMAIL)) { - EmailPlugin.getInstance(userManager, currScope).sendNotification(portalURL, siteLandingPagePath, notification2Save, currGroupName, portalName, senderEmail, hashtags); + EmailPlugin.getInstance(userManager, currScope).sendNotification(portalURL, siteLandingPagePath, notification2Save, currGroupName, portalName, senderEmail, null, 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; + } + + /** + * actually save the notification to the store + * @param notification2Save the notification instance to save + * @return true if the notification was sent ok + */ + private boolean saveNotification(Notification notification2Save, Set mentionedVREGroups, 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"); + return true; //I'm not sending notifications to the person who triggered it, pretend I sent it though + } + List channels = null; + try { + channels = getStoreInstance().getUserNotificationChannels(notification2Save.getUserid(), notification2Save.getType()); + } catch (Exception e) { + e.printStackTrace(); + } + boolean result = false; + if (channels.contains(NotificationChannelType.PORTAL)) { + result = getStoreInstance().saveNotification(notification2Save); + if (result) + _log.trace("Notification Saved Successfully! "); + else + _log.error("Error While trying to save Notification"); + } + if (channels.contains(NotificationChannelType.EMAIL)) { + EmailPlugin.getInstance(userManager, currScope).sendNotification(portalURL, siteLandingPagePath, notification2Save, currGroupName, portalName, senderEmail, mentionedVREGroups, hashtags); } if (channels.isEmpty()) { _log.info("Notification was not needed as "+ notification2Save.getUserid() +" decided not to be notified for " + notification2Save.getType()); @@ -504,8 +540,8 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen } otherRecipientNames += "

If you reply, your message will be also delivered to them.

"; } - - + + Notification not = new Notification( UUID.randomUUID().toString(), NotificationType.MESSAGE, @@ -516,11 +552,11 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen "sent you a message: " + "
" + messageText +"
" - + otherRecipientNames, - false, - currUser.getUsername(), - currUser.getFullname(), - currUser.getUserAvatarId()); + + otherRecipientNames, + false, + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not, optionalParams); } @@ -533,7 +569,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen notificationText.append("posted on ").append(currGroupName).append(":") // has done something .append("

").append(feedText).append(" ") .append("

"); - + Notification not = new Notification( UUID.randomUUID().toString(), NotificationType.POST_ALERT, @@ -548,6 +584,31 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen currUser.getUserAvatarId()); return saveNotification(not, hashtags); } + + @Override + public boolean notifyPost(String userIdToNotify, String feedid, + String feedText, Set mentionedVREGroups, + Set hashtags) { + StringBuilder notificationText = new StringBuilder(); + notificationText.append("posted on ").append(currGroupName).append(":") // has done something + .append("

").append(feedText).append(" ") + .append("

"); + + Notification not = new Notification( + UUID.randomUUID().toString(), + NotificationType.POST_ALERT, + userIdToNotify, //user no notify + feedid, //the post + new Date(), + getApplicationUrl()+"?oid="+feedid, + notificationText.toString(), + false, + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); + return saveNotification(not, mentionedVREGroups, hashtags.toArray(new String[hashtags.size()])); + } + /** * {@inheritDoc} */ @@ -568,7 +629,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen currUser.getUsername(), currUser.getFullname(), currUser.getUserAvatarId(), - commentKey); + commentKey); return saveNotification(not); } /** @@ -642,11 +703,11 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?oid="+feedid, "mentioned you: " + "
\"" + feedText +"\"
", - false, - currUser.getUsername(), - currUser.getFullname(), - currUser.getUserAvatarId(), - commentKey); + false, + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId(), + commentKey); return saveNotification(not); } /** @@ -654,8 +715,8 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen */ @Override public boolean notifyLikedFeed(String userIdToNotify, String feedid, String feedText) { - - Notification not = new Notification( + + Notification not = new Notification( UUID.randomUUID().toString(), NotificationType.LIKE, userIdToNotify, //user no notify @@ -673,11 +734,81 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen * {@inheritDoc} */ @Override - public boolean notifyJobStatus(String userIdToNotify, ApplicationProfile executingJobApId, RunningJob job) { - //TODO: missing implementation - return false; + public boolean notifyJobStatus(String userIdToNotify, RunningJob job) { + + //get job status + NotificationType statusToUse = null; + + // notification final part + String notificationFinalPart = null; + + switch(job.getStatus()){ + case CANCELLED: + notificationFinalPart = " has been cancelled."; + statusToUse = NotificationType.JOB_COMPLETED_NOK; + break; + case CANCELLING: + notificationFinalPart = " is going to be cancelled."; + statusToUse = NotificationType.JOB_COMPLETED_NOK; + break; + case DELETED: + notificationFinalPart = " has been deleted."; + statusToUse = NotificationType.JOB_COMPLETED_NOK; + break; + case DELETING: + notificationFinalPart = " is going to be deleted."; + statusToUse = NotificationType.JOB_COMPLETED_NOK; + break; + case EXECUTING: + notificationFinalPart = " is executing."; + statusToUse = NotificationType.JOB_COMPLETED_OK; + break; + case FAILED: + notificationFinalPart = " is failed."; + statusToUse = NotificationType.JOB_COMPLETED_NOK; + break; + case NEW: + notificationFinalPart = " has been instanciated."; + statusToUse = NotificationType.JOB_COMPLETED_OK; + break; + case SUBMITTED: + notificationFinalPart = " has been submitted."; + statusToUse = NotificationType.JOB_COMPLETED_OK; + break; + case SUCCEEDED: + notificationFinalPart = " terminated correctly."; + statusToUse = NotificationType.JOB_COMPLETED_OK; + break; + case TIMED_OUT: + notificationFinalPart = " went in time out."; + statusToUse = NotificationType.JOB_COMPLETED_NOK; + break; + case WAITING: + notificationFinalPart = " is waiting."; + statusToUse = NotificationType.JOB_COMPLETED_NOK; + break; + default: + _log.error("job status is missing, returning without sending notification"); + return false; + } + + Notification not = new Notification( + UUID.randomUUID().toString(), + statusToUse, + userIdToNotify, //user to notify + job.getServiceName(), + new Date(), + null, + "'s job with id " + job.getJobId() + ", named " + job.getJobName() +"" + notificationFinalPart + + (job.getMessage() != null && !job.getMessage().isEmpty() ? + " Additional information: " + job.getMessage() : ""), + false, + currUser.getUsername(), + job.getServiceName(), + currUser.getUserAvatarId()); + return saveNotification(not); } - + /** * {@inheritDoc} */ diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java index 3d8f7c6..f09f7ec 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java @@ -2,11 +2,11 @@ package org.gcube.applicationsupportlayer.social; import java.util.Date; import java.util.List; +import java.util.Set; import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder; -import org.gcube.portal.databook.shared.ApplicationProfile; import org.gcube.portal.databook.shared.NotificationType; import org.gcube.portal.databook.shared.RunningJob; /** @@ -167,6 +167,7 @@ public interface NotificationsManager { * @return true if the notification is correctly delivered, false otherwise */ boolean notifyDeletedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate); + /** * use to notify a user that someone created this post * @@ -175,7 +176,21 @@ public interface NotificationsManager { * @param feedText the liked feed text or a portion of it * @return true if the notification is correctly delivered, false otherwise */ + @Deprecated boolean notifyPost(String userIdToNotify, String feedid, String feedText, String ... hashtags); + + /** + * use to notify a user that someone created this post + * + * @param userIdToNotify the user you want to notify + * @param feedid the liked feedid + * @param feedText the liked feed text or a portion of it + * @param mentionedVREGroups the names of the mentioned vre's groups, if any + * @param hashtags the set of hashtags in the post, if any + * @return true if the notification is correctly delivered, false otherwise + */ + boolean notifyPost(String userIdToNotify, String feedid, String feedText, Set mentionedVREGroups, Set hashtags); + /** * use to notify a user that someone commented on his post * @@ -240,10 +255,9 @@ public interface NotificationsManager { * use to notify a user he got one of his job finished * * @param userIdToNotify the user you want to notify - * @param executingApp the {@link ApplicationProfile} of the application from which the job was executed/lauched * @return true if the notification is correctly delivered, false otherwise */ - boolean notifyJobStatus(String userIdToNotify, ApplicationProfile executingJobApId, RunningJob job); + boolean notifyJobStatus(String userIdToNotify, RunningJob job); boolean notifyTDMTabularResourceSharing(String userIdToNotify, String tabularResourceName, String encodedTabularResourceParams) throws Exception; /** 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 a93d9c4..b7ec9d3 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java @@ -1,6 +1,7 @@ package org.gcube.applicationsupportlayer.social.mailing; import java.util.ArrayList; +import java.util.Set; import org.gcube.portal.databook.shared.Notification; import org.gcube.vomanagement.usermanagement.UserManager; @@ -44,8 +45,8 @@ public class EmailPlugin { * @param portalName * @param senderEmail */ - public void sendNotification(String portalURL, String siteLandingPagePath, Notification notification2Save, String vreName, String portalName, String senderEmail, String ... hashtags) { - EmailNotificationProducer thread = new EmailNotificationProducer(new NotificationMail(userManager, portalURL, siteLandingPagePath, notification2Save, vreName, portalName, senderEmail, hashtags)); + public void sendNotification(String portalURL, String siteLandingPagePath, Notification notification2Save, String vreName, String portalName, String senderEmail, Set mentionedGroups, String ... hashtags) { + EmailNotificationProducer thread = new EmailNotificationProducer(new NotificationMail(userManager, portalURL, siteLandingPagePath, notification2Save, vreName, portalName, senderEmail, mentionedGroups, hashtags)); thread.start(); _log.trace("Thread notification Mail started OK"); } 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 d92379f..fe4bd11 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/NotificationMail.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/NotificationMail.java @@ -3,6 +3,7 @@ package org.gcube.applicationsupportlayer.social.mailing; import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.Set; import javax.mail.Message; import javax.mail.Multipart; @@ -38,10 +39,10 @@ public class NotificationMail { private String portalURL; private String siteLandingPagePath; private String[] hashtags; - + private Set mentionedVReGroups; private static DatabookStore store = new DBCassandraAstyanaxImpl(); - public NotificationMail(UserManager userManager, String portalURL, String siteLandingPagePath, Notification notification2Send, String vreName, String portalName, String senderEmail, String ... hashtags) { + public NotificationMail(UserManager userManager, String portalURL, String siteLandingPagePath, Notification notification2Send, String vreName, String portalName, String senderEmail, Set mentionedVReGroups, String ... hashtags) { super(); this.userManager = userManager; this.portalURL = portalURL; @@ -51,6 +52,7 @@ public class NotificationMail { this.portalName = portalName; this.senderEmail = senderEmail; this.hashtags = hashtags; + this.mentionedVReGroups = mentionedVReGroups; } protected Message getMessageNotification(Session session) throws Exception { @@ -117,7 +119,7 @@ public class NotificationMail { + vreNameToUse + "[vreNameFromFeed is " + vreNameFromFeed + ", vreName is " + vreName + "]"); // set subject - msg2Return.setSubject(SocialMailingUtil.getSubjectByNotificationType(notification2Send, vreNameToUse, user.getFirstName(), hashtags)); + msg2Return.setSubject(SocialMailingUtil.getSubjectByNotificationType(notification2Send, vreNameToUse, user.getFirstName(), mentionedVReGroups, 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"); @@ -136,9 +138,6 @@ public class NotificationMail { return msg2Return; } - - - protected Notification getNotification2Send() { return notification2Send; } @@ -167,4 +166,8 @@ public class NotificationMail { return siteLandingPagePath; } + public Set getMentionedVReGroups() { + return mentionedVReGroups; + } + } 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 2073b7a..d2c707d 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java @@ -2,7 +2,10 @@ package org.gcube.applicationsupportlayer.social.mailing; import java.text.Format; import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager; import org.gcube.portal.databook.shared.Comment; @@ -61,7 +64,7 @@ public class SocialMailingUtil { } String sender = notification2Save.getSenderFullName(); - + String portalHost = portalURL.replaceAll("https://", ""); portalHost = portalHost.replaceAll("http://", ""); @@ -74,8 +77,6 @@ public class SocialMailingUtil { notification2Save.getType() == NotificationType.MENTION || notification2Save.getType() == NotificationType.OWN_COMMENT) { body.append("
").append(WRITE_ABOVE_TO_REPLY).append("

"); - - } String attachmentsNotice = ""; @@ -145,7 +146,7 @@ public class SocialMailingUtil { } } String sender = notification2Save.getSenderFullName(); - + String portalHost = portalURL.replaceAll("https://", ""); portalHost = portalHost.replaceAll("http://", ""); @@ -193,7 +194,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, Set mentionedVReGroups, String ...optionalParams) { switch (notification2Save.getType()) { case LIKE: return notification2Save.getSenderFullName()+" liked your post in " + (vreName == null? "" : vreName); @@ -229,17 +230,23 @@ public class SocialMailingUtil { return notification2Save.getSenderFullName() + " mentioned you in " + (vreName == null? "" : vreName); case POST_ALERT: String toReturn = notification2Save.getSenderFullName() + " posted on " + vreName; + if(mentionedVReGroups != null && !mentionedVReGroups.isEmpty()){ + for (String mentionedGroup : mentionedVReGroups) { + toReturn += " [" + mentionedGroup + "]"; + } + } if (optionalParams != null) { //in this case optionalParams are the hashtags - for (int i = 0; i < optionalParams.length; i++) - toReturn += " " + optionalParams[i]; + Set hashtags = new HashSet(Arrays.asList(optionalParams)); + for (String hashtag : hashtags) + toReturn += " " + hashtag; } return toReturn; case REQUEST_CONNECTION: return "Connection request"; case JOB_COMPLETED_NOK: - return "Job Completed"; + return notification2Save.getSubjectid() + "'s job status notification"; // i.e. Name of the job + ... case JOB_COMPLETED_OK: - return "Job Completed"; + return notification2Save.getSubjectid() + "'s job status notification"; // i.e. Name of the job + ... case CALENDAR_ADDED_EVENT: return vreName +": New event in a shared calendar"; case CALENDAR_UPDATED_EVENT: @@ -309,10 +316,12 @@ public class SocialMailingUtil { actionLink.append("\">").append(" Go to Contacts Center").append(""); break; case JOB_COMPLETED_NOK: - actionLink.append("\">").append(" Go to Application").append(""); + //actionLink.append("\">").append(" Go to Application").append(""); + actionLink.append("\">").append("").append(""); break; case JOB_COMPLETED_OK: - actionLink.append("\">").append(" Go to Application").append(""); + //actionLink.append("\">").append(" Go to Application").append(""); + actionLink.append("\">").append("").append(""); break; case CALENDAR_ADDED_EVENT: actionLink.append("\">").append(" Go to Calendar").append(""); @@ -396,69 +405,69 @@ public class SocialMailingUtil { try{ - if(notification2Save.getType().equals(NotificationType.POST_ALERT) || feed == null) - return ""; + if(notification2Save.getType().equals(NotificationType.COMMENT) || notification2Save.getType().equals(NotificationType.LIKE)){ - String htmlPost = "
" + "
----

Original post:

"; - // data formatter - Format formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm a"); + String htmlPost = "
" + "
----

Original post:

"; + // data formatter + Format formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm a"); - // escape html - String feedTextNoHtml = convertHTML2Text(feed.getDescription()); + // escape html + String feedTextNoHtml = convertHTML2Text(feed.getDescription()); - // build up html post + comments - if(notification2Save.getType() == NotificationType.POST_ALERT || (comments.size() == 0 && notification2Save.getType() == NotificationType.MENTION)) - htmlPost += "
" - + feed.getFullName() - + ": " - + (feedTextNoHtml.length() > 30 ? feedTextNoHtml.substring(0, 30) + " ..." : feedTextNoHtml) - + "

" + formatter.format(feed.getTime()) + "

" - +"
"; - else - htmlPost += "
" - + feed.getFullName() - + ": " - + (feedTextNoHtml.length() > 30 ? feedTextNoHtml.substring(0, 30) + " ..." : feedTextNoHtml) - + "

" + formatter.format(feed.getTime()) + "

" - +"
"; + // build up html post + comments + if(notification2Save.getType() == NotificationType.POST_ALERT || (comments.size() == 0 && notification2Save.getType() == NotificationType.MENTION)) + htmlPost += "
" + + feed.getFullName() + + ": " + + (feedTextNoHtml.length() > 30 ? feedTextNoHtml.substring(0, 30) + " ..." : feedTextNoHtml) + + "

" + formatter.format(feed.getTime()) + "

" + +"
"; + else + htmlPost += "
" + + feed.getFullName() + + ": " + + (feedTextNoHtml.length() > 30 ? feedTextNoHtml.substring(0, 30) + " ..." : feedTextNoHtml) + + "

" + formatter.format(feed.getTime()) + "

" + +"
"; - if(comments != null) - for (int i = 0; i < comments.size(); i++) { + if(comments != null) + for (int i = 0; i < comments.size(); i++) { - String commentTextNoHtml = comments.get(i).getText().replaceAll("&", "&"); + String commentTextNoHtml = comments.get(i).getText().replaceAll("&", "&"); - if((commentKey != null && comments.get(i).getKey().equals(commentKey)) && !(notification2Save.getType() == NotificationType.POST_ALERT)){ - htmlPost += "
" - + comments.get(i).getFullName() - + ": " - + commentTextNoHtml - + "

" + formatter.format(comments.get(i).getTime()) + "

" - +"
"; + if((commentKey != null && comments.get(i).getKey().equals(commentKey)) && !(notification2Save.getType() == NotificationType.POST_ALERT)){ + htmlPost += "
" + + comments.get(i).getFullName() + + ": " + + commentTextNoHtml + + "

" + formatter.format(comments.get(i).getTime()) + "

" + +"
"; - break; - } - else - htmlPost += "
" - + comments.get(i).getFullName() - + ": " - + commentTextNoHtml - + "

" + formatter.format(comments.get(i).getTime()) + "

" - +"
"; - } + break; + } + else + htmlPost += "
" + + comments.get(i).getFullName() + + ": " + + commentTextNoHtml + + "

" + formatter.format(comments.get(i).getTime()) + "

" + +"
"; + } - return htmlPost; + return htmlPost; + } }catch(Exception e){ _log.error("Unable to reconstruct html discussion to put into the email body.", e); } @@ -477,45 +486,45 @@ public class SocialMailingUtil { try{ - if(notification2Save.getType().equals(NotificationType.POST_ALERT) || feed == null) - return ""; + if(notification2Save.getType().equals(NotificationType.COMMENT) || notification2Save.getType().equals(NotificationType.LIKE)){ - // build discussion - String discussion = "\n\n----\n\nOriginal post:"; + // build discussion + String discussion = "\n\n----\n\nOriginal post:"; - // data formatter - Format formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm a"); + // data formatter + Format formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm a"); - // escape html - String feedTextNoHtml = convertHTML2Text(feed.getDescription()); - - // build up post + comments - discussion += - "\n" - + "[" + formatter.format(feed.getTime()) + "] " - + feed.getFullName() - + ": " - + (feedTextNoHtml.length() > 200 ? feedTextNoHtml.substring(0, 200) + " ..." : feedTextNoHtml) - + "\n"; - - - for (int i = 0; i < comments.size(); i++) { - - String commentTextNoHtml = convertHTML2Text(comments.get(i).getText()); + // escape html + String feedTextNoHtml = convertHTML2Text(feed.getDescription()); + // build up post + comments discussion += - "\t" - + "[" + formatter.format(comments.get(i).getTime()) + "] " - + comments.get(i).getFullName() + "\n" + + "[" + formatter.format(feed.getTime()) + "] " + + feed.getFullName() + ": " - + commentTextNoHtml + + (feedTextNoHtml.length() > 200 ? feedTextNoHtml.substring(0, 200) + " ..." : feedTextNoHtml) + "\n"; - if(commentKey != null && comments.get(i).getKey().equals(commentKey)) - break; - } - return discussion; + for (int i = 0; i < comments.size(); i++) { + + String commentTextNoHtml = convertHTML2Text(comments.get(i).getText()); + + discussion += + "\t" + + "[" + formatter.format(comments.get(i).getTime()) + "] " + + comments.get(i).getFullName() + + ": " + + commentTextNoHtml + + "\n"; + + if(commentKey != null && comments.get(i).getKey().equals(commentKey)) + break; + } + + return discussion; + } } catch(Exception e){ _log.error("Unable to reconstruct plain text discussion to put into the email body.", e);