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
This commit is contained in:
Massimiliano Assante 2016-03-22 17:48:34 +00:00
parent c82d04328d
commit 5183a676f1
9 changed files with 181 additions and 12 deletions

View File

@ -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);
}

View File

@ -21,4 +21,7 @@ public interface JoinServiceAsync {
void addMembershipRequest(String scope, String optionalMessage,
AsyncCallback<Void> callback);
void registerUser(String scope, long vreId, boolean isInvitation,
AsyncCallback<Boolean> callback);
}

View File

@ -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;
}
}

View File

@ -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("<div class=\"frame\" style=\"font-size: 16px;\">" + message + ". Please <a href=\"javascript: location.reload();\">reload</a> this page.</div>"));
}
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();
}
}
}

View File

@ -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<Widget, AccessVREDialog> {
}
@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<Boolean>() {
@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.");
}
});
}
}

View File

@ -0,0 +1,20 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<g:HTMLPanel>
<b:Modal ui:field="m" title="My Modal" backdrop="STATIC"
keyboard="true" animation="true">
<b:HelpBlock ui:field="helpBlock"></b:HelpBlock>
<b:HelpBlock>
By entering this VRE you agree to the terms indicated in the
<a href="/web/guest/terms-of-use" target="_blank">Terms of Use</a>
of this gateway.
</b:HelpBlock>
<b:ModalFooter>
<b:Button type="PRIMARY" ui:field="confirmRequest">Confirm Request</b:Button>
<b:Button type="DEFAULT" ui:field="close">Close</b:Button>
</b:ModalFooter>
</b:Modal>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -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 {

View File

@ -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;
}
}

View File

@ -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<String> 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<String> adminEmails = LoginServiceUtil.getAdministratorsEmails(scope);