fixed email sender
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerSocial@92717 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
bd160b5396
commit
b82db948b1
|
@ -1,12 +1,17 @@
|
||||||
package org.gcube.applicationsupportlayer.social;
|
package org.gcube.applicationsupportlayer.social;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
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.Properties;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.application.framework.core.session.ASLSession;
|
import org.gcube.application.framework.core.session.ASLSession;
|
||||||
import org.gcube.applicationsupportlayer.social.mailing.EmailPlugin;
|
import org.gcube.applicationsupportlayer.social.mailing.EmailPlugin;
|
||||||
|
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
||||||
import org.gcube.portal.databook.shared.ApplicationProfile;
|
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;
|
||||||
|
@ -34,12 +39,19 @@ import org.slf4j.LoggerFactory;
|
||||||
public class ApplicationNotificationsManager extends SocialPortalBridge implements NotificationsManager {
|
public class ApplicationNotificationsManager extends SocialPortalBridge implements NotificationsManager {
|
||||||
private static final Logger _log = LoggerFactory.getLogger(ApplicationNotificationsManager.class);
|
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;
|
||||||
/**
|
/**
|
||||||
* Use this constructor if you do not need notifications to point back to your applications
|
* Use this constructor if you do not need notifications to point back to your applications
|
||||||
* @param aslSession the ASLSession instance
|
* @param aslSession the ASLSession instance
|
||||||
*/
|
*/
|
||||||
public ApplicationNotificationsManager(ASLSession session) {
|
public ApplicationNotificationsManager(ASLSession session) {
|
||||||
super(session);
|
super(session);
|
||||||
|
portalName = getPortalInstanceName();
|
||||||
|
senderEmail = getNotificationSenderEmail();
|
||||||
_log.warn("Asked for Simple Notification (without redirect to creator)");
|
_log.warn("Asked for Simple Notification (without redirect to creator)");
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -53,6 +65,8 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
||||||
*/
|
*/
|
||||||
public ApplicationNotificationsManager(ASLSession session, String portletClassName) {
|
public ApplicationNotificationsManager(ASLSession session, String portletClassName) {
|
||||||
super(session, portletClassName);
|
super(session, portletClassName);
|
||||||
|
portalName = getPortalInstanceName();
|
||||||
|
senderEmail = getNotificationSenderEmail();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* actually save the notification to the store
|
* actually save the notification to the store
|
||||||
|
@ -80,7 +94,7 @@ 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.sendNotification(notification2Save, aslSession.getGroupName());
|
EmailPlugin.sendNotification(notification2Save, aslSession.getGroupName(), portalName, senderEmail);
|
||||||
|
|
||||||
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());
|
||||||
|
@ -753,4 +767,55 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
||||||
|
|
||||||
return saveNotification(not);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package org.gcube.applicationsupportlayer.social.mailing;
|
package org.gcube.applicationsupportlayer.social.mailing;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@ -28,7 +31,7 @@ import com.liferay.portal.util.PortalUtil;
|
||||||
public class EmailPlugin {
|
public class EmailPlugin {
|
||||||
|
|
||||||
private static final Logger _log = LoggerFactory.getLogger(EmailPlugin.class);
|
private static final Logger _log = LoggerFactory.getLogger(EmailPlugin.class);
|
||||||
|
|
||||||
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 removedMarkup = notification2Save.getDescription().replaceAll("&", "&");
|
String removedMarkup = notification2Save.getDescription().replaceAll("&", "&");
|
||||||
|
@ -75,7 +78,7 @@ public class EmailPlugin {
|
||||||
return completeActonLinkByNotificationType(notification2Save, actionLink, portalURL);
|
return completeActonLinkByNotificationType(notification2Save, actionLink, portalURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendNotification(Notification notification2Save, String vreName) {
|
public static void sendNotification(Notification notification2Save, String vreName, String portalName, String senderEmail) {
|
||||||
|
|
||||||
UserModel user = null;
|
UserModel user = null;
|
||||||
String portalUrl = null;
|
String portalUrl = null;
|
||||||
|
@ -98,7 +101,7 @@ public class EmailPlugin {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// EMAIL SENDER
|
// EMAIL SENDER
|
||||||
Address from = new InternetAddress("no-reply@d4science.org");
|
Address from = new InternetAddress(senderEmail, portalName);
|
||||||
mimeMessage.setHeader("Content-Type", "text/html; charset=UTF-8");
|
mimeMessage.setHeader("Content-Type", "text/html; charset=UTF-8");
|
||||||
mimeMessage.setFrom(from);
|
mimeMessage.setFrom(from);
|
||||||
Address address = new InternetAddress(email);
|
Address address = new InternetAddress(email);
|
||||||
|
@ -269,6 +272,7 @@ public class EmailPlugin {
|
||||||
|
|
||||||
return actionLink.toString();
|
return actionLink.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue