added hashtags in subject email of post notifications, with redirection to search in the VRE
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerSocial@101406 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
028fb77fbc
commit
746d0df7ad
|
@ -72,7 +72,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
||||||
* @param notification2Save the notification instance to save
|
* @param notification2Save the notification instance to save
|
||||||
* @return true if the notification was sent ok
|
* @return true if the notification was sent ok
|
||||||
*/
|
*/
|
||||||
private boolean saveNotification(Notification notification2Save) {
|
private boolean saveNotification(Notification notification2Save, String ... hashtags) {
|
||||||
_log.trace("Trying to send notification to: " + notification2Save.getUserid() + " Type: " + notification2Save.getType());
|
_log.trace("Trying to send notification to: " + notification2Save.getUserid() + " Type: " + notification2Save.getType());
|
||||||
if (notification2Save.getSenderid().compareTo(notification2Save.getUserid()) == 0) {
|
if (notification2Save.getSenderid().compareTo(notification2Save.getUserid()) == 0) {
|
||||||
_log.trace("Sender and Receiver are the same " + notification2Save.getUserid() + " Notification Stopped");
|
_log.trace("Sender and Receiver are the same " + notification2Save.getUserid() + " Notification Stopped");
|
||||||
|
@ -93,15 +93,15 @@ 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().sendNotification(notification2Save, aslSession.getGroupName(), portalName, senderEmail);
|
EmailPlugin.getInstance().sendNotification(notification2Save, aslSession.getGroupName(), portalName, senderEmail, 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());
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the url of the application if exists in the profile
|
* return the url of the application if exists in the profile
|
||||||
* @return .
|
* @return .
|
||||||
|
@ -454,10 +454,10 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean notifyPost(String userIdToNotify, String feedid, String feedText) {
|
public boolean notifyPost(String userIdToNotify, String feedid, String feedText, String ... hashtags) {
|
||||||
|
|
||||||
StringBuilder notificationText = new StringBuilder();
|
StringBuilder notificationText = new StringBuilder();
|
||||||
notificationText.append("posted a news on <b>").append(aslSession.getGroupName()).append(":</b>") // has done something
|
notificationText.append("posted a news on <b> ").append(aslSession.getGroupName()).append(":</b>") // has done something
|
||||||
.append("<br /><br /> ").append(escapeHtml(feedText)).append(". ")
|
.append("<br /><br /> ").append(escapeHtml(feedText)).append(". ")
|
||||||
.append("<br /><br />Follow the discussion and comment it. ");
|
.append("<br /><br />Follow the discussion and comment it. ");
|
||||||
|
|
||||||
|
@ -473,7 +473,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
||||||
aslSession.getUsername(),
|
aslSession.getUsername(),
|
||||||
aslSession.getUserFullName(),
|
aslSession.getUserFullName(),
|
||||||
aslSession.getUserAvatarId());
|
aslSession.getUserAvatarId());
|
||||||
return saveNotification(not);
|
return saveNotification(not, hashtags);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
|
|
@ -171,7 +171,7 @@ 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
|
||||||
*/
|
*/
|
||||||
boolean notifyPost(String userIdToNotify, String feedid, String feedText);
|
boolean notifyPost(String userIdToNotify, String feedid, String feedText, String ... hashtags);
|
||||||
/**
|
/**
|
||||||
* use to notify a user that someone commented on his post
|
* use to notify a user that someone commented on his post
|
||||||
*
|
*
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class EmailNotificationsConsumer extends Thread {
|
||||||
//sync method to ensure the producer do not put new emails in the meantime
|
//sync method to ensure the producer do not put new emails in the meantime
|
||||||
synchronized(EmailPlugin.BUFFER_EMAILS){
|
synchronized(EmailPlugin.BUFFER_EMAILS){
|
||||||
for (NotificationMail mail : EmailPlugin.BUFFER_EMAILS) {
|
for (NotificationMail mail : EmailPlugin.BUFFER_EMAILS) {
|
||||||
Message m = EmailPlugin.getMessageNotification(session, mail.getNotification2Send(), mail.getVreName(), mail.getPortalName(), mail.getSenderEmail());
|
Message m = EmailPlugin.getMessageNotification(session, mail.getNotification2Send(), mail.getVreName(), mail.getPortalName(), mail.getSenderEmail(), mail.getHashtags());
|
||||||
if (m != null) {
|
if (m != null) {
|
||||||
m.saveChanges();
|
m.saveChanges();
|
||||||
Address[] addresses = m.getAllRecipients();
|
Address[] addresses = m.getAllRecipients();
|
||||||
|
|
|
@ -50,12 +50,22 @@ public class EmailPlugin {
|
||||||
|
|
||||||
protected static ArrayList<NotificationMail> BUFFER_EMAILS = new ArrayList<NotificationMail>();
|
protected static ArrayList<NotificationMail> BUFFER_EMAILS = new ArrayList<NotificationMail>();
|
||||||
|
|
||||||
private static String getHTMLEmail(Notification notification2Save, String userFirstName, String portalURL, String email) {
|
private static String getHTMLEmail(Notification notification2Save, String userFirstName, String portalURL, String email, String ... hashtags) {
|
||||||
|
|
||||||
String removedMarkup = notification2Save.getDescription().replaceAll("&", "&");
|
String removedMarkup = notification2Save.getDescription().replaceAll("&", "&");
|
||||||
removedMarkup = removedMarkup.replaceAll(">", ">");
|
removedMarkup = removedMarkup.replaceAll(">", ">");
|
||||||
removedMarkup = removedMarkup.replaceAll("<", "<");
|
removedMarkup = removedMarkup.replaceAll("<", "<");
|
||||||
|
|
||||||
|
if (hashtags != null && hashtags.length > 0) {
|
||||||
|
_log.debug("editing hyperlinks for mail client");
|
||||||
|
//notification2Save uri contains the absoulte path to the feed in the correct channel, e.g. /group/ustore_vre?oid=f1637958-34d0-48fc-b5ad-13b1116e389d
|
||||||
|
String pathToVRE = "/group/data-e-infrastructure-gateway?";
|
||||||
|
if (notification2Save.getUri().split("\\?").length > 0) {
|
||||||
|
pathToVRE = notification2Save.getUri().split("\\?")[0];
|
||||||
|
}
|
||||||
|
removedMarkup = removedMarkup.replace("href=\"?", "href=\""+portalURL + pathToVRE + "?"); //because there is no indication of the portal
|
||||||
|
}
|
||||||
|
|
||||||
String sender = notification2Save.getSenderFullName();
|
String sender = notification2Save.getSenderFullName();
|
||||||
if (notification2Save.getType() == NotificationType.DOCUMENT_WORKFLOW_STEP_REQUEST_TASK)
|
if (notification2Save.getType() == NotificationType.DOCUMENT_WORKFLOW_STEP_REQUEST_TASK)
|
||||||
sender = "";
|
sender = "";
|
||||||
|
@ -91,10 +101,17 @@ public class EmailPlugin {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getTextEmail(Notification notification2Save, String userFirstName, String portalURL, String email) {
|
private static String getTextEmail(Notification notification2Save, String userFirstName, String portalURL, String email, String[] hashtags) {
|
||||||
|
|
||||||
String removedMarkup = convertHTML2Text(notification2Save.getDescription());
|
String removedMarkup = convertHTML2Text(notification2Save.getDescription());
|
||||||
|
|
||||||
|
if (hashtags != null && hashtags.length > 0) {
|
||||||
|
for (int i = 0; i < hashtags.length; i++) {
|
||||||
|
_log.debug("replacing " + hashtags[i]);
|
||||||
|
removedMarkup = removedMarkup.replace(hashtags[i], " " + hashtags[i] + " "); //because removing html cause trimming we put spaces back
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_log.debug("*****removedMarkup=\n" + removedMarkup);
|
||||||
|
|
||||||
String sender = notification2Save.getSenderFullName();
|
String sender = notification2Save.getSenderFullName();
|
||||||
if (notification2Save.getType() == NotificationType.DOCUMENT_WORKFLOW_STEP_REQUEST_TASK)
|
if (notification2Save.getType() == NotificationType.DOCUMENT_WORKFLOW_STEP_REQUEST_TASK)
|
||||||
|
@ -182,17 +199,12 @@ public class EmailPlugin {
|
||||||
* @param portalName
|
* @param portalName
|
||||||
* @param senderEmail
|
* @param senderEmail
|
||||||
*/
|
*/
|
||||||
public void sendNotification(Notification notification2Save, String vreName, String portalName, String senderEmail) {
|
public void sendNotification(Notification notification2Save, String vreName, String portalName, String senderEmail, String ... hashtags) {
|
||||||
EmailNotificationProducer thread = new EmailNotificationProducer(new NotificationMail(notification2Save, vreName, portalName, senderEmail));
|
EmailNotificationProducer thread = new EmailNotificationProducer(new NotificationMail(notification2Save, vreName, portalName, senderEmail, hashtags));
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Message getMessageNotification(
|
protected static Message getMessageNotification(Session session, Notification notification2Save, String vreName, String portalName, String senderEmail, String ... hashtags) throws Exception {
|
||||||
Session session,
|
|
||||||
Notification notification2Save,
|
|
||||||
String vreName,
|
|
||||||
String portalName,
|
|
||||||
String senderEmail) throws Exception {
|
|
||||||
|
|
||||||
UserModel user = null;
|
UserModel user = null;
|
||||||
String portalUrl = null;
|
String portalUrl = null;
|
||||||
|
@ -214,13 +226,13 @@ public class EmailPlugin {
|
||||||
msg2Return.setFrom(new InternetAddress(senderEmail, portalName));
|
msg2Return.setFrom(new InternetAddress(senderEmail, portalName));
|
||||||
msg2Return.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
|
msg2Return.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
|
||||||
|
|
||||||
msg2Return.setSubject(getSubjectByNotificationType(notification2Save, portalUrl, vreName, user.getFirstName()));
|
msg2Return.setSubject(getSubjectByNotificationType(notification2Save, portalUrl, vreName, user.getFirstName(), hashtags));
|
||||||
|
|
||||||
final MimeBodyPart textPart = new MimeBodyPart();
|
final MimeBodyPart textPart = new MimeBodyPart();
|
||||||
textPart.setContent(getTextEmail(notification2Save, user.getFirstName(), portalUrl, email), "text/plain");
|
textPart.setContent(getTextEmail(notification2Save, user.getFirstName(), portalUrl, email, hashtags), "text/plain; charset=UTF-8");
|
||||||
|
|
||||||
final MimeBodyPart htmlPart = new MimeBodyPart();
|
final MimeBodyPart htmlPart = new MimeBodyPart();
|
||||||
htmlPart.setContent(getHTMLEmail(notification2Save, user.getFirstName(), portalUrl, email), "text/html; charset=UTF-8");
|
htmlPart.setContent(getHTMLEmail(notification2Save, user.getFirstName(), portalUrl, email, hashtags), "text/html; charset=UTF-8");
|
||||||
|
|
||||||
final Multipart mp = new MimeMultipart("alternative");
|
final Multipart mp = new MimeMultipart("alternative");
|
||||||
mp.addBodyPart(textPart);
|
mp.addBodyPart(textPart);
|
||||||
|
@ -240,7 +252,7 @@ public class EmailPlugin {
|
||||||
* @param vreName
|
* @param vreName
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static String getSubjectByNotificationType(Notification notification2Save, String portalURL, String vreName, String userFirstName) {
|
private static String getSubjectByNotificationType(Notification notification2Save, String portalURL, String vreName, String userFirstName, String ...hashtags) {
|
||||||
switch (notification2Save.getType()) {
|
switch (notification2Save.getType()) {
|
||||||
case LIKE:
|
case LIKE:
|
||||||
return notification2Save.getSenderFullName()+" favorited your post";
|
return notification2Save.getSenderFullName()+" favorited your post";
|
||||||
|
@ -273,7 +285,11 @@ public class EmailPlugin {
|
||||||
case MENTION:
|
case MENTION:
|
||||||
return notification2Save.getSenderFullName() + " mentioned you";
|
return notification2Save.getSenderFullName() + " mentioned you";
|
||||||
case POST_ALERT:
|
case POST_ALERT:
|
||||||
return notification2Save.getSenderFullName() + " shared a news on " + vreName;
|
String toReturn = notification2Save.getSenderFullName() + " shared a news on " + vreName;
|
||||||
|
if (hashtags != null)
|
||||||
|
for (int i = 0; i < hashtags.length; i++)
|
||||||
|
toReturn += " " + hashtags[i];
|
||||||
|
return toReturn;
|
||||||
case REQUEST_CONNECTION:
|
case REQUEST_CONNECTION:
|
||||||
return "Connection request";
|
return "Connection request";
|
||||||
case JOB_COMPLETED_NOK:
|
case JOB_COMPLETED_NOK:
|
||||||
|
|
|
@ -12,14 +12,15 @@ public class NotificationMail {
|
||||||
private String vreName;
|
private String vreName;
|
||||||
private String portalName;
|
private String portalName;
|
||||||
private String senderEmail;
|
private String senderEmail;
|
||||||
|
private String[] hashtags;
|
||||||
|
|
||||||
public NotificationMail(Notification notification2Send, String vreName,
|
public NotificationMail(Notification notification2Send, String vreName, String portalName, String senderEmail, String ... hashtags) {
|
||||||
String portalName, String senderEmail) {
|
|
||||||
super();
|
super();
|
||||||
this.notification2Send = notification2Send;
|
this.notification2Send = notification2Send;
|
||||||
this.vreName = vreName;
|
this.vreName = vreName;
|
||||||
this.portalName = portalName;
|
this.portalName = portalName;
|
||||||
this.senderEmail = senderEmail;
|
this.senderEmail = senderEmail;
|
||||||
|
this.hashtags = hashtags;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Notification getNotification2Send() {
|
protected Notification getNotification2Send() {
|
||||||
|
@ -37,4 +38,8 @@ public class NotificationMail {
|
||||||
protected String getSenderEmail() {
|
protected String getSenderEmail() {
|
||||||
return senderEmail;
|
return senderEmail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String[] getHashtags() {
|
||||||
|
return hashtags;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue