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
This commit is contained in:
Massimiliano Assante 2015-07-08 10:20:15 +00:00
parent f308e14d1e
commit aa8f0fe59b
2 changed files with 21 additions and 68 deletions

View File

@ -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;
}
}

View File

@ -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("<body><br />")
.append("<div style=\"color:#000; font-size:13px; font-family:'lucida grande',tahoma,verdana,arial,sans-serif;\">")
body.append("<body>");
if (notification2Save.getType() == NotificationType.POST_ALERT) {
body.append("<div>").append(WRITE_ABOVE_TO_REPLY).append("</div><br />");
}
body.append("<div style=\"color:#000; font-size:13px; font-family:'lucida grande',tahoma,verdana,arial,sans-serif;\">")
.append("Dear ").append(userFirstName).append(",") //dear <user>
.append("<p>").append(sender).append(" ").append(removedMarkup) // has done something
.append(getActionLink(notification2Save, portalURL)).append("</p>") //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 <user>
.append("\n").append(sender).append(" ").append(removedMarkup) // has done something
.append("\nsee: ").append(portalURL).append(notification2Save.getUri())
@ -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));