From 5183a676f16a9358b7dc4ef528870792eb2443ed Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Tue, 22 Mar 2016 17:48:34 +0000 Subject: [PATCH] self registration almost complete git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/join-vre@126074 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../user/joinvre/client/JoinService.java | 2 + .../user/joinvre/client/JoinServiceAsync.java | 3 + .../portlets/user/joinvre/client/JoinVRE.java | 2 +- .../client/responsive/ResponsivePanel.java | 21 ++++-- .../joinvre/client/ui/AccessVREDialog.java | 71 +++++++++++++++++++ .../joinvre/client/ui/AccessVREDialog.ui.xml | 20 ++++++ .../client/ui/RequestMembershipDialog.java | 1 - .../user/joinvre/server/JoinServiceImpl.java | 68 ++++++++++++++++++ .../user/joinvre/server/LoginServiceUtil.java | 5 +- 9 files changed, 181 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/joinvre/client/ui/AccessVREDialog.java create mode 100644 src/main/java/org/gcube/portlets/user/joinvre/client/ui/AccessVREDialog.ui.xml diff --git a/src/main/java/org/gcube/portlets/user/joinvre/client/JoinService.java b/src/main/java/org/gcube/portlets/user/joinvre/client/JoinService.java index 6612f48..451dfc1 100644 --- a/src/main/java/org/gcube/portlets/user/joinvre/client/JoinService.java +++ b/src/main/java/org/gcube/portlets/user/joinvre/client/JoinService.java @@ -23,4 +23,6 @@ public interface JoinService extends RemoteService { VRE getSelectedVRE(Long vreId); void addMembershipRequest(String scope, String optionalMessage); + + boolean registerUser(String scope, long vreId, boolean isInvitation); } diff --git a/src/main/java/org/gcube/portlets/user/joinvre/client/JoinServiceAsync.java b/src/main/java/org/gcube/portlets/user/joinvre/client/JoinServiceAsync.java index fec19d6..b45f389 100644 --- a/src/main/java/org/gcube/portlets/user/joinvre/client/JoinServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/joinvre/client/JoinServiceAsync.java @@ -21,4 +21,7 @@ public interface JoinServiceAsync { void addMembershipRequest(String scope, String optionalMessage, AsyncCallback callback); + + void registerUser(String scope, long vreId, boolean isInvitation, + AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/user/joinvre/client/JoinVRE.java b/src/main/java/org/gcube/portlets/user/joinvre/client/JoinVRE.java index 2e21f25..9150daa 100644 --- a/src/main/java/org/gcube/portlets/user/joinvre/client/JoinVRE.java +++ b/src/main/java/org/gcube/portlets/user/joinvre/client/JoinVRE.java @@ -70,7 +70,7 @@ public class JoinVRE implements EntryPoint { default: //Not belonging logger.log(Level.INFO, "User is NOT Belonging"); rp = displayVREs(); - rp.requestMembership(vre); + rp.requestMembership(vre, vre.getinfraScope(), false); break; } } diff --git a/src/main/java/org/gcube/portlets/user/joinvre/client/responsive/ResponsivePanel.java b/src/main/java/org/gcube/portlets/user/joinvre/client/responsive/ResponsivePanel.java index 0bfcf8f..b8b6d12 100644 --- a/src/main/java/org/gcube/portlets/user/joinvre/client/responsive/ResponsivePanel.java +++ b/src/main/java/org/gcube/portlets/user/joinvre/client/responsive/ResponsivePanel.java @@ -5,6 +5,7 @@ import java.util.LinkedHashMap; import org.gcube.portlets.user.joinvre.client.JoinService; import org.gcube.portlets.user.joinvre.client.JoinServiceAsync; +import org.gcube.portlets.user.joinvre.client.ui.AccessVREDialog; import org.gcube.portlets.user.joinvre.client.ui.RequestMembershipDialog; import org.gcube.portlets.user.joinvre.client.ui.VreThumbnail; import org.gcube.portlets.user.joinvre.shared.VRE; @@ -19,7 +20,7 @@ import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.VerticalPanel; public class ResponsivePanel extends Composite { - + private final JoinServiceAsync joinService = GWT.create(JoinService.class); public static final String loading = GWT.getModuleBaseURL() + "../images/vre-loader.gif"; @@ -42,7 +43,7 @@ public class ResponsivePanel extends Composite { header.setSubtext(cat.getDescription()); mainPanel.add(header); mainPanel.add(getVREThumbnails(categories, cat)); - + } } } @@ -66,15 +67,21 @@ public class ResponsivePanel extends Composite { } return toReturn; } - + protected void showError(String message) { mainPanel.clear(); mainPanel.add(new HTML("
" + message + ". Please reload this page.
")); } - - public void requestMembership(VRE vre) { - RequestMembershipDialog modal = new RequestMembershipDialog(vre); - modal.show(); + + public void requestMembership(VRE vre, String scope, boolean isInvitation) { + if (vre.isUponRequest()) { + RequestMembershipDialog modal = new RequestMembershipDialog(vre); + modal.show(); + } else { + AccessVREDialog modal = new AccessVREDialog(vre, isInvitation); + modal.show(); + } + } } diff --git a/src/main/java/org/gcube/portlets/user/joinvre/client/ui/AccessVREDialog.java b/src/main/java/org/gcube/portlets/user/joinvre/client/ui/AccessVREDialog.java new file mode 100644 index 0000000..be19512 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/joinvre/client/ui/AccessVREDialog.java @@ -0,0 +1,71 @@ +package org.gcube.portlets.user.joinvre.client.ui; + +import org.gcube.portlets.user.joinvre.client.JoinService; +import org.gcube.portlets.user.joinvre.client.JoinServiceAsync; +import org.gcube.portlets.user.joinvre.shared.VRE; + +import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.HelpBlock; +import com.github.gwtbootstrap.client.ui.Modal; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.uibinder.client.UiHandler; +import com.google.gwt.user.client.Window.Location; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.Widget; + +public class AccessVREDialog extends Composite { + private final JoinServiceAsync joinService = GWT.create(JoinService.class); + private static AccessVREDialogUiBinder uiBinder = GWT + .create(AccessVREDialogUiBinder.class); + + interface AccessVREDialogUiBinder extends UiBinder { + } + @UiField Modal m; + @UiField Button close; + @UiField Button confirmRequest; + @UiField HelpBlock helpBlock; + private boolean isInvitation = false; + VRE myVRE = null; + public AccessVREDialog(final VRE vre, boolean isInvitation) { + initWidget(uiBinder.createAndBindUi(this)); + this.myVRE = vre; + this.isInvitation = isInvitation; + String text = isInvitation ? "To accept the invite, please click on the accept invite button below" : "You are about to enter the " + vre.getName() + ", please confirm your request."; + helpBlock.setText(text); + String buttonText = isInvitation ? "Accept invite" : "Confirm Request"; + confirmRequest.setText(buttonText); + } + + public void show() { + String headerText = isInvitation ? "Invitation to " + myVRE.getName() : "Join request for " + myVRE.getName(); + m.setTitle(headerText); + m.show(); + } + + @UiHandler("close") + void handleClick(ClickEvent e) { + m.hide(); + } + @UiHandler("confirmRequest") + void confirm(ClickEvent e) { + helpBlock.setText("Registering to " + myVRE.getName() + " please wait ... "); + joinService.registerUser(myVRE.getinfraScope(), myVRE.getId(), isInvitation, new AsyncCallback() { + + @Override + public void onSuccess(Boolean result) { + Location.assign(myVRE.getFriendlyURL()); + } + + @Override + public void onFailure(Throwable caught) { + confirmRequest.removeFromParent(); + m.setTitle("An error occurred! Your request has not been sent"); + helpBlock.setText("An email with the cause of the error has been sent to the support team, we'll be back to you shortly."); + } + }); + } +} diff --git a/src/main/java/org/gcube/portlets/user/joinvre/client/ui/AccessVREDialog.ui.xml b/src/main/java/org/gcube/portlets/user/joinvre/client/ui/AccessVREDialog.ui.xml new file mode 100644 index 0000000..b8d531a --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/joinvre/client/ui/AccessVREDialog.ui.xml @@ -0,0 +1,20 @@ + + + + + + + + By entering this VRE you agree to the terms indicated in the + Terms of Use + of this gateway. + + + Confirm Request + Close + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/joinvre/client/ui/RequestMembershipDialog.java b/src/main/java/org/gcube/portlets/user/joinvre/client/ui/RequestMembershipDialog.java index f4e7303..13cbfd7 100644 --- a/src/main/java/org/gcube/portlets/user/joinvre/client/ui/RequestMembershipDialog.java +++ b/src/main/java/org/gcube/portlets/user/joinvre/client/ui/RequestMembershipDialog.java @@ -15,7 +15,6 @@ import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiHandler; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.Widget; public class RequestMembershipDialog extends Composite { 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 ba7ceb7..e09b260 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 @@ -5,12 +5,18 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; +import javax.servlet.http.HttpServletRequest; + 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; +import org.gcube.portal.databook.shared.Invite; +import org.gcube.portal.databook.shared.InviteStatus; import org.gcube.portlets.user.joinvre.client.JoinService; import org.gcube.portlets.user.joinvre.shared.UserBelonging; import org.gcube.portlets.user.joinvre.shared.VRE; @@ -48,6 +54,7 @@ import com.liferay.portal.util.PortalUtil; public class JoinServiceImpl extends RemoteServiceServlet implements JoinService { private static Log _log = LogFactoryUtil.getLog(JoinServiceImpl.class); private static final String TEST_USER = "test.user"; + private static DatabookStore store; /** * the current ASLSession * @return the session @@ -372,4 +379,65 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService public String getPortalUrl() throws PortalException, SystemException { return PortalUtil.getPortalURL(this.getThreadLocalRequest()); } + + /** + * the user to the VRE, plus send notifications to the vre manages of the vre + */ + @Override + public boolean registerUser(String scope, long groupId, boolean isInvitation) { + UserManager userM = new LiferayUserManager(); + try { + ASLSession session = getASLSession(); + String username = session.getUsername(); + //add the user to the VRE + userM.assignUserToGroup(groupId, userM.getUserId(username)); + 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, getPortalBasicUrl(), gatewayName, invite); + } + } + else { + //LoginServiceUtil.notifyUserSelfRegistration(username, scope, getPortalBasicUrl(), gatewayName); + _log.info("notifyUserSelfRegistration sent"); + } + } + catch (Exception e) { + e.printStackTrace(); + return false; + } + return true; + } + + /** + * + * @return the unique instance of the store + */ + public static synchronized DatabookStore initStore() { + if (store == null) { + store = new DBCassandraAstyanaxImpl(); + } + return store; + } + /** + * + * @return the portal basic url, e.g. http://www.foo.com + */ + private String getPortalBasicUrl() { + HttpServletRequest request = this.getThreadLocalRequest(); + String toReturn = ""; + //protocol + String protocol = (request.isSecure()) ? "https://" : "http://" ; + toReturn += protocol; + //server name + toReturn += request.getServerName(); + //port + toReturn += (request.getServerPort() == 80) ? "" : ":"+request.getServerPort() ; + //_log.trace("getPortalBasicUrl: " +toReturn + "request.getServerPort: " + request.getServerPort()); + return toReturn; + } } 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 d7e4db5..d01657c 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 @@ -7,7 +7,6 @@ import java.util.Set; import org.gcube.common.portal.PortalContext; import org.gcube.portal.databook.shared.Invite; -import org.gcube.portlets.user.joinvre.shared.VO; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.UserManager; import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; @@ -145,7 +144,7 @@ public class LoginServiceUtil { * @param scope . * @param optionalMessage . */ - public static void notifyUserSelfRegistration(String username, VO rootVO, String scope, String portalbasicurl, String gatewayName) throws Exception { + public static void notifyUserSelfRegistration(String username, String scope, String portalbasicurl, String gatewayName) throws Exception { ArrayList adminEmails = LoginServiceUtil.getAdministratorsEmails(scope); LiferayUserManager um = new LiferayUserManager(); @@ -191,7 +190,7 @@ public class LoginServiceUtil { * @param scope . * @param optionalMessage . */ - public static void notifyUserAcceptedInvite(String username, VO rootVO, String scope, String portalbasicurl, String gatewayName, Invite invite) throws Exception { + public static void notifyUserAcceptedInvite(String username, String scope, String portalbasicurl, String gatewayName, Invite invite) throws Exception { ArrayList adminEmails = LoginServiceUtil.getAdministratorsEmails(scope);