emails are working
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerSocial@128068 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
cc6a9872a3
commit
7790c9d91d
11
pom.xml
11
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.applicationsupportlayer</groupId>
|
||||
<artifactId>aslsocial</artifactId>
|
||||
<version>0.16.0-SNAPSHOT</version>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Social Portal ASL Extension</name>
|
||||
<description>
|
||||
|
@ -45,6 +45,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.common.portal</groupId>
|
||||
<artifactId>portal-manager</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -65,11 +66,13 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.dvos</groupId>
|
||||
<artifactId>usermanagement-core</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.portal</groupId>
|
||||
<artifactId>custom-portal-handler</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- FWS DEPS -->
|
||||
|
@ -133,6 +136,12 @@
|
|||
<artifactId>portlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
|
|
@ -5,6 +5,8 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.applicationsupportlayer.social.mailing.EmailPlugin;
|
||||
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
||||
|
@ -21,8 +23,8 @@ import org.gcube.vomanagement.usermanagement.UserManager;
|
|||
import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.UserModel;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -37,20 +39,23 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
|||
|
||||
private String portalName;
|
||||
private String senderEmail;
|
||||
private String portalURL;
|
||||
/**
|
||||
* deprecated method:please use ApplicationNotificationsManager(String scope, {@link SocialNetworkingUser} currUser, String portletClassName)
|
||||
* @deprecated:please use ApplicationNotificationsManager(String scope, {@link SocialNetworkingUser} currUser, String portletClassName)
|
||||
* Use this constructor if you do not need notifications to point back to your applications
|
||||
* @param ASLSession the ASLSession instance
|
||||
*/
|
||||
@Deprecated
|
||||
public ApplicationNotificationsManager(ASLSession session) {
|
||||
super(session);
|
||||
portalName = PortalContext.getConfiguration().getGatewayName();
|
||||
senderEmail = PortalContext.getConfiguration().getSenderEmail();
|
||||
PortalContext context = PortalContext.getConfiguration();
|
||||
portalName = context.getGatewayName();
|
||||
senderEmail = context.getSenderEmail();
|
||||
portalURL = context.getGatewayURL();
|
||||
_log.warn("Asked for Simple Notification (without redirect to creator)");
|
||||
}
|
||||
/**
|
||||
* deprecated method: please use ApplicationNotificationsManager(String scope, {@link SocialNetworkingUser} currUser, String portletClassName)
|
||||
* @deprecated: please use ApplicationNotificationsManager(String scope, {@link SocialNetworkingUser} currUser, String portletClassName)
|
||||
* Use this constructor if you do need notifications to point back to your applications,
|
||||
* make sure you create your application profile on the infrastructure.
|
||||
*
|
||||
|
@ -62,18 +67,19 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
|||
@Deprecated
|
||||
public ApplicationNotificationsManager(ASLSession session, String portletClassName) {
|
||||
super(session, portletClassName);
|
||||
portalName = PortalContext.getConfiguration().getGatewayName();
|
||||
senderEmail = PortalContext.getConfiguration().getSenderEmail();
|
||||
PortalContext context = PortalContext.getConfiguration();
|
||||
portalName = context.getGatewayName();
|
||||
senderEmail = context.getSenderEmail();
|
||||
portalURL = context.getGatewayURL();
|
||||
}
|
||||
/**
|
||||
* Use this constructor if you do not need notifications to point back to your applications
|
||||
* @param scope the current scope
|
||||
* @param currUser an instance of {@link SocialNetworkingUser} filled with the required user data
|
||||
*/
|
||||
public ApplicationNotificationsManager(String scope, SocialNetworkingUser currUser) {
|
||||
public ApplicationNotificationsManager(HttpServletRequest request, String scope, SocialNetworkingUser currUser) {
|
||||
super(scope, currUser);
|
||||
portalName = PortalContext.getConfiguration().getGatewayName();
|
||||
senderEmail = PortalContext.getConfiguration().getSenderEmail();
|
||||
setContext(request);
|
||||
_log.warn("Asked for Simple Notification (without redirect to creator)");
|
||||
}
|
||||
/**
|
||||
|
@ -87,10 +93,19 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
|||
* @param currUser an instance of {@link SocialNetworkingUser} filled with the required user data
|
||||
* @param portletClassName your portlet class name will be used ad unique identifier for your applicationProfile
|
||||
*/
|
||||
public ApplicationNotificationsManager(String scope, SocialNetworkingUser currUser, String portletClassName) {
|
||||
public ApplicationNotificationsManager(HttpServletRequest request, String scope, SocialNetworkingUser currUser, String portletClassName) {
|
||||
super(scope, currUser, portletClassName);
|
||||
portalName = PortalContext.getConfiguration().getGatewayName();
|
||||
senderEmail = PortalContext.getConfiguration().getSenderEmail();
|
||||
setContext(request);
|
||||
}
|
||||
/**
|
||||
* set the current portal context (name, emal, url)
|
||||
* @param request
|
||||
*/
|
||||
private void setContext(HttpServletRequest request) {
|
||||
PortalContext context = PortalContext.getConfiguration();
|
||||
portalName = context.getGatewayName(request);
|
||||
senderEmail = context.getSenderEmail(request);
|
||||
portalURL = context.getGatewayURL(request);
|
||||
}
|
||||
/**
|
||||
* actually save the notification to the store
|
||||
|
@ -117,9 +132,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
|||
else
|
||||
_log.error("Error While trying to save Notification");
|
||||
}
|
||||
if (channels.contains(NotificationChannelType.EMAIL))
|
||||
EmailPlugin.getInstance().sendNotification(notification2Save, currGroupName, portalName, senderEmail, hashtags);
|
||||
|
||||
if (channels.contains(NotificationChannelType.EMAIL)) {
|
||||
EmailPlugin.getInstance(portalURL).sendNotification(notification2Save, currGroupName, portalName, senderEmail, hashtags);
|
||||
}
|
||||
if (channels.isEmpty()) {
|
||||
_log.info("Notification was not needed as "+ notification2Save.getUserid() +" decided not to be notified for " + notification2Save.getType());
|
||||
result = true;
|
||||
|
@ -264,7 +279,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
|
|||
@Override
|
||||
public boolean notifyFolderAddedUser(String userIdToNotify, WorkspaceSharedFolder sharedFolder, String newAddedUserId) throws InternalErrorException, UserManagementSystemException, UserRetrievalFault, UserManagementPortalException {
|
||||
UserManager um = new LiferayUserManager();
|
||||
UserModel user = um.getUserByScreenName(newAddedUserId);
|
||||
GCubeUser user = um.getUserByUsername(newAddedUserId);
|
||||
Notification not = new Notification(
|
||||
UUID.randomUUID().toString(),
|
||||
NotificationType.WP_FOLDER_ADDEDUSER,
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
|||
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Node;
|
||||
|
@ -100,10 +100,10 @@ public class SocialPortalBridge {
|
|||
return store;
|
||||
}
|
||||
|
||||
protected String getScopeByOrganizationId(String vreid) {
|
||||
protected String getScopeByVREId(long vreid) {
|
||||
GroupManager gm = new LiferayGroupManager();
|
||||
try {
|
||||
return gm.getScope(vreid);
|
||||
return gm.getInfrastructureScope(vreid);
|
||||
} catch (Exception e) {
|
||||
_log.error("Could not find a scope for this VREid: " + vreid);
|
||||
return null;
|
||||
|
|
|
@ -43,7 +43,6 @@ public class EmailNotificationsConsumer extends Thread {
|
|||
public EmailNotificationsConsumer() {
|
||||
super();
|
||||
_log.info("EmailNotificationsConsumer thread started at " + new Date() + " trying to fetch SMTP configuration from infrastructure ...");
|
||||
|
||||
//query
|
||||
try {
|
||||
List<ServiceEndpoint> resources = getConfigurationFromIS();
|
||||
|
@ -127,7 +126,7 @@ public class EmailNotificationsConsumer extends Thread {
|
|||
_log.debug("Emails Buffer not empty, sending emails ");
|
||||
Transport t = null;
|
||||
try {
|
||||
t = session.getTransport();
|
||||
t = session.getTransport("smtp");
|
||||
t.connect();
|
||||
|
||||
//sync method to ensure the producer do not put new emails in the meantime
|
||||
|
|
|
@ -15,13 +15,14 @@ import javax.mail.internet.MimeBodyPart;
|
|||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
|
||||
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
||||
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
|
||||
import org.gcube.portal.databook.server.DatabookStore;
|
||||
import org.gcube.portal.databook.shared.Comment;
|
||||
import org.gcube.portal.databook.shared.Feed;
|
||||
import org.gcube.portal.databook.shared.Notification;
|
||||
import org.gcube.portal.databook.shared.NotificationType;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
|
@ -30,10 +31,6 @@ import org.jsoup.nodes.TextNode;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.liferay.portal.model.UserModel;
|
||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||
import com.liferay.portal.util.PortalUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Massimiliano Assante
|
||||
|
@ -48,13 +45,16 @@ public class EmailPlugin {
|
|||
private static EmailPlugin singleton;
|
||||
private static DatabookStore store = new DBCassandraAstyanaxImpl();
|
||||
|
||||
public static EmailPlugin getInstance() {
|
||||
private static String portalURL;
|
||||
|
||||
public static EmailPlugin getInstance(String portalURL) {
|
||||
if (singleton == null)
|
||||
singleton = new EmailPlugin();
|
||||
singleton = new EmailPlugin(portalURL);
|
||||
return singleton;
|
||||
}
|
||||
|
||||
private EmailPlugin() {
|
||||
private EmailPlugin(String portalURL) {
|
||||
EmailPlugin.portalURL = portalURL;
|
||||
new EmailNotificationsConsumer().start();
|
||||
}
|
||||
|
||||
|
@ -394,17 +394,15 @@ public class EmailPlugin {
|
|||
|
||||
protected static Message getMessageNotification(Session session, Notification notification2Save, String vreName, String portalName, String senderEmail, String ... hashtags) throws Exception {
|
||||
|
||||
UserModel user = null;
|
||||
String portalUrl = null;
|
||||
GCubeUser user = null;
|
||||
try {
|
||||
user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), notification2Save.getUserid());
|
||||
portalUrl = PortalUtil.getPortalURL(OrganizationsUtil.getCompany().getVirtualHost(), 443, true);
|
||||
user = new LiferayUserManager().getUserByUsername(notification2Save.getUserid());
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
_log.warn("While trying to get email for user/group: " + notification2Save.getUserid());
|
||||
return null;
|
||||
}
|
||||
String email = user.getEmailAddress();
|
||||
String email = user.getEmail();
|
||||
|
||||
Message msg2Return = new MimeMessage(session);
|
||||
|
||||
|
@ -448,13 +446,13 @@ public class EmailPlugin {
|
|||
}
|
||||
|
||||
// set subject
|
||||
msg2Return.setSubject(getSubjectByNotificationType(notification2Save, portalUrl, vreName, user.getFirstName(), hashtags));
|
||||
msg2Return.setSubject(getSubjectByNotificationType(notification2Save, portalURL, vreName, user.getFirstName(), hashtags));
|
||||
|
||||
final MimeBodyPart textPart = new MimeBodyPart();
|
||||
textPart.setContent(getTextEmail(notification2Save, user.getFirstName(), portalUrl, email, feed, comments, commentKey, hashtags), "text/plain; charset=UTF-8");
|
||||
textPart.setContent(getTextEmail(notification2Save, user.getFirstName(), portalURL, email, feed, comments, commentKey, hashtags), "text/plain; charset=UTF-8");
|
||||
|
||||
final MimeBodyPart htmlPart = new MimeBodyPart();
|
||||
htmlPart.setContent(getHTMLEmail(notification2Save, user.getFirstName(), portalUrl, email, vreName, feed, comments, commentKey, hashtags), "text/html; charset=UTF-8");
|
||||
htmlPart.setContent(getHTMLEmail(notification2Save, user.getFirstName(), portalURL, email, vreName, feed, comments, commentKey, hashtags), "text/html; charset=UTF-8");
|
||||
|
||||
final Multipart mp = new MimeMultipart("alternative");
|
||||
mp.addBodyPart(textPart);
|
||||
|
|
Loading…
Reference in New Issue