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
This commit is contained in:
Massimiliano Assante 2016-04-26 14:26:57 +00:00
parent c3d2f0d456
commit 1e710f2430
3 changed files with 24 additions and 20 deletions

View File

@ -69,7 +69,6 @@
<dependency> <dependency>
<groupId>com.github.gwtbootstrap</groupId> <groupId>com.github.gwtbootstrap</groupId>
<artifactId>gwt-bootstrap</artifactId> <artifactId>gwt-bootstrap</artifactId>
<version>2.3.2.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.portal</groupId> <groupId>org.gcube.portal</groupId>
@ -115,9 +114,8 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.mail</groupId> <groupId>com.sun.mail</groupId>
<artifactId>javax.mail-api</artifactId> <artifactId>javax.mail</artifactId>
<version>1.4.5</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -236,7 +234,7 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>

View File

@ -8,9 +8,7 @@ import java.util.List;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager; 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.GCubePortalConstants;
import org.gcube.common.portal.PortalContext;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl; import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
import org.gcube.portal.databook.server.DatabookStore; 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.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; 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.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeMembershipRequest; import org.gcube.vomanagement.usermanagement.model.GCubeMembershipRequest;
import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.gcube.vomanagement.usermanagement.model.GCubeUser;
@ -375,7 +374,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
if (optionalMessage == null || optionalMessage.compareTo("") == 0) if (optionalMessage == null || optionalMessage.compareTo("") == 0)
optionalMessage = "none"; optionalMessage = "none";
try { try {
LoginServiceUtil.addMembershipRequest(username, scope, optionalMessage, getPortalUrl(), PortalContext.getConfiguration().getGatewayName()); LoginServiceUtil.addMembershipRequest(username, scope, optionalMessage, getThreadLocalRequest());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -395,7 +394,6 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
try { try {
ASLSession session = getASLSession(); ASLSession session = getASLSession();
String username = session.getUsername(); String username = session.getUsername();
String gatewayURL = PortalContext.getConfiguration().getGatewayURL(getThreadLocalRequest());
_log.debug("registerUser " +username + " to "+ scope); _log.debug("registerUser " +username + " to "+ scope);
GCubeUser currUser = um.getUserByUsername(username); GCubeUser currUser = um.getUserByUsername(username);
GroupManager gm = new LiferayGroupManager(); GroupManager gm = new LiferayGroupManager();
@ -406,18 +404,17 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
Thread.sleep(1000); Thread.sleep(1000);
um.acceptMembershipRequest(currUser.getUserId(), groupId, true, replierUsername, "Automatic acceptance request at " + new Date()); um.acceptMembershipRequest(currUser.getUserId(), groupId, true, replierUsername, "Automatic acceptance request at " + new Date());
_log.info("fakeRequest accepted"); _log.info("fakeRequest accepted");
String gatewayName = PortalContext.getConfiguration().getGatewayName();
if (isInvitation) { if (isInvitation) {
initStore(); initStore();
String inviteId = store.isExistingInvite(scope, session.getUserEmailAddress()); String inviteId = store.isExistingInvite(scope, session.getUserEmailAddress());
if (inviteId != null) { if (inviteId != null) {
Invite invite = store.readInvite(inviteId); Invite invite = store.readInvite(inviteId);
store.setInviteStatus(scope, session.getUserEmailAddress(), InviteStatus.ACCEPTED); store.setInviteStatus(scope, session.getUserEmailAddress(), InviteStatus.ACCEPTED);
LoginServiceUtil.notifyUserAcceptedInvite(username, scope, gatewayURL, gatewayName, invite); LoginServiceUtil.notifyUserAcceptedInvite(username, scope, invite, getThreadLocalRequest());
} }
} }
else { else {
LoginServiceUtil.notifyUserSelfRegistration(username, scope, gatewayURL, gatewayName); LoginServiceUtil.notifyUserSelfRegistration(username, scope, getThreadLocalRequest());
_log.info("notifyUserSelfRegistration sent"); _log.info("notifyUserSelfRegistration sent");
} }
} }

View File

@ -5,6 +5,9 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; 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.common.portal.mailing.EmailNotification;
import org.gcube.portal.databook.shared.Invite; import org.gcube.portal.databook.shared.Invite;
import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.GroupManager;
@ -87,7 +90,10 @@ public class LoginServiceUtil {
* @param scope . * @param scope .
* @param optionalMessage . * @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); _log.info("gatewayName = " + gatewayName + " Message=" + optionalMessage);
@ -130,7 +136,7 @@ public class LoginServiceUtil {
adminEmails.toArray(allMails); 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(); mailToAdmin.sendEmail();
} }
@ -140,15 +146,15 @@ public class LoginServiceUtil {
* @param scope . * @param scope .
* @param optionalMessage . * @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<String> adminEmails = LoginServiceUtil.getAdministratorsEmails(scope); ArrayList<String> adminEmails = LoginServiceUtil.getAdministratorsEmails(scope);
LiferayUserManager um = new LiferayUserManager(); LiferayUserManager um = new LiferayUserManager();
GCubeUser currUser = um.getUserByUsername(username); GCubeUser currUser = um.getUserByUsername(username);
String name = currUser.getFirstName(); String name = currUser.getFirstName();
String lastname = currUser.getLastName(); String lastname = currUser.getLastName();
String portalbasicurl = PortalContext.getConfiguration().getGatewayURL(request);
String gatewayName = PortalContext.getConfiguration().getGatewayName(request);
StringBuffer body = new StringBuffer(); StringBuffer body = new StringBuffer();
body.append("<p>Dear manager of "+ scope +",<br />this email message was automatically generated by " + portalbasicurl +" to inform you that "); body.append("<p>Dear manager of "+ scope +",<br />this email message was automatically generated by " + portalbasicurl +" to inform you that ");
body.append("</p>").append("<p>") body.append("</p>").append("<p>")
@ -169,7 +175,7 @@ public class LoginServiceUtil {
adminEmails.toArray(allMails); 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(); mailToAdmin.sendEmail();
} }
@ -180,8 +186,11 @@ public class LoginServiceUtil {
* @param scope . * @param scope .
* @param optionalMessage . * @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<String> adminEmails = LoginServiceUtil.getAdministratorsEmails(scope); ArrayList<String> adminEmails = LoginServiceUtil.getAdministratorsEmails(scope);
LiferayUserManager um = new LiferayUserManager(); LiferayUserManager um = new LiferayUserManager();
@ -212,7 +221,7 @@ public class LoginServiceUtil {
adminEmails.toArray(allMails); 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(); mailToAdmin.sendEmail();
} }