self registration complete

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/join-vre@126084 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-03-23 10:08:45 +00:00
parent 5183a676f1
commit 4744b7401f
4 changed files with 28 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import org.gcube.portlets.user.joinvre.shared.VRE;
import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.HelpBlock; import com.github.gwtbootstrap.client.ui.HelpBlock;
import com.github.gwtbootstrap.client.ui.Icon;
import com.github.gwtbootstrap.client.ui.Modal; import com.github.gwtbootstrap.client.ui.Modal;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
@ -28,6 +29,7 @@ public class AccessVREDialog extends Composite {
@UiField Button close; @UiField Button close;
@UiField Button confirmRequest; @UiField Button confirmRequest;
@UiField HelpBlock helpBlock; @UiField HelpBlock helpBlock;
@UiField Icon loading;
private boolean isInvitation = false; private boolean isInvitation = false;
VRE myVRE = null; VRE myVRE = null;
public AccessVREDialog(final VRE vre, boolean isInvitation) { public AccessVREDialog(final VRE vre, boolean isInvitation) {
@ -53,6 +55,7 @@ public class AccessVREDialog extends Composite {
@UiHandler("confirmRequest") @UiHandler("confirmRequest")
void confirm(ClickEvent e) { void confirm(ClickEvent e) {
helpBlock.setText("Registering to " + myVRE.getName() + " please wait ... "); helpBlock.setText("Registering to " + myVRE.getName() + " please wait ... ");
loading.setVisible(true);
joinService.registerUser(myVRE.getinfraScope(), myVRE.getId(), isInvitation, new AsyncCallback<Boolean>() { joinService.registerUser(myVRE.getinfraScope(), myVRE.getId(), isInvitation, new AsyncCallback<Boolean>() {
@Override @Override

View File

@ -6,11 +6,13 @@
keyboard="true" animation="true"> keyboard="true" animation="true">
<b:HelpBlock ui:field="helpBlock"></b:HelpBlock> <b:HelpBlock ui:field="helpBlock"></b:HelpBlock>
<b:Icon type="ROTATE_RIGHT" size="FOUR_TIMES" spin="true" ui:field="loading" visible="false"/>
<b:HelpBlock> <b:HelpBlock>
By entering this VRE you agree to the terms indicated in the 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> <a href="/web/guest/terms-of-use" target="_blank">Terms of Use</a>
of this gateway. of this gateway.
</b:HelpBlock> </b:HelpBlock>
<b:ModalFooter> <b:ModalFooter>
<b:Button type="PRIMARY" ui:field="confirmRequest">Confirm Request</b:Button> <b:Button type="PRIMARY" ui:field="confirmRequest">Confirm Request</b:Button>
<b:Button type="DEFAULT" ui:field="close">Close</b:Button> <b:Button type="DEFAULT" ui:field="close">Close</b:Button>

View File

@ -51,8 +51,7 @@ public class RequestMembershipDialog extends Composite {
} }
@UiHandler("confirmRequest") @UiHandler("confirmRequest")
void confirm(ClickEvent e) { void confirm(ClickEvent e) {
String text = optionalText.getText() == null || optionalText.getText().equals("") ? " ": optionalText.getText(); String text = optionalText.getText();
joinService.addMembershipRequest(myVRE.getinfraScope(), text, new AsyncCallback<Void>() { joinService.addMembershipRequest(myVRE.getinfraScope(), text, new AsyncCallback<Void>() {
@Override @Override
public void onSuccess(Void result) { public void onSuccess(Void result) {

View File

@ -2,6 +2,7 @@ package org.gcube.portlets.user.joinvre.server;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -12,6 +13,7 @@ import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.portal.CustomAttributeKeys; 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.common.portal.PortalContext;
import org.gcube.portal.custom.communitymanager.SiteManagerUtil;
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;
@ -36,10 +38,12 @@ import org.gcube.vomanagement.usermanagement.model.MembershipRequestStatus;
import org.gcube.vomanagement.usermanagement.model.VirtualGroup; import org.gcube.vomanagement.usermanagement.model.VirtualGroup;
import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.management.PortalManager;
import com.liferay.portal.model.Group; import com.liferay.portal.model.Group;
import com.liferay.portal.model.VirtualHost; import com.liferay.portal.model.VirtualHost;
import com.liferay.portal.service.LayoutSetLocalServiceUtil; import com.liferay.portal.service.LayoutSetLocalServiceUtil;
@ -370,6 +374,8 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
@Override @Override
public void addMembershipRequest(String scope, String optionalMessage) { public void addMembershipRequest(String scope, String optionalMessage) {
String username = getASLSession().getUsername(); String username = getASLSession().getUsername();
if (optionalMessage == null || optionalMessage.compareTo("") == 0)
optionalMessage = "none";
try { try {
LoginServiceUtil.addMembershipRequest(username, scope, optionalMessage, getPortalUrl(), PortalContext.getConfiguration().getGatewayName()); LoginServiceUtil.addMembershipRequest(username, scope, optionalMessage, getPortalUrl(), PortalContext.getConfiguration().getGatewayName());
} catch (Exception e) { } catch (Exception e) {
@ -382,15 +388,26 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
/** /**
* the user to the VRE, plus send notifications to the vre manages of the vre * the user to the VRE, plus send notifications to the vre manages of the vre
* in order to register a user i had to create a fake membership request because assigning a user to a group would have required
* the user to logout and login otherwise
*/ */
@Override @Override
public boolean registerUser(String scope, long groupId, boolean isInvitation) { public boolean registerUser(String scope, long groupId, boolean isInvitation) {
UserManager userM = new LiferayUserManager(); UserManager um = new LiferayUserManager();
try { try {
ASLSession session = getASLSession(); ASLSession session = getASLSession();
String username = session.getUsername(); String username = session.getUsername();
//add the user to the VRE
userM.assignUserToGroup(groupId, userM.getUserId(username)); _log.debug("registerUser " +username + " to "+ scope);
GCubeUser currUser = um.getUserByUsername(username);
GroupManager gm = new LiferayGroupManager();
um.requestMembership(currUser.getUserId(), gm.getGroupIdFromInfrastructureScope(scope), "Automatic Request at " + new Date());
_log.info("fakeRequest sent");
String replierUsername = LiferayUserManager.getAdmin().getScreenName();
_log.trace("Sleep 1 second ...");
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(); String gatewayName = PortalContext.getConfiguration().getGatewayName();
if (isInvitation) { if (isInvitation) {
initStore(); initStore();
@ -402,7 +419,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
} }
} }
else { else {
//LoginServiceUtil.notifyUserSelfRegistration(username, scope, getPortalBasicUrl(), gatewayName); LoginServiceUtil.notifyUserSelfRegistration(username, scope, getPortalBasicUrl(), gatewayName);
_log.info("notifyUserSelfRegistration sent"); _log.info("notifyUserSelfRegistration sent");
} }
} }
@ -410,6 +427,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
return true; return true;
} }