From 59a3786158ea038390ea0790f56cc5f8f483a9f7 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Fri, 18 Mar 2016 10:51:18 +0000 Subject: [PATCH] added getVirtual group method git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vo-management/usermanagement-core@125710 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../usermanagement/GroupManager.java | 7 ++++++ .../impl/LiferayGroupManager.java | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/GroupManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/GroupManager.java index f2c69f0..d3bbeea 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/GroupManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/GroupManager.java @@ -84,6 +84,13 @@ public interface GroupManager { * @throws GroupRetrievalFault */ GCubeGroup getGroup(long groupId) throws UserManagementSystemException, GroupRetrievalFault; + /** + * Virtual Groups are handled as Custom attributes in Liferay Sites table + * @param groupId the LR groupId + * @return the virtual group name associated to this group + * @throws GroupRetrievalFault + */ + String getVirtualGroupName(long groupId) throws GroupRetrievalFault; /** * * @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 82c0e88..7f18492 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayGroupManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayGroupManager.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.gcube.common.portal.CustomAttributeKeys; import org.gcube.common.portal.PortalContext; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; @@ -109,6 +110,28 @@ public class LiferayGroupManager implements GroupManager { return group; } + public String getVirtualGroupName(long groupId) throws GroupRetrievalFault { + try { + _log.debug("Setting Thread Permission"); + long userId = LiferayUserManager.getAdmin().getUserId(); + PrincipalThreadLocal.setName(userId); + PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(userId)); + PermissionThreadLocal.setPermissionChecker(permissionChecker); + Group site = GroupLocalServiceUtil.getGroup(groupId); + if (site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()) == null || site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()).equals("")) { + _log.warn(String.format("Attribute %s not initialized.", CustomAttributeKeys.VIRTUAL_GROUP.getKeyName())); + return null; + } else { + String[] values = (String[]) site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()); + if (values != null) + return values[0]; + else return ""; + } + } catch (Exception e) { + e.printStackTrace(); + return "Exception "; + } + } @Override public GCubeGroup createRootVO(String rootVOName, String description) throws UserManagementNameException, UserManagementSystemException, UserRetrievalFault, GroupRetrievalFault, UserManagementPortalException { Group group = null;