notifications text revised

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerSocial@68606 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2013-01-31 14:46:37 +00:00
parent 83311117df
commit 655745e344
2 changed files with 159 additions and 58 deletions

View File

@ -73,7 +73,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
_log.error("Error While trying to save Notification");
}
if (channels.contains(NotificationChannelType.EMAIL))
EmailPlugin.sendNotification(notification2Save);
EmailPlugin.sendNotification(notification2Save, aslSession.getGroupName());
if (channels.isEmpty()) {
_log.info("Notification was not needed as the user decided not to be notified");
@ -103,7 +103,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
sharedFolder.getId(), //the
new Date(),
"?oid="+sharedFolder.getId(),
"has shared a workspace folder ("+ sharedFolder.getName() +") with you",
"shared the workspace folder "+ sharedFolder.getName() +" with you",
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
@ -127,8 +127,8 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
userIdToNotify, //user no notify
sharedFolder.getId(), //the
new Date(),
"?oid="+sharedFolder.getId(),
"has added a new user ("+ user.getFullname() +") on your workspace shared folder ("+ sharedFolder.getName() +")",
"?oid="+sharedFolder.getId(),
"added "+ user.getFullname() +" to your workspace shared folder "+ sharedFolder.getName(),
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
@ -150,7 +150,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
sharedFolder.getId(), //the
new Date(),
"?oid="+sharedFolder.getId(),
"has removed a user ("+ user.getFullname() +") from your workspace shared folder ("+ sharedFolder.getName() +")",
"removed "+ user.getFullname() +" from your workspace shared folder "+ sharedFolder.getName(),
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
@ -171,7 +171,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
item.getId(), //the
new Date(),
"?oid="+item.getId()+"&parentoid="+item.getParent().getId(),
"has added a new item ("+ item.getName() +") on your workspace shared folder ("+ item.getParent().getName() +")",
"added "+ item.getName() +" to your workspace shared folder "+ item.getParent().getName(),
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
@ -192,7 +192,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
item.getId(), //the
new Date(),
"?oid="+item.getId()+"&parentoid="+item.getParent().getId(),
"has removed an item ("+ item.getName() +") from your workspace shared folder ("+ item.getParent().getName() +")",
"removed "+ item.getName() +" from your workspace shared folder "+ item.getParent().getName(),
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
@ -213,7 +213,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
"?oid="+item.getId()+"&parentoid="+item.getParent().getId(),
new Date(),
"?folder="+item.getParent().getId()+"&item="+item.getId(),
"has updated an item ("+ item.getName() +") on your workspace shared folder ("+ item.getParent().getName() +")",
" updated "+ item.getName() +" to your workspace shared folder "+ item.getParent().getName(),
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
@ -233,7 +233,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
"messageid_not_provided", //the
new Date(),
"",
"has sent you a message with subject: " + escapeHtml(subject),
"sent you a message with subject: " + escapeHtml(subject),
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
@ -307,7 +307,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
documentWorkflowId, //the workflowid
new Date(),
getApplicationUrl()+"?oid="+documentWorkflowId,
"has viewed a document workflow you created (" + escapeHtml(documentName) + ").",
"viewed document workflow " + escapeHtml(documentName),
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
@ -327,7 +327,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
documentWorkflowId, //the workflowid
new Date(),
getApplicationUrl()+"?oid="+documentWorkflowId,
"has edited a document workflow you created (" + escapeHtml(documentName) + ").",
"updated document workflow " + escapeHtml(documentName),
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
@ -339,9 +339,10 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
*/
@Override
public boolean notifyDocumentWorkflowTaskRequest(String userIdToNotify, String documentWorkflowId, String documentName, String assignedRoleName) {
String notificationText = "in " + aslSession.getGroupName() + " you are requested to perform a new task in the Document Workflow titled: "
+ escapeHtml(documentName) + ". Your role is: " + assignedRoleName;
String notificationText = "You are requested to perform a new task in the Document Workflow (" + escapeHtml(documentName) + "). " +
"Your role is: " + assignedRoleName +". On " + aslSession.getGroupName() + " Virtual Research Environment.";
Notification not = new Notification(
UUID.randomUUID().toString(),
NotificationType.DOCUMENT_WORKFLOW_STEP_REQUEST_TASK,
@ -370,8 +371,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
documentWorkflowId, //the workflowid
new Date(),
getApplicationUrl()+"?oid="+documentWorkflowId,
"has forwarded a document workflow you created (" + escapeHtml(documentName) + ") " +
"from step " + fromStepName + " towards step " + toStepName +". On " + aslSession.getGroupName() + " Virtual Research Environment. ",
"forwarded the Document Workflow titled: " + escapeHtml(documentName) +
" from status \"" + fromStepName + "\" to status \"" + toStepName +"\". In " + aslSession.getGroupName(),
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
@ -391,8 +393,8 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
documentWorkflowId, //the workflowid
new Date(),
getApplicationUrl()+"?oid="+documentWorkflowId,
"has performed the last needed forward on a document workflow you created (" + escapeHtml(documentName) + "). " +
"Consequently, this Document Workflow moved from step " + fromStepName + " to step " + toStepName +". On " + aslSession.getGroupName() + " Virtual Research Environment. ",
"has performed the last needed forward on a Document Workflow titled: " + escapeHtml(documentName) + " in . " + aslSession.getGroupName() + "." +
"Step \"" + fromStepName + "\" is now complete. The next step is \"" + toStepName +"\". On " + aslSession.getGroupName() + " Virtual Research Environment. ",
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
@ -405,8 +407,8 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
*/
@Override
public boolean notifyDocumentWorkflowFirstStepRequest(String userIdToNotify, String documentWorkflowId, String documentName, String assignedRole) {
String notificationText = "has involved you in a Document Workflow (" + escapeHtml(documentName) + ") " +
"and has assigned you the role: " + assignedRole +". On " + aslSession.getGroupName() + " Virtual Research Environment.";
String notificationText = "involved you in the Document Workflow titled: " + escapeHtml(documentName) + ". " +
"You are requested to perform a task. Your role is: " + assignedRole+".";
Notification not = new Notification(
UUID.randomUUID().toString(),
NotificationType.DOCUMENT_WORKFLOW_FIRST_STEP_REQUEST_INVOLVMENT,

View File

@ -27,29 +27,46 @@ import com.liferay.portal.util.PortalUtil;
public class EmailPlugin {
private static GCUBEClientLog _log = new GCUBEClientLog(EmailPlugin.class);
private static String getHTMLEmail(Notification notification2Save, String userFirstName, String portalUrl, String email) {
String removeMarkup = notification2Save.getDescription().replaceAll("&", "&");
removeMarkup = removeMarkup.replaceAll(">", ">");
removeMarkup = removeMarkup.replaceAll("&lt;", "<");
private static String getHTMLEmail(Notification notification2Save, String userFirstName, String portalURL, String email) {
String removedMarkup = notification2Save.getDescription().replaceAll("&amp;", "&");
removedMarkup = removedMarkup.replaceAll("&gt;", ">");
removedMarkup = removedMarkup.replaceAll("&lt;", "<");
String sender = notification2Save.getSenderFullName();
if (notification2Save.getType() == NotificationType.DOCUMENT_WORKFLOW_STEP_REQUEST_TASK)
sender = "";
return "<body>" +
"<br />Hi " + userFirstName + "," +
"<p>" + sender + " " + removeMarkup + "</p>" +
"<br /><p>See this at <a href=\"portalUrl\">" + portalUrl + "</a>" +
"<br /><p><div style=\"color:#999999; font-size:11px; font-family:'lucida grande',tahoma,verdana,arial,sans-serif; padding-top:30px;\">" +
"This message was sent to <a href=\"mailto:"+email+"\" style=\"color:#3b5998;text-decoration:none\" target=\"_blank\">"+email+"</a>. " +
"If you don't want to receive these emails in the future, please <a href=\""+portalUrl+"/group/data-e-infrastructure-gateway/notifications\" style=\"color:#3b5998;text-decoration:none\" target=\"_blank\">unsubscribe</a>." +
"</div></p>" +
"</body>";
StringBuilder body = new StringBuilder();
body.append("<body><br />Dear ").append(userFirstName).append(",") //dear <user>
.append("<p>").append(sender).append(" ").append(removedMarkup) // has done something
.append(getActionLink(notification2Save, portalURL)).append("</p>") //Goto
.append("<br />")
.append("<p><div style=\"color:#999999; font-size:11px; font-family:'lucida grande',tahoma,verdana,arial,sans-serif; padding-top:30px;\">")
.append("This message was sent to <a href=\"mailto:")
.append(email).append("\" style=\"color:#3B5998;text-decoration:none\" target=\"_blank\">").append(email).append("</a> by ")
.append(portalURL).append(".")
.append("If you don't want to receive these emails in the future, please <a href=\"")
.append(portalURL).append("/group/data-e-infrastructure-gateway/notifications\" style=\"color:#3b5998;text-decoration:none\" target=\"_blank\">unsubscribe</a>.")
.append("</div></p>")
.append("<p><div style=\"color:#999999; font-size:10px; font-family:'lucida grande',tahoma,verdana,arial,sans-serif; padding-top:15px;\">")
.append("WARNING / LEGAL TEXT: This message is intended only for the use of the individual or entity to which it is addressed and may contain")
.append("information which is privileged, confidential, proprietary, or exempt from disclosure under applicable law. If you are not the intended recipient or the person responsible for delivering the message to the intended recipient, you are strictly prohibited from disclosing, distributing, copying, or in any way using this message.")
.append("If you have received this communication in error, please notify the <sender> and destroy and delete any copies you may have received.")
.append("</div></p>")
.append("</body>");
return body.toString();
}
public static void sendNotification(Notification notification2Save) {
private static String getActionLink(Notification notification2Save, String portalURL) {
StringBuilder actionLink = new StringBuilder("<a style=\"color:#3B5998; text-decoration:none\" target=\"_blank\" href=\"");
return completeActonLinkByNotificationType(notification2Save, actionLink, portalURL);
}
public static void sendNotification(Notification notification2Save, String vreName) {
UserModel user = null;
String portalUrl = null;
@ -78,7 +95,7 @@ public class EmailPlugin {
Address address = new InternetAddress(email);
mimeMessage.addRecipient(Message.RecipientType.TO, address);
mimeMessage.setSubject(getSubjectByNotificationType(notification2Save));
mimeMessage.setSubject(getSubjectByNotificationType(notification2Save, portalUrl, vreName));
// mimeMessage.setText(body);
mimeMessage.setContent(getHTMLEmail(notification2Save, user.getFirstName(), portalUrl, email), "text/html");
mimeMessage.setSentDate(new Date());
@ -90,53 +107,135 @@ public class EmailPlugin {
}
}
private static String getSubjectByNotificationType(Notification notification2Save) {
private static String getSubjectByNotificationType(Notification notification2Save, String portalURL, String vreName) {
//<Portal URI senza protocollo>: Shared document workflow view notification
String portalHost = portalURL.replaceAll("https://", "");
portalHost = portalHost.replaceAll("http://", "");
switch (notification2Save.getType()) {
case LIKE:
return notification2Save.getSenderFullName() + " liked your post";
return portalHost + ": Like on your post notification";
case COMMENT:
return notification2Save.getSenderFullName() + " also replied on a post you replied";
return portalHost + ": Reply on a post notification";
case MESSAGE:
return notification2Save.getSenderFullName() + " sent you a message";
return portalHost + ": New message notification";
case WP_FOLDER_ADDEDUSER:
return notification2Save.getSenderFullName() + " added a new user to your shared folder";
return portalHost + ": New user in a shared folder notification";
case WP_FOLDER_REMOVEDUSER:
return notification2Save.getSenderFullName() + " removed a user to your shared folder";
return portalHost + ": Removed user in a shared folder notification";
case WP_FOLDER_SHARE:
return notification2Save.getSenderFullName() + " shared a folder with you";
return portalHost + ": Folder sharing notification";
case WP_ITEM_NEW:
return notification2Save.getSenderFullName() + " added a new item to your shared folder";
return portalHost + ": New item in a shared folder notification";
case WP_ITEM_DELETE:
return notification2Save.getSenderFullName() + " deleted an item from your shared folder";
return portalHost + ": Deleted item in a shared folder notification";
case WP_ITEM_UPDATED:
return notification2Save.getSenderFullName() + " updated an item in your shared folder";
return portalHost + ": Updated item in a shared folder notification";
case OWN_COMMENT:
return notification2Save.getSenderFullName() + " replied to your post";
return portalHost + ": Reply on your post notification";
case REQUEST_CONNECTION:
return notification2Save.getSenderFullName() + " wants to connect with you";
return portalHost + ": Connection request notification";
case JOB_COMPLETED_NOK:
return notification2Save.getSenderFullName() + " job KO";
return portalHost + ": Job Completed notification";
case JOB_COMPLETED_OK:
return notification2Save.getSenderFullName() + " job OK";
return portalHost + ": Job Completed notification";
case DOCUMENT_WORKFLOW_EDIT:
return notification2Save.getSenderFullName() + " edited your Document Workflow";
return portalHost + ": Shared document workflow view notification";
case DOCUMENT_WORKFLOW_VIEW:
return notification2Save.getSenderFullName() + " viewed your Document Workflow";
return portalHost + ": Shared document workflow view notification";
case DOCUMENT_WORKFLOW_STEP_REQUEST_TASK:
return "You are requested to perform a new task in the Document Workflow";
return portalHost + " - " + vreName +": Request for task notification";
case DOCUMENT_WORKFLOW_FIRST_STEP_REQUEST_INVOLVMENT:
return notification2Save.getSenderFullName() + " has involved you in a Document Workflow ";
return portalHost + " - " + vreName +": Request for task notification";
case DOCUMENT_WORKFLOW_USER_FORWARD_TO_OWNER:
return notification2Save.getSenderFullName() + " has forwarded a document workflow you created";
return portalHost + " - " + vreName +": Document workflow forward notification";
case DOCUMENT_WORKFLOW_STEP_FORWARD_PEER:
return notification2Save.getSenderFullName() + " has forwarded a document workflow you are involved into";
return portalHost + " - " + vreName +": Done task notification";
case DOCUMENT_WORKFLOW_FORWARD_STEP_COMPLETED_OWNER:
return notification2Save.getSenderFullName() + " has performed the last needed forward on a document workflow you created ";
return portalHost + " - " + vreName +": Document workflow step completion notification";
default:
return "You have a new Notification";
}
}
/**
* generate the clickable link
* @param notification2Save
* @param actionLink
* @param portalURL
* @return
*/
private static String completeActonLinkByNotificationType(Notification notification2Save, StringBuilder actionLink, String portalURL) {
actionLink.append(portalURL).append(notification2Save.getUri());
switch (notification2Save.getType()) {
case LIKE:
actionLink.append("\">").append("See the Post").append("</a>");
break;
case COMMENT:
actionLink.append("\">").append("See the Post").append("</a>");
break;
case MESSAGE:
actionLink.append("\">").append("Go to Message").append("</a>");
break;
case WP_FOLDER_ADDEDUSER:
actionLink.append("\">").append("Go to Folder").append("</a>");
break;
case WP_FOLDER_REMOVEDUSER:
actionLink.append("\">").append("Go to Folder").append("</a>");
break;
case WP_FOLDER_SHARE:
actionLink.append("\">").append("Go to Folder").append("</a>");
break;
case WP_ITEM_NEW:
actionLink.append("\">").append("Go to Folder").append("</a>");
break;
case WP_ITEM_DELETE:
actionLink.append("\">").append("Go to Folder").append("</a>");
break;
case WP_ITEM_UPDATED:
actionLink.append("\">").append("Go to Folder").append("</a>");
break;
case OWN_COMMENT:
actionLink.append("\">").append("See the Post").append("</a>");
break;
case REQUEST_CONNECTION:
actionLink.append("\">").append("Go to Contacts Center").append("</a>");
break;
case JOB_COMPLETED_NOK:
actionLink.append("\">").append("Go to Application").append("</a>");
break;
case JOB_COMPLETED_OK:
actionLink.append("\">").append("Go to Application").append("</a>");
break;
case DOCUMENT_WORKFLOW_EDIT:
actionLink.append("\">").append("Go to Document Workflow Manager").append("</a>");
break;
case DOCUMENT_WORKFLOW_VIEW:
actionLink.append("\">").append("Go to Document Workflow Manager").append("</a>");
break;
case DOCUMENT_WORKFLOW_STEP_REQUEST_TASK:
actionLink.append("\">").append("Go to Your Document Workflows").append("</a>");
break;
case DOCUMENT_WORKFLOW_FIRST_STEP_REQUEST_INVOLVMENT:
actionLink.append("\">").append("Go to Your Document Workflows").append("</a>");
break;
case DOCUMENT_WORKFLOW_USER_FORWARD_TO_OWNER:
actionLink.append("\">").append("Go to Document Workflow Manager").append("</a>");
break;
case DOCUMENT_WORKFLOW_STEP_FORWARD_PEER:
actionLink.append("\">").append("Go to Document Workflow Manager").append("</a>");
break;
case DOCUMENT_WORKFLOW_FORWARD_STEP_COMPLETED_OWNER:
actionLink.append("\">").append("Go to Document Workflow Manager").append("</a>");
break;
default:
actionLink.append("\">").append("").append("</a>");
break;
}
return actionLink.toString();
}
}