From 1be03d5f669fadf37b0b13e2a74f8e179b2cd9dd Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 17 Nov 2016 16:59:46 +0000 Subject: [PATCH] Implemented Feature #4877 remove VRE association to single Category constraint git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/join-vre@134338 82a268e6-3cf1-43bd-a215-b396298e98cf --- distro/changelog.xml | 4 + .../user/joinvre/server/JoinServiceImpl.java | 103 +++++------------- 2 files changed, 34 insertions(+), 73 deletions(-) diff --git a/distro/changelog.xml b/distro/changelog.xml index 5496609..8bb1cf2 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,4 +1,8 @@ + + Removed ASL Session + Implemented Feature #4877 remove VRE association to single Category constraint + Added support for invite-only closed groups 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 cadc722..78c9284 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 @@ -35,6 +35,7 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.gcube.vomanagement.usermanagement.model.GroupMembershipType; import org.gcube.vomanagement.usermanagement.model.MembershipRequestStatus; import org.gcube.vomanagement.usermanagement.model.VirtualGroup; +import org.gcube.vomanagement.usermanagement.util.ManagementUtils; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.liferay.portal.kernel.cache.CacheRegistryUtil; @@ -113,13 +114,12 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService * @throws PortalException */ public LinkedHashMap> getPortalSitesMappedToVRE() throws Exception { - - GroupManager gm = new LiferayGroupManager(); LinkedHashMap> toReturn = new LinkedHashMap>(); long currentSiteGroupId = getSiteFromServletRequest(getThreadLocalRequest()).getGroupId(); - List currentSiteVGroups = getVirtualGroups(currentSiteGroupId); + List currentSiteVGroups = gm.getVirtualGroups(currentSiteGroupId); + for (VirtualGroup vg : currentSiteVGroups) { ArrayList toCreate = new ArrayList(); VRECategory cat = new VRECategory(1L, vg.getName(), vg.getDescription()); @@ -144,36 +144,34 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService //for each root sub organizations (VO) for (GCubeGroup vOrg : rootGroupVO.getChildren()) { - for (GCubeGroup vreOrganization : vOrg.getChildren()) { - long vreID = vreOrganization.getGroupId(); - String vreName = vreOrganization.getGroupName(); - String vreDescription = vreOrganization.getDescription(); + for (GCubeGroup vreSite : vOrg.getChildren()) { + long vreID = vreSite.getGroupId(); + String vreName = vreSite.getGroupName(); + String vreDescription = vreSite.getDescription(); - long logoId = vreOrganization.getLogoId(); + long logoId = vreSite.getLogoId(); String vreLogoURL = gm.getGroupLogoURL(logoId); - String groupName = gm.getInfrastructureScope(vreOrganization.getGroupId()); - String friendlyURL = GCubePortalConstants.PREFIX_GROUP_URL+vreOrganization.getFriendlyURL(); + String groupName = gm.getInfrastructureScope(vreSite.getGroupId()); + String friendlyURL = GCubePortalConstants.PREFIX_GROUP_URL+vreSite.getFriendlyURL(); - String catName = gm.getVirtualGroup(vreID).getName(); - - VRECategory toLookFor = null; - for (VRECategory vre : toReturn.keySet()) { - if (vre.getName().compareTo(catName)==0) - toLookFor = vre; - } - if (toLookFor != null) { - ArrayList toUpdate = toReturn.get(toLookFor); - UserBelonging belongs = UserBelonging.NOT_BELONGING; - VRE toAdd = new VRE(vreID,vreName, vreDescription, vreLogoURL, groupName, friendlyURL, belongs, getVREMembershipType(vreOrganization.getMembershipType())); - if (currUser != null) { - //check if the user belongs to it - if (currUserGroups.contains(vreOrganization)) { - toAdd.setUserBelonging(UserBelonging.BELONGING); + List vreGroups = gm.getVirtualGroups(vreID); + for (VirtualGroup vreGroup : vreGroups) { + for (VRECategory vre : toReturn.keySet()) { + if (vre.getName().compareTo(vreGroup.getName())==0) { + ArrayList toUpdate = toReturn.get(vre); + UserBelonging belongs = UserBelonging.NOT_BELONGING; + VRE toAdd = new VRE(vreID,vreName, vreDescription, vreLogoURL, groupName, friendlyURL, belongs, getVREMembershipType(vreSite.getMembershipType())); + if (currUser != null) { + //check if the user belongs to it + if (currUserGroups.contains(vreSite)) { + toAdd.setUserBelonging(UserBelonging.BELONGING); + } + else if (checkPending(currUser.getUsername(), vreSite.getGroupId())) + toAdd.setUserBelonging(UserBelonging.PENDING); + } + toUpdate.add(toAdd); } - else if (checkPending(currUser.getUsername(), vreOrganization.getGroupId())) - toAdd.setUserBelonging(UserBelonging.PENDING); - } - toUpdate.add(toAdd); + } } } } @@ -400,11 +398,11 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService @Override public String isExistingInvite(long groupId) { - + _log.debug("initiating Store"); initStore(); _log.debug("initStore OK"); - + String email = PortalContext.getConfiguration().getCurrentUser(getThreadLocalRequest()).getEmail(); String infraScope = null; try { @@ -433,48 +431,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService return null; } - /** - * read the list of virtual groups the current site (i-marine, services etc. ) should show up - * @param actualGroupId - * @return he list of virtual groups the current site (i-marine, services etc. ) should show up - * @throws GroupRetrievalFault - * @throws VirtualGroupNotExistingException - */ - private List getVirtualGroups(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException { - List toReturn = new ArrayList(); - try { - long userId = LiferayUserManager.getAdmin().getUserId(); - PrincipalThreadLocal.setName(userId); - PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(userId)); - PermissionThreadLocal.setPermissionChecker(permissionChecker); - Group site = GroupLocalServiceUtil.getGroup(actualGroupId); - _log.debug("Set Thread Permission done, getVirtual Group of " + site.getName()); - if (site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()) == null || site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()).equals("")) { - String warningMessage = String.format("Attribute %s not initialized.", CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()); - _log.warn(warningMessage); - throw new VirtualGroupNotExistingException(warningMessage); - } else { - String[] values = (String[]) site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()); - VirtualGroup toAdd = new VirtualGroup(); - if (values != null && values.length > 0) { - for (int i = 0; i < values.length; i++) { - toAdd = new VirtualGroup(); - String[] splits = values[i].split("\\|"); - toAdd.setName(splits[0]); - toAdd.setDescription(splits[1]); - toReturn.add(toAdd); - _log.debug("VirtualGroup selected found for " + site.getName() + " -> " + toAdd.getName()); - } - } else { - toAdd.setName("NoVirtualGroupAssigned"); - toAdd.setDescription("NoVirtualGroupDescription"); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return toReturn; - } + /** * * @param request