From 1e710f243038bd0e774a1dc3144ff8800dcabe85 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Tue, 26 Apr 2016 14:26:57 +0000 Subject: [PATCH] integrated with centralized email notification git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/join-vre@128318 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 8 +++--- .../user/joinvre/server/JoinServiceImpl.java | 11 +++----- .../user/joinvre/server/LoginServiceUtil.java | 25 +++++++++++++------ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index f38bb86..507427b 100644 --- a/pom.xml +++ b/pom.xml @@ -69,7 +69,6 @@ com.github.gwtbootstrap gwt-bootstrap - 2.3.2.0 org.gcube.portal @@ -115,9 +114,8 @@ provided - javax.mail - javax.mail-api - 1.4.5 + com.sun.mail + javax.mail provided @@ -236,7 +234,7 @@ - + diff --git a/src/main/java/org/gcube/portlets/user/joinvre/server/JoinServiceImpl.java b/src/main/java/org/gcube/portlets/user/joinvre/server/JoinServiceImpl.java index 60701e6..bcd56ad 100644 --- a/src/main/java/org/gcube/portlets/user/joinvre/server/JoinServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/joinvre/server/JoinServiceImpl.java @@ -8,9 +8,7 @@ import java.util.List; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.SessionManager; -import org.gcube.common.portal.CustomAttributeKeys; import org.gcube.common.portal.GCubePortalConstants; -import org.gcube.common.portal.PortalContext; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl; import org.gcube.portal.databook.server.DatabookStore; @@ -29,6 +27,7 @@ import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemExcep import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; +import org.gcube.vomanagement.usermanagement.model.CustomAttributeKeys; import org.gcube.vomanagement.usermanagement.model.GCubeGroup; import org.gcube.vomanagement.usermanagement.model.GCubeMembershipRequest; import org.gcube.vomanagement.usermanagement.model.GCubeUser; @@ -375,7 +374,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService if (optionalMessage == null || optionalMessage.compareTo("") == 0) optionalMessage = "none"; try { - LoginServiceUtil.addMembershipRequest(username, scope, optionalMessage, getPortalUrl(), PortalContext.getConfiguration().getGatewayName()); + LoginServiceUtil.addMembershipRequest(username, scope, optionalMessage, getThreadLocalRequest()); } catch (Exception e) { e.printStackTrace(); } @@ -395,7 +394,6 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService try { ASLSession session = getASLSession(); String username = session.getUsername(); - String gatewayURL = PortalContext.getConfiguration().getGatewayURL(getThreadLocalRequest()); _log.debug("registerUser " +username + " to "+ scope); GCubeUser currUser = um.getUserByUsername(username); GroupManager gm = new LiferayGroupManager(); @@ -406,18 +404,17 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService Thread.sleep(1000); um.acceptMembershipRequest(currUser.getUserId(), groupId, true, replierUsername, "Automatic acceptance request at " + new Date()); _log.info("fakeRequest accepted"); - String gatewayName = PortalContext.getConfiguration().getGatewayName(); if (isInvitation) { initStore(); String inviteId = store.isExistingInvite(scope, session.getUserEmailAddress()); if (inviteId != null) { Invite invite = store.readInvite(inviteId); store.setInviteStatus(scope, session.getUserEmailAddress(), InviteStatus.ACCEPTED); - LoginServiceUtil.notifyUserAcceptedInvite(username, scope, gatewayURL, gatewayName, invite); + LoginServiceUtil.notifyUserAcceptedInvite(username, scope, invite, getThreadLocalRequest()); } } else { - LoginServiceUtil.notifyUserSelfRegistration(username, scope, gatewayURL, gatewayName); + LoginServiceUtil.notifyUserSelfRegistration(username, scope, getThreadLocalRequest()); _log.info("notifyUserSelfRegistration sent"); } } diff --git a/src/main/java/org/gcube/portlets/user/joinvre/server/LoginServiceUtil.java b/src/main/java/org/gcube/portlets/user/joinvre/server/LoginServiceUtil.java index 395f519..6b7e0fa 100644 --- a/src/main/java/org/gcube/portlets/user/joinvre/server/LoginServiceUtil.java +++ b/src/main/java/org/gcube/portlets/user/joinvre/server/LoginServiceUtil.java @@ -5,6 +5,9 @@ import java.util.List; import java.util.Map; import java.util.Set; +import javax.servlet.http.HttpServletRequest; + +import org.gcube.common.portal.PortalContext; import org.gcube.common.portal.mailing.EmailNotification; import org.gcube.portal.databook.shared.Invite; import org.gcube.vomanagement.usermanagement.GroupManager; @@ -87,7 +90,10 @@ public class LoginServiceUtil { * @param scope . * @param optionalMessage . */ - public static void addMembershipRequest(String username, String scope, String optionalMessage,String portalbasicurl, String gatewayName) throws Exception{ + public static void addMembershipRequest(String username, String scope, String optionalMessage, HttpServletRequest request) throws Exception{ + + String gatewayName = PortalContext.getConfiguration().getGatewayName(request); + String portalbasicurl = PortalContext.getConfiguration().getGatewayURL(request); _log.info("gatewayName = " + gatewayName + " Message=" + optionalMessage); @@ -130,7 +136,7 @@ public class LoginServiceUtil { adminEmails.toArray(allMails); - EmailNotification mailToAdmin = new EmailNotification(allMails , "[" + gatewayName + "] - Join Request", body.toString()); + EmailNotification mailToAdmin = new EmailNotification(allMails , "[" + gatewayName + "] - Join Request", body.toString(), request); mailToAdmin.sendEmail(); } @@ -140,15 +146,15 @@ public class LoginServiceUtil { * @param scope . * @param optionalMessage . */ - public static void notifyUserSelfRegistration(String username, String scope, String portalbasicurl, String gatewayName) throws Exception { + public static void notifyUserSelfRegistration(String username, String scope, HttpServletRequest request) throws Exception { ArrayList adminEmails = LoginServiceUtil.getAdministratorsEmails(scope); LiferayUserManager um = new LiferayUserManager(); GCubeUser currUser = um.getUserByUsername(username); String name = currUser.getFirstName(); String lastname = currUser.getLastName(); - - + String portalbasicurl = PortalContext.getConfiguration().getGatewayURL(request); + String gatewayName = PortalContext.getConfiguration().getGatewayName(request); StringBuffer body = new StringBuffer(); body.append("

Dear manager of "+ scope +",
this email message was automatically generated by " + portalbasicurl +" to inform you that "); body.append("

").append("

") @@ -169,7 +175,7 @@ public class LoginServiceUtil { adminEmails.toArray(allMails); - EmailNotification mailToAdmin = new EmailNotification(allMails , "[" + gatewayName + "] - Self Registration", body.toString()); + EmailNotification mailToAdmin = new EmailNotification(allMails , "[" + gatewayName + "] - Self Registration", body.toString(), request); mailToAdmin.sendEmail(); } @@ -180,8 +186,11 @@ public class LoginServiceUtil { * @param scope . * @param optionalMessage . */ - public static void notifyUserAcceptedInvite(String username, String scope, String portalbasicurl, String gatewayName, Invite invite) throws Exception { + public static void notifyUserAcceptedInvite(String username, String scope, Invite invite, HttpServletRequest request) throws Exception { + String portalbasicurl = PortalContext.getConfiguration().getGatewayURL(request); + String gatewayName = PortalContext.getConfiguration().getGatewayName(request); + ArrayList adminEmails = LoginServiceUtil.getAdministratorsEmails(scope); LiferayUserManager um = new LiferayUserManager(); @@ -212,7 +221,7 @@ public class LoginServiceUtil { adminEmails.toArray(allMails); - EmailNotification mailToAdmin = new EmailNotification(allMails , "[" + gatewayName + "] - Accepted Invitation", body.toString()); + EmailNotification mailToAdmin = new EmailNotification(allMails , "[" + gatewayName + "] - Accepted Invitation", body.toString(), request); mailToAdmin.sendEmail(); }