From 7465bb2c393e3823c31b2e9c9bedfa464b49c252 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 17 Nov 2016 17:24:24 +0000 Subject: [PATCH] Implemented support for Feature #4877 remove VRE association to single Category constraint git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vo-management/usermanagement-core@134344 82a268e6-3cf1-43bd-a215-b396298e98cf --- distro/changelog.xml | 3 + pom.xml | 2 +- .../usermanagement/GroupManager.java | 2 +- .../impl/LiferayGroupManager.java | 58 +++++++++++++++---- .../usermanagement/util/ManagementUtils.java | 55 +----------------- 5 files changed, 53 insertions(+), 67 deletions(-) diff --git a/distro/changelog.xml b/distro/changelog.xml index a87f6e2..af8ecae 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,4 +1,7 @@ + + Added method to read VirtualGroups associated to sites + Added efficient method to retireve VRE logo URLs diff --git a/pom.xml b/pom.xml index b0e052e..a853bcc 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.dvos usermanagement-core - 2.1.0-SNAPSHOT + 2.2.0-SNAPSHOT jar User Management API diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/GroupManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/GroupManager.java index 3b6118d..2c7eec6 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/GroupManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/GroupManager.java @@ -100,7 +100,7 @@ public interface GroupManager { * @return the virtual group name associated to this group * @throws GroupRetrievalFault */ - VirtualGroup getVirtualGroup(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException; + List getVirtualGroups(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException; /* * * @param scope the infrastructure scope e.g. /gcube/devsec diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayGroupManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayGroupManager.java index 9ce309d..c996f24 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayGroupManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayGroupManager.java @@ -51,6 +51,9 @@ import com.liferay.portlet.expando.model.ExpandoBridge; import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil; public class LiferayGroupManager implements GroupManager { + + private static final String DEFAULT_INFRA_NAME = "gcube"; + public static final String INFRASTRUCTURE_NAME = "infrastructure"; /** * logger */ @@ -136,28 +139,32 @@ public class LiferayGroupManager implements GroupManager { * {@inheritDoc} */ @Override - public VirtualGroup getVirtualGroup(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException { - VirtualGroup toReturn = new VirtualGroup(); + public 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) { - String[] splits = values[0].split("\\|"); - toReturn.setName(splits[0]); - toReturn.setDescription(splits[1]); + 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); + } } else { - toReturn.setName("NoVirtualGroupAssigned"); - toReturn.setDescription("NoVirtualGroupDescription"); + toAdd.setName("NoVirtualGroupAssigned"); + toAdd.setDescription("NoVirtualGroupDescription"); } } } catch (Exception e) { @@ -414,7 +421,7 @@ public class LiferayGroupManager implements GroupManager { public Set listGroupsByUserAndSite(long userId, final String serverName) throws UserRetrievalFault, UserManagementSystemException, GroupRetrievalFault, VirtualGroupNotExistingException { Set toReturn = new HashSet<>(); try { - List currSiteVirtualGroups = ManagementUtils.getVirtualGroupsBySiteGroupId(ManagementUtils.getSiteGroupIdFromServletRequest(serverName)); + List currSiteVirtualGroups = getVirtualGroups(ManagementUtils.getSiteGroupIdFromServletRequest(serverName)); for (GCubeGroup userGroup : listGroupsByUser(userId)) { if (isVRE(userGroup.getGroupId())) { for (VirtualGroup vg : currSiteVirtualGroups) @@ -609,8 +616,37 @@ public class LiferayGroupManager implements GroupManager { e.printStackTrace(); } } - private static final String DEFAULT_INFRA_NAME = "gcube"; - public static final String INFRASTRUCTURE_NAME = "infrastructure"; + + private VirtualGroup getVirtualGroup(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException { + VirtualGroup toReturn = new VirtualGroup(); + 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()); + if (values != null && values.length > 0) { + String[] splits = values[0].split("\\|"); + toReturn.setName(splits[0]); + toReturn.setDescription(splits[1]); + } else { + toReturn.setName("NoVirtualGroupAssigned"); + toReturn.setDescription("NoVirtualGroupDescription"); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return toReturn; + } + /** * read the infrastructure name from a property file and returns it */ diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/util/ManagementUtils.java b/src/main/java/org/gcube/vomanagement/usermanagement/util/ManagementUtils.java index 7b03681..1d9678f 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/util/ManagementUtils.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/util/ManagementUtils.java @@ -1,13 +1,7 @@ package org.gcube.vomanagement.usermanagement.util; -import java.util.ArrayList; import java.util.List; -import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; -import org.gcube.vomanagement.usermanagement.exception.VirtualGroupNotExistingException; -import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; -import org.gcube.vomanagement.usermanagement.model.CustomAttributeKeys; -import org.gcube.vomanagement.usermanagement.model.VirtualGroup; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,14 +12,8 @@ import com.liferay.portal.kernel.util.PropsUtil; import com.liferay.portal.model.Company; import com.liferay.portal.model.Group; import com.liferay.portal.model.VirtualHost; -import com.liferay.portal.security.auth.PrincipalThreadLocal; -import com.liferay.portal.security.permission.PermissionChecker; -import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil; -import com.liferay.portal.security.permission.PermissionThreadLocal; import com.liferay.portal.service.CompanyLocalServiceUtil; -import com.liferay.portal.service.GroupLocalServiceUtil; import com.liferay.portal.service.LayoutSetLocalServiceUtil; -import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.VirtualHostLocalServiceUtil; public class ManagementUtils { @@ -81,46 +69,5 @@ public class ManagementUtils { _log.warn("serverName is " + serverName + " but i could not find any virtualHost associated to it"); return -1; } - /** - * 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 - */ - public static List getVirtualGroupsBySiteGroupId(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; - } + }