USER subscriptions complete

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/join-vre@126063 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-03-22 16:33:01 +00:00
parent 04d15cedce
commit c82d04328d
5 changed files with 56 additions and 38 deletions

View File

@ -4,7 +4,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.gcube.portlets.user.joinvre.client.responsive.ResponsivePanel;
import org.gcube.portlets.user.joinvre.shared.UserBelonging;
import org.gcube.portlets.user.joinvre.shared.VRE;
import com.google.gwt.core.client.EntryPoint;
@ -67,7 +66,6 @@ public class JoinVRE implements EntryPoint {
case PENDING:
logger.log(Level.INFO, "User is Pending");
rp = displayVREs();
rp.displayPending();
break;
default: //Not belonging
logger.log(Level.INFO, "User is NOT Belonging");

View File

@ -13,7 +13,6 @@ import org.gcube.portlets.user.joinvre.shared.VRECategory;
import com.github.gwtbootstrap.client.ui.PageHeader;
import com.github.gwtbootstrap.client.ui.Thumbnails;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
@ -73,10 +72,6 @@ public class ResponsivePanel extends Composite {
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 displayPending() {
Window.alert("Pending");
}
public void requestMembership(VRE vre) {
RequestMembershipDialog modal = new RequestMembershipDialog(vre);
modal.show();

View File

@ -3,6 +3,7 @@ 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.client.JoinVRE;
import org.gcube.portlets.user.joinvre.shared.UserBelonging;
import org.gcube.portlets.user.joinvre.shared.VRE;
import com.github.gwtbootstrap.client.ui.Button;
@ -45,9 +46,17 @@ public class VreThumbnail extends Composite {
vreName.setText(name);
if (vre.isUponRequest()) {
joinButton.setType(ButtonType.DEFAULT);
joinButton.setText("Access");
joinButton.setText("Request Access");
if (vre.getUserBelonging() == UserBelonging.PENDING) {
joinButton.setText("Waiting approval");
joinButton.setType(ButtonType.WARNING);
joinButton.setEnabled(false);
}
if (vre.getUserBelonging() == UserBelonging.BELONGING) {
joinButton.setType(ButtonType.SUCCESS);
joinButton.setText("Access Granted");
}
} else {
joinButton.setType(ButtonType.PRIMARY);
joinButton.setText("Enter this VRE");
}
vreImage.setUrl(vre.getImageURL());
@ -55,27 +64,29 @@ public class VreThumbnail extends Composite {
@UiHandler("joinButton")
void handleClick(ClickEvent e) {
if (myVre.isExternal()) {
RedirectPanel modal = new RedirectPanel(myVre);
modal.show();
}
else {
joinService.joinVRE(myVre.getId(), new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
String errorDescription = "Error while trying to join to"
+ myVre.getName() + " VRE. Please Try again later. "
+ "If the problem persist please contact us at www.gcube-system.org";
Window.alert(errorDescription);
}
if (myVre.getUserBelonging() != UserBelonging.PENDING) {
if (myVre.isExternal()) {
RedirectPanel modal = new RedirectPanel(myVre);
modal.show();
}
else {
joinService.joinVRE(myVre.getId(), new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
String errorDescription = "Error while trying to join to"
+ myVre.getName() + " VRE. Please Try again later. "
+ "If the problem persist please contact us at www.gcube-system.org";
Window.alert(errorDescription);
}
@Override
public void onSuccess(String currentGroupName) {
Location.assign("/group/" +currentGroupName +"/explore?"+JoinVRE.GET_OID_PARAMETER+"="+myVre.getId());
//RequestMembershipDialog modal = new RequestMembershipDialog(currentGroupName);
//modal.show();
}
});
@Override
public void onSuccess(String currentGroupName) {
Location.assign("/group/" +currentGroupName +"/explore?"+JoinVRE.GET_OID_PARAMETER+"="+myVre.getId());
//RequestMembershipDialog modal = new RequestMembershipDialog(currentGroupName);
//modal.show();
}
});
}
}
}

View File

@ -10,7 +10,6 @@ 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.communitymanager.impl.GCubeSiteManagerImpl;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.user.joinvre.client.JoinService;
import org.gcube.portlets.user.joinvre.shared.UserBelonging;
@ -48,6 +47,7 @@ import com.liferay.portal.util.PortalUtil;
@SuppressWarnings("serial")
public class JoinServiceImpl extends RemoteServiceServlet implements JoinService {
private static Log _log = LogFactoryUtil.getLog(JoinServiceImpl.class);
private static final String TEST_USER = "test.user";
/**
* the current ASLSession
* @return the session
@ -68,7 +68,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
* @return .
*/
public String getDevelopmentUser() {
String user = "test.user";
String user = TEST_USER;
return user;
}
@ -148,6 +148,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
try {
GroupManager gm = new LiferayGroupManager();
toReturn.setUponRequest(group.isRequestBasedGroup());
System.out.println(group.getGroupName() + " getVRECustomAttr group.isRequestBasedGroup?" + group.isRequestBasedGroup());
Boolean attributeValue = (Boolean) gm.readCustomAttr(group.getGroupId(), CustomAttributeKeys.IS_EXTERNAL.getKeyName());
toReturn.setExternal(attributeValue);
if (attributeValue) { //we read the custom attr URL if and only if the VRE is External, in the other case is useless
@ -169,6 +170,8 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
* @throws PortalException
*/
public LinkedHashMap<VRECategory, ArrayList<VRE>> getPortalSitesMappedToVRE() throws Exception {
ASLSession session = getASLSession();
GroupManager gm = new LiferayGroupManager();
LinkedHashMap<VRECategory, ArrayList<VRE>> toReturn = new LinkedHashMap<VRECategory, ArrayList<VRE>>();
//before iterating the actual groups create the virtualGroups in the correct order
@ -217,7 +220,18 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
}
if (toLookFor != null) {
ArrayList<VRE> toUpdate = toReturn.get(toLookFor);
toUpdate.add(new VRE(vreID,vreName, vreDescription, vreLogoURL, groupName, friendlyURL, UserBelonging.NOT_BELONGING, requireAccessGrant, isExternal, urlIfAny));
UserBelonging belongs = UserBelonging.NOT_BELONGING;
VRE toAdd = new VRE(vreID,vreName, vreDescription, vreLogoURL, groupName, friendlyURL, belongs, requireAccessGrant, isExternal, urlIfAny);
if (session.getUsername().compareTo(TEST_USER) != 0) {
GCubeUser currUser = new LiferayUserManager().getUserByUsername(session.getUsername());
//check if the user belongs to it
if (gm.listGroupsByUser(currUser.getUserId()).contains(vreOrganization)) {
toAdd.setUserBelonging(UserBelonging.BELONGING);
}
else if (checkPending(currUser.getUsername(), vreOrganization.getGroupId()))
toAdd.setUserBelonging(UserBelonging.PENDING);
}
toUpdate.add(toAdd);
}
}
}
@ -312,7 +326,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
boolean requireAccessGrant = attrs.isUponRequest();
boolean isExternal = attrs.isExternal();
String urlIfAny = attrs.getUrlIfAny();
GCubeUser currUser = um.getUserByUsername(session.getUsername());
//check if the user belongs to it
UserBelonging belongEnum = UserBelonging.NOT_BELONGING;
@ -338,10 +352,10 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
*/
private static boolean checkPending(String screenName, long groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault {
UserManager um = new LiferayUserManager();
List<GCubeMembershipRequest> requests = um.listMembershipRequestsByGroup(groupId);
for (GCubeMembershipRequest r : requests) {
if ( r.getStatus() == MembershipRequestStatus.REQUEST && (r.getRequestingUser().getUsername().compareTo(screenName)==0))
return true;
List<GCubeMembershipRequest> requests = um.listMembershipRequestsByGroup(groupId);
for (GCubeMembershipRequest r : requests) {
if ( r.getStatus() == MembershipRequestStatus.REQUEST && (r.getRequestingUser().getUsername().compareTo(screenName)==0))
return true;
}
return false;
}

View File

@ -13,7 +13,7 @@
<mime-type>text/html</mime-type>
</supports>
<portlet-info>
<title>Join VRE</title>
<title>Explore Virtual Research Environments</title>
<short-title>JoinVRE Portlet</short-title>
<keywords>JoinVRE Portlet</keywords>
</portlet-info>