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
This commit is contained in:
parent
1abe50026c
commit
54db46f5f4
|
@ -2,6 +2,8 @@
|
||||||
<Changeset component="org.gcube.applicationsupportlayer.aslsocial.1-2-0"
|
<Changeset component="org.gcube.applicationsupportlayer.aslsocial.1-2-0"
|
||||||
date="2017-01-16">
|
date="2017-01-16">
|
||||||
<Change>partially removed portal context dependency (where possible)</Change>
|
<Change>partially removed portal context dependency (where possible)</Change>
|
||||||
|
<Change>added support to job notifications</Change>
|
||||||
|
<Change>added support for ticket #6342</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
<Changeset component="org.gcube.applicationsupportlayer.aslsocial.1-1-0"
|
<Changeset component="org.gcube.applicationsupportlayer.aslsocial.1-1-0"
|
||||||
date="2016-09-29">
|
date="2016-09-29">
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.applicationsupportlayer</groupId>
|
<groupId>org.gcube.applicationsupportlayer</groupId>
|
||||||
<artifactId>aslsocial</artifactId>
|
<artifactId>aslsocial</artifactId>
|
||||||
<version>1.3.0-SNAPSHOT</version>
|
<version>1.2.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>Social Portal ASL Extension</name>
|
<name>Social Portal ASL Extension</name>
|
||||||
<description>
|
<description>
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.applicationsupportlayer.social;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.applicationsupportlayer.social.mailing.EmailPlugin;
|
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.exceptions.InternalErrorException;
|
||||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
|
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.Notification;
|
||||||
import org.gcube.portal.databook.shared.NotificationChannelType;
|
import org.gcube.portal.databook.shared.NotificationChannelType;
|
||||||
import org.gcube.portal.databook.shared.NotificationType;
|
import org.gcube.portal.databook.shared.NotificationType;
|
||||||
|
@ -127,6 +127,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
||||||
_log.info("senderEmail: " + senderEmail);
|
_log.info("senderEmail: " + senderEmail);
|
||||||
_log.info("portalName: " + senderEmail);
|
_log.info("portalName: " + senderEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* actually save the notification to the store
|
* actually save the notification to the store
|
||||||
* @param notification2Save the notification instance to save
|
* @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");
|
_log.error("Error While trying to save Notification");
|
||||||
}
|
}
|
||||||
if (channels.contains(NotificationChannelType.EMAIL)) {
|
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<String> 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<NotificationChannelType> 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()) {
|
if (channels.isEmpty()) {
|
||||||
_log.info("Notification was not needed as "+ notification2Save.getUserid() +" decided not to be notified for " + notification2Save.getType());
|
_log.info("Notification was not needed as "+ notification2Save.getUserid() +" decided not to be notified for " + notification2Save.getType());
|
||||||
|
@ -516,11 +552,11 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
||||||
"sent you a message: "
|
"sent you a message: "
|
||||||
+ "<br/><div style=\"margin-top: 10px; margin-bottom: 10px; margin-left: 50px; padding-left: 15px; border-left: 3px solid #ccc; font-style: italic;\">"
|
+ "<br/><div style=\"margin-top: 10px; margin-bottom: 10px; margin-left: 50px; padding-left: 15px; border-left: 3px solid #ccc; font-style: italic;\">"
|
||||||
+ messageText +"</div>"
|
+ messageText +"</div>"
|
||||||
+ otherRecipientNames,
|
+ otherRecipientNames,
|
||||||
false,
|
false,
|
||||||
currUser.getUsername(),
|
currUser.getUsername(),
|
||||||
currUser.getFullname(),
|
currUser.getFullname(),
|
||||||
currUser.getUserAvatarId());
|
currUser.getUserAvatarId());
|
||||||
|
|
||||||
return saveNotification(not, optionalParams);
|
return saveNotification(not, optionalParams);
|
||||||
}
|
}
|
||||||
|
@ -548,6 +584,31 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
||||||
currUser.getUserAvatarId());
|
currUser.getUserAvatarId());
|
||||||
return saveNotification(not, hashtags);
|
return saveNotification(not, hashtags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean notifyPost(String userIdToNotify, String feedid,
|
||||||
|
String feedText, Set<String> mentionedVREGroups,
|
||||||
|
Set<String> hashtags) {
|
||||||
|
StringBuilder notificationText = new StringBuilder();
|
||||||
|
notificationText.append("posted on <b> ").append(currGroupName).append(":</b>") // has done something
|
||||||
|
.append("<br /><br /> ").append(feedText).append(" ")
|
||||||
|
.append("<br /><br />");
|
||||||
|
|
||||||
|
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}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -568,7 +629,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
||||||
currUser.getUsername(),
|
currUser.getUsername(),
|
||||||
currUser.getFullname(),
|
currUser.getFullname(),
|
||||||
currUser.getUserAvatarId(),
|
currUser.getUserAvatarId(),
|
||||||
commentKey);
|
commentKey);
|
||||||
return saveNotification(not);
|
return saveNotification(not);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -642,11 +703,11 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
||||||
getApplicationUrl()+"?oid="+feedid,
|
getApplicationUrl()+"?oid="+feedid,
|
||||||
"mentioned you: " + "<div style=\"margin-top: 10px; margin-bottom: 10px; margin-left: 50px; padding-left: 15px; border-left: 3px solid #ccc; font-style: italic;\">\""
|
"mentioned you: " + "<div style=\"margin-top: 10px; margin-bottom: 10px; margin-left: 50px; padding-left: 15px; border-left: 3px solid #ccc; font-style: italic;\">\""
|
||||||
+ feedText +"\"</div>",
|
+ feedText +"\"</div>",
|
||||||
false,
|
false,
|
||||||
currUser.getUsername(),
|
currUser.getUsername(),
|
||||||
currUser.getFullname(),
|
currUser.getFullname(),
|
||||||
currUser.getUserAvatarId(),
|
currUser.getUserAvatarId(),
|
||||||
commentKey);
|
commentKey);
|
||||||
return saveNotification(not);
|
return saveNotification(not);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -655,7 +716,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
||||||
@Override
|
@Override
|
||||||
public boolean notifyLikedFeed(String userIdToNotify, String feedid, String feedText) {
|
public boolean notifyLikedFeed(String userIdToNotify, String feedid, String feedText) {
|
||||||
|
|
||||||
Notification not = new Notification(
|
Notification not = new Notification(
|
||||||
UUID.randomUUID().toString(),
|
UUID.randomUUID().toString(),
|
||||||
NotificationType.LIKE,
|
NotificationType.LIKE,
|
||||||
userIdToNotify, //user no notify
|
userIdToNotify, //user no notify
|
||||||
|
@ -673,9 +734,79 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean notifyJobStatus(String userIdToNotify, ApplicationProfile executingJobApId, RunningJob job) {
|
public boolean notifyJobStatus(String userIdToNotify, RunningJob job) {
|
||||||
//TODO: missing implementation
|
|
||||||
return false;
|
//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 <b>" + job.getJobName() +"</b>" + notificationFinalPart +
|
||||||
|
(job.getMessage() != null && !job.getMessage().isEmpty() ?
|
||||||
|
" Additional information: " + job.getMessage() : ""),
|
||||||
|
false,
|
||||||
|
currUser.getUsername(),
|
||||||
|
job.getServiceName(),
|
||||||
|
currUser.getUserAvatarId());
|
||||||
|
return saveNotification(not);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,11 +2,11 @@ package org.gcube.applicationsupportlayer.social;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
||||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
|
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.NotificationType;
|
||||||
import org.gcube.portal.databook.shared.RunningJob;
|
import org.gcube.portal.databook.shared.RunningJob;
|
||||||
/**
|
/**
|
||||||
|
@ -167,6 +167,7 @@ public interface NotificationsManager {
|
||||||
* @return true if the notification is correctly delivered, false otherwise
|
* @return true if the notification is correctly delivered, false otherwise
|
||||||
*/
|
*/
|
||||||
boolean notifyDeletedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate);
|
boolean notifyDeletedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* use to notify a user that someone created this post
|
* 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
|
* @param feedText the liked feed text or a portion of it
|
||||||
* @return true if the notification is correctly delivered, false otherwise
|
* @return true if the notification is correctly delivered, false otherwise
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
boolean notifyPost(String userIdToNotify, String feedid, String feedText, String ... hashtags);
|
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<String> mentionedVREGroups, Set<String> hashtags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* use to notify a user that someone commented on his post
|
* 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
|
* use to notify a user he got one of his job finished
|
||||||
*
|
*
|
||||||
* @param userIdToNotify the user you want to notify
|
* @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
|
* @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;
|
boolean notifyTDMTabularResourceSharing(String userIdToNotify, String tabularResourceName, String encodedTabularResourceParams) throws Exception;
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.gcube.applicationsupportlayer.social.mailing;
|
package org.gcube.applicationsupportlayer.social.mailing;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.portal.databook.shared.Notification;
|
import org.gcube.portal.databook.shared.Notification;
|
||||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
|
@ -44,8 +45,8 @@ public class EmailPlugin {
|
||||||
* @param portalName
|
* @param portalName
|
||||||
* @param senderEmail
|
* @param senderEmail
|
||||||
*/
|
*/
|
||||||
public void sendNotification(String portalURL, String siteLandingPagePath, Notification notification2Save, String vreName, String portalName, String senderEmail, String ... hashtags) {
|
public void sendNotification(String portalURL, String siteLandingPagePath, Notification notification2Save, String vreName, String portalName, String senderEmail, Set<String> mentionedGroups, String ... hashtags) {
|
||||||
EmailNotificationProducer thread = new EmailNotificationProducer(new NotificationMail(userManager, portalURL, siteLandingPagePath, notification2Save, vreName, portalName, senderEmail, hashtags));
|
EmailNotificationProducer thread = new EmailNotificationProducer(new NotificationMail(userManager, portalURL, siteLandingPagePath, notification2Save, vreName, portalName, senderEmail, mentionedGroups, hashtags));
|
||||||
thread.start();
|
thread.start();
|
||||||
_log.trace("Thread notification Mail started OK");
|
_log.trace("Thread notification Mail started OK");
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.applicationsupportlayer.social.mailing;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.mail.Message;
|
import javax.mail.Message;
|
||||||
import javax.mail.Multipart;
|
import javax.mail.Multipart;
|
||||||
|
@ -38,10 +39,10 @@ public class NotificationMail {
|
||||||
private String portalURL;
|
private String portalURL;
|
||||||
private String siteLandingPagePath;
|
private String siteLandingPagePath;
|
||||||
private String[] hashtags;
|
private String[] hashtags;
|
||||||
|
private Set<String> mentionedVReGroups;
|
||||||
private static DatabookStore store = new DBCassandraAstyanaxImpl();
|
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<String> mentionedVReGroups, String ... hashtags) {
|
||||||
super();
|
super();
|
||||||
this.userManager = userManager;
|
this.userManager = userManager;
|
||||||
this.portalURL = portalURL;
|
this.portalURL = portalURL;
|
||||||
|
@ -51,6 +52,7 @@ public class NotificationMail {
|
||||||
this.portalName = portalName;
|
this.portalName = portalName;
|
||||||
this.senderEmail = senderEmail;
|
this.senderEmail = senderEmail;
|
||||||
this.hashtags = hashtags;
|
this.hashtags = hashtags;
|
||||||
|
this.mentionedVReGroups = mentionedVReGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Message getMessageNotification(Session session) throws Exception {
|
protected Message getMessageNotification(Session session) throws Exception {
|
||||||
|
@ -117,7 +119,7 @@ public class NotificationMail {
|
||||||
+ vreNameToUse + "[vreNameFromFeed is " + vreNameFromFeed + ", vreName is " + vreName + "]");
|
+ vreNameToUse + "[vreNameFromFeed is " + vreNameFromFeed + ", vreName is " + vreName + "]");
|
||||||
|
|
||||||
// set subject
|
// 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();
|
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");
|
||||||
|
@ -136,9 +138,6 @@ public class NotificationMail {
|
||||||
return msg2Return;
|
return msg2Return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected Notification getNotification2Send() {
|
protected Notification getNotification2Send() {
|
||||||
return notification2Send;
|
return notification2Send;
|
||||||
}
|
}
|
||||||
|
@ -167,4 +166,8 @@ public class NotificationMail {
|
||||||
return siteLandingPagePath;
|
return siteLandingPagePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<String> getMentionedVReGroups() {
|
||||||
|
return mentionedVReGroups;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,10 @@ package org.gcube.applicationsupportlayer.social.mailing;
|
||||||
|
|
||||||
import java.text.Format;
|
import java.text.Format;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
||||||
import org.gcube.portal.databook.shared.Comment;
|
import org.gcube.portal.databook.shared.Comment;
|
||||||
|
@ -74,8 +77,6 @@ public class SocialMailingUtil {
|
||||||
notification2Save.getType() == NotificationType.MENTION ||
|
notification2Save.getType() == NotificationType.MENTION ||
|
||||||
notification2Save.getType() == NotificationType.OWN_COMMENT) {
|
notification2Save.getType() == NotificationType.OWN_COMMENT) {
|
||||||
body.append("<div>").append(WRITE_ABOVE_TO_REPLY).append("</div><br />");
|
body.append("<div>").append(WRITE_ABOVE_TO_REPLY).append("</div><br />");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String attachmentsNotice = "";
|
String attachmentsNotice = "";
|
||||||
|
@ -193,7 +194,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, Set<String> mentionedVReGroups, String ...optionalParams) {
|
||||||
switch (notification2Save.getType()) {
|
switch (notification2Save.getType()) {
|
||||||
case LIKE:
|
case LIKE:
|
||||||
return notification2Save.getSenderFullName()+" liked your post in " + (vreName == null? "" : vreName);
|
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);
|
return notification2Save.getSenderFullName() + " mentioned you in " + (vreName == null? "" : vreName);
|
||||||
case POST_ALERT:
|
case POST_ALERT:
|
||||||
String toReturn = notification2Save.getSenderFullName() + " posted on " + vreName;
|
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
|
if (optionalParams != null) { //in this case optionalParams are the hashtags
|
||||||
for (int i = 0; i < optionalParams.length; i++)
|
Set<String> hashtags = new HashSet<String>(Arrays.asList(optionalParams));
|
||||||
toReturn += " " + optionalParams[i];
|
for (String hashtag : hashtags)
|
||||||
|
toReturn += " " + hashtag;
|
||||||
}
|
}
|
||||||
return toReturn;
|
return toReturn;
|
||||||
case REQUEST_CONNECTION:
|
case REQUEST_CONNECTION:
|
||||||
return "Connection request";
|
return "Connection request";
|
||||||
case JOB_COMPLETED_NOK:
|
case JOB_COMPLETED_NOK:
|
||||||
return "Job Completed";
|
return notification2Save.getSubjectid() + "'s job status notification"; // i.e. Name of the job + ...
|
||||||
case JOB_COMPLETED_OK:
|
case JOB_COMPLETED_OK:
|
||||||
return "Job Completed";
|
return notification2Save.getSubjectid() + "'s job status notification"; // i.e. Name of the job + ...
|
||||||
case CALENDAR_ADDED_EVENT:
|
case CALENDAR_ADDED_EVENT:
|
||||||
return vreName +": New event in a shared calendar";
|
return vreName +": New event in a shared calendar";
|
||||||
case CALENDAR_UPDATED_EVENT:
|
case CALENDAR_UPDATED_EVENT:
|
||||||
|
@ -309,10 +316,12 @@ public class SocialMailingUtil {
|
||||||
actionLink.append("\">").append(" Go to Contacts Center").append("</a>");
|
actionLink.append("\">").append(" Go to Contacts Center").append("</a>");
|
||||||
break;
|
break;
|
||||||
case JOB_COMPLETED_NOK:
|
case JOB_COMPLETED_NOK:
|
||||||
actionLink.append("\">").append(" Go to Application").append("</a>");
|
//actionLink.append("\">").append(" Go to Application").append("</a>");
|
||||||
|
actionLink.append("\">").append("").append("</a>");
|
||||||
break;
|
break;
|
||||||
case JOB_COMPLETED_OK:
|
case JOB_COMPLETED_OK:
|
||||||
actionLink.append("\">").append(" Go to Application").append("</a>");
|
//actionLink.append("\">").append(" Go to Application").append("</a>");
|
||||||
|
actionLink.append("\">").append("").append("</a>");
|
||||||
break;
|
break;
|
||||||
case CALENDAR_ADDED_EVENT:
|
case CALENDAR_ADDED_EVENT:
|
||||||
actionLink.append("\">").append(" Go to Calendar").append("</a>");
|
actionLink.append("\">").append(" Go to Calendar").append("</a>");
|
||||||
|
@ -396,69 +405,69 @@ public class SocialMailingUtil {
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
if(notification2Save.getType().equals(NotificationType.POST_ALERT) || feed == null)
|
if(notification2Save.getType().equals(NotificationType.COMMENT) || notification2Save.getType().equals(NotificationType.LIKE)){
|
||||||
return "";
|
|
||||||
|
|
||||||
String htmlPost = "<br />" + "<br />----<p>Original post:</p>";
|
String htmlPost = "<br />" + "<br />----<p>Original post:</p>";
|
||||||
// data formatter
|
// data formatter
|
||||||
Format formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm a");
|
Format formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm a");
|
||||||
|
|
||||||
// escape html
|
// escape html
|
||||||
String feedTextNoHtml = convertHTML2Text(feed.getDescription());
|
String feedTextNoHtml = convertHTML2Text(feed.getDescription());
|
||||||
|
|
||||||
// build up html post + comments
|
// build up html post + comments
|
||||||
if(notification2Save.getType() == NotificationType.POST_ALERT || (comments.size() == 0 && notification2Save.getType() == NotificationType.MENTION))
|
if(notification2Save.getType() == NotificationType.POST_ALERT || (comments.size() == 0 && notification2Save.getType() == NotificationType.MENTION))
|
||||||
htmlPost += "<div style=\"margin-top: 10px; margin-bottom: 10px;padding-left: 15px; "
|
htmlPost += "<div style=\"margin-top: 10px; margin-bottom: 10px;padding-left: 15px; "
|
||||||
+ "font-style: italic; font-weight:bold\">"
|
+ "font-style: italic; font-weight:bold\">"
|
||||||
+ feed.getFullName()
|
+ feed.getFullName()
|
||||||
+ ": "
|
+ ": "
|
||||||
+ (feedTextNoHtml.length() > 30 ? feedTextNoHtml.substring(0, 30) + " ..." : feedTextNoHtml)
|
+ (feedTextNoHtml.length() > 30 ? feedTextNoHtml.substring(0, 30) + " ..." : feedTextNoHtml)
|
||||||
+ "<p style=\"font-family:Lucida Grande,"
|
+ "<p style=\"font-family:Lucida Grande,"
|
||||||
+ "Verdana,Bitstream Vera Sans,Arial,sans-serif; "
|
+ "Verdana,Bitstream Vera Sans,Arial,sans-serif; "
|
||||||
+ "white-space: nowrap; font-size: smaller; color: #999;\">" + formatter.format(feed.getTime()) + "</p>"
|
+ "white-space: nowrap; font-size: smaller; color: #999;\">" + formatter.format(feed.getTime()) + "</p>"
|
||||||
+"</div>";
|
+"</div>";
|
||||||
else
|
else
|
||||||
htmlPost += "<div style=\"margin-top: 10px; margin-bottom: 10px;padding-left: 15px; "
|
htmlPost += "<div style=\"margin-top: 10px; margin-bottom: 10px;padding-left: 15px; "
|
||||||
+ "font-style: italic\">"
|
+ "font-style: italic\">"
|
||||||
+ feed.getFullName()
|
+ feed.getFullName()
|
||||||
+ ": "
|
+ ": "
|
||||||
+ (feedTextNoHtml.length() > 30 ? feedTextNoHtml.substring(0, 30) + " ..." : feedTextNoHtml)
|
+ (feedTextNoHtml.length() > 30 ? feedTextNoHtml.substring(0, 30) + " ..." : feedTextNoHtml)
|
||||||
+ "<p style=\"font-family:Lucida Grande,"
|
+ "<p style=\"font-family:Lucida Grande,"
|
||||||
+ "Verdana,Bitstream Vera Sans,Arial,sans-serif; "
|
+ "Verdana,Bitstream Vera Sans,Arial,sans-serif; "
|
||||||
+ "white-space: nowrap; font-size: smaller; color: #999;\">" + formatter.format(feed.getTime()) + "</p>"
|
+ "white-space: nowrap; font-size: smaller; color: #999;\">" + formatter.format(feed.getTime()) + "</p>"
|
||||||
+"</div>";
|
+"</div>";
|
||||||
|
|
||||||
if(comments != null)
|
if(comments != null)
|
||||||
for (int i = 0; i < comments.size(); i++) {
|
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)){
|
if((commentKey != null && comments.get(i).getKey().equals(commentKey)) && !(notification2Save.getType() == NotificationType.POST_ALERT)){
|
||||||
htmlPost += "<div style=\"margin-top: 10px; margin-bottom: 10px; margin-left: 50px; padding-left: 15px; "
|
htmlPost += "<div style=\"margin-top: 10px; margin-bottom: 10px; margin-left: 50px; padding-left: 15px; "
|
||||||
+ "border-left: 3px solid #ccc; font-style: italic; font-weight:bold\">"
|
+ "border-left: 3px solid #ccc; font-style: italic; font-weight:bold\">"
|
||||||
+ comments.get(i).getFullName()
|
+ comments.get(i).getFullName()
|
||||||
+ ": "
|
+ ": "
|
||||||
+ commentTextNoHtml
|
+ commentTextNoHtml
|
||||||
+ "<p style=\"font-family:Lucida Grande,"
|
+ "<p style=\"font-family:Lucida Grande,"
|
||||||
+ "Verdana,Bitstream Vera Sans,Arial,sans-serif; "
|
+ "Verdana,Bitstream Vera Sans,Arial,sans-serif; "
|
||||||
+ "white-space: nowrap; font-size: smaller; color: #999;\">" + formatter.format(comments.get(i).getTime()) + "</p>"
|
+ "white-space: nowrap; font-size: smaller; color: #999;\">" + formatter.format(comments.get(i).getTime()) + "</p>"
|
||||||
+"</div>";
|
+"</div>";
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
htmlPost += "<div style=\"margin-top: 10px; margin-bottom: 10px; margin-left: 50px; padding-left: 15px; "
|
||||||
|
+ "border-left: 3px solid #ccc; font-style: italic;\">"
|
||||||
|
+ comments.get(i).getFullName()
|
||||||
|
+ ": "
|
||||||
|
+ commentTextNoHtml
|
||||||
|
+ "<p style=\"font-family:Lucida Grande,"
|
||||||
|
+ "Verdana,Bitstream Vera Sans,Arial,sans-serif; "
|
||||||
|
+ "white-space: nowrap; font-size: smaller; color: #999;\">" + formatter.format(comments.get(i).getTime()) + "</p>"
|
||||||
|
+"</div>";
|
||||||
}
|
}
|
||||||
else
|
|
||||||
htmlPost += "<div style=\"margin-top: 10px; margin-bottom: 10px; margin-left: 50px; padding-left: 15px; "
|
|
||||||
+ "border-left: 3px solid #ccc; font-style: italic;\">"
|
|
||||||
+ comments.get(i).getFullName()
|
|
||||||
+ ": "
|
|
||||||
+ commentTextNoHtml
|
|
||||||
+ "<p style=\"font-family:Lucida Grande,"
|
|
||||||
+ "Verdana,Bitstream Vera Sans,Arial,sans-serif; "
|
|
||||||
+ "white-space: nowrap; font-size: smaller; color: #999;\">" + formatter.format(comments.get(i).getTime()) + "</p>"
|
|
||||||
+"</div>";
|
|
||||||
}
|
|
||||||
|
|
||||||
return htmlPost;
|
return htmlPost;
|
||||||
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
_log.error("Unable to reconstruct html discussion to put into the email body.", e);
|
_log.error("Unable to reconstruct html discussion to put into the email body.", e);
|
||||||
}
|
}
|
||||||
|
@ -477,45 +486,45 @@ public class SocialMailingUtil {
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
if(notification2Save.getType().equals(NotificationType.POST_ALERT) || feed == null)
|
if(notification2Save.getType().equals(NotificationType.COMMENT) || notification2Save.getType().equals(NotificationType.LIKE)){
|
||||||
return "";
|
|
||||||
|
|
||||||
// build discussion
|
// build discussion
|
||||||
String discussion = "\n\n----\n\nOriginal post:";
|
String discussion = "\n\n----\n\nOriginal post:";
|
||||||
|
|
||||||
// data formatter
|
// data formatter
|
||||||
Format formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm a");
|
Format formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm a");
|
||||||
|
|
||||||
// escape html
|
// escape html
|
||||||
String feedTextNoHtml = convertHTML2Text(feed.getDescription());
|
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());
|
|
||||||
|
|
||||||
|
// build up post + comments
|
||||||
discussion +=
|
discussion +=
|
||||||
"\t"
|
"\n"
|
||||||
+ "[" + formatter.format(comments.get(i).getTime()) + "] "
|
+ "[" + formatter.format(feed.getTime()) + "] "
|
||||||
+ comments.get(i).getFullName()
|
+ feed.getFullName()
|
||||||
+ ": "
|
+ ": "
|
||||||
+ commentTextNoHtml
|
+ (feedTextNoHtml.length() > 200 ? feedTextNoHtml.substring(0, 200) + " ..." : feedTextNoHtml)
|
||||||
+ "\n";
|
+ "\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){
|
catch(Exception e){
|
||||||
_log.error("Unable to reconstruct plain text discussion to put into the email body.", e);
|
_log.error("Unable to reconstruct plain text discussion to put into the email body.", e);
|
||||||
|
|
Loading…
Reference in New Issue