From aa8f0fe59bb641f607e25130c1b100f782230a6e Mon Sep 17 00:00:00 2001 From: "massimiliano.assante" Date: Wed, 8 Jul 2015 10:20:15 +0000 Subject: [PATCH] removed method for getting portal instance name and moved to portal manager git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerSocial@117077 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../ApplicationNotificationsManager.java | 69 ++----------------- .../social/mailing/EmailPlugin.java | 20 ++++-- 2 files changed, 21 insertions(+), 68 deletions(-) diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java index 77c4377..4bff3ad 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java @@ -1,12 +1,8 @@ package org.gcube.applicationsupportlayer.social; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; -import java.util.Properties; import java.util.UUID; import org.gcube.application.framework.core.session.ASLSession; @@ -14,7 +10,7 @@ import org.gcube.applicationsupportlayer.social.mailing.EmailPlugin; 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.custom.communitymanager.OrganizationsUtil; +import org.gcube.common.portal.PortalContext; import org.gcube.portal.databook.shared.ApplicationProfile; import org.gcube.portal.databook.shared.Notification; import org.gcube.portal.databook.shared.NotificationChannelType; @@ -29,8 +25,6 @@ import org.gcube.vomanagement.usermanagement.model.UserModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.liferay.portal.kernel.util.Tuple; - /** * * @author Massimiliano Assante, ISTI-CNR @@ -40,9 +34,6 @@ import com.liferay.portal.kernel.util.Tuple; public class ApplicationNotificationsManager extends SocialPortalBridge implements NotificationsManager { private static final Logger _log = LoggerFactory.getLogger(ApplicationNotificationsManager.class); - private static final String SENDER_EMAIL = "notificationSenderEmail"; - private static final String GATEWAY_NAME = "portalinstancename"; - private String portalName; private String senderEmail; /** @@ -51,8 +42,8 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen */ public ApplicationNotificationsManager(ASLSession session) { super(session); - portalName = getPortalInstanceName(); - senderEmail = getNotificationSenderEmail(); + portalName = PortalContext.getPortalInstanceName(); + senderEmail = PortalContext.getConfiguration().getSenderEmail(); _log.warn("Asked for Simple Notification (without redirect to creator)"); } /** @@ -66,8 +57,8 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen */ public ApplicationNotificationsManager(ASLSession session, String portletClassName) { super(session, portletClassName); - portalName = getPortalInstanceName(); - senderEmail = getNotificationSenderEmail(); + portalName = PortalContext.getPortalInstanceName(); + senderEmail = PortalContext.getConfiguration().getSenderEmail(); } /** * actually save the notification to the store @@ -864,54 +855,4 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen return saveNotification(not); } - - /** - * read the portal instance name from a property file and returns it - */ - private static String getPortalInstanceName() { - //get the portles to look for from the property file - Properties props = new Properties(); - String toReturn = ""; - - try { - String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-data.properties"; - File propsFile = new File(propertyfile); - FileInputStream fis = new FileInputStream(propsFile); - props.load( fis); - toReturn = props.getProperty(GATEWAY_NAME); - } - //catch exception in case properties file does not exist - catch(IOException e) { - toReturn = "D4science Gateway"; - _log.error("gcube-data.properties file not found under $CATALINA_HOME/conf dir, returning default Portal Name " + toReturn); - return toReturn; - } - _log.debug("Returning Gateway Name: " + toReturn ); - return toReturn; - } - - /** - * read the sender email for notifications name from a property file and returns it - */ - private static String getNotificationSenderEmail() { - //get the portles to look for from the property file - Properties props = new Properties(); - String toReturn = ""; - - try { - String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-data.properties"; - File propsFile = new File(propertyfile); - FileInputStream fis = new FileInputStream(propsFile); - props.load( fis); - toReturn = props.getProperty(SENDER_EMAIL); - } - //catch exception in case properties file does not exist - catch(IOException e) { - toReturn = "do-not-reply@d4science.org"; - _log.error("gcube-data.properties file not found under $CATALINA_HOME/conf dir, returning default Email" + toReturn); - return toReturn; - } - _log.debug("Returning SENDER_EMAIL: " + toReturn ); - return toReturn; - } } 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 788ec1c..a75a86e 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java @@ -35,6 +35,7 @@ public class EmailPlugin { private static final Logger _log = LoggerFactory.getLogger(EmailPlugin.class); protected static final int SECONDS2WAIT = 60; + public static final String WRITE_ABOVE_TO_REPLY = "- Write ABOVE THIS LINE to post a reply via email -"; private static EmailPlugin singleton; @@ -75,8 +76,13 @@ public class EmailPlugin { StringBuilder body = new StringBuilder(); - body.append("
") - .append("
") + body.append(""); + + if (notification2Save.getType() == NotificationType.POST_ALERT) { + body.append("
").append(WRITE_ABOVE_TO_REPLY).append("

"); + } + + body.append("
") .append("Dear ").append(userFirstName).append(",") //dear .append("

").append(sender).append(" ").append(removedMarkup) // has done something .append(getActionLink(notification2Save, portalURL)).append("

") //Goto @@ -122,6 +128,10 @@ public class EmailPlugin { StringBuilder body = new StringBuilder(); + if (notification2Save.getType() == NotificationType.POST_ALERT) { + body.append(WRITE_ABOVE_TO_REPLY).append("\n\n"); + } + body.append("Dear ").append(userFirstName).append(",") //dear .append("\n").append(sender).append(" ").append(removedMarkup) // has done something .append("\nsee: ").append(portalURL).append(notification2Save.getUri()) @@ -199,7 +209,7 @@ public class EmailPlugin { * @param portalName * @param senderEmail */ - public void sendNotification(Notification notification2Save, String vreName, String portalName, String senderEmail, String ... hashtags) { + public void sendNotification(Notification notification2Save, String vreName, String portalName, String senderEmail, String ... hashtags) { EmailNotificationProducer thread = new EmailNotificationProducer(new NotificationMail(notification2Save, vreName, portalName, senderEmail, hashtags)); thread.start(); } @@ -220,7 +230,9 @@ public class EmailPlugin { Message msg2Return = new MimeMessage(session); - + if (notification2Save.getType() == NotificationType.POST_ALERT) { + senderEmail = "social.post@d4science.org"; + } // EMAIL SENDER msg2Return.setHeader("Content-Type", "text/html; charset=UTF-8"); msg2Return.setFrom(new InternetAddress(senderEmail, portalName));