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;