From b072b22511a1b8721a21fb48d37a2388b3050fcb Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 29 Dec 2016 16:05:36 +0000 Subject: [PATCH] added method to retrieve user contacts depending on the current group git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vo-management/usermanagement-core@141429 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../usermanagement/GroupManager.java | 9 ++++++ .../usermanagement/UserManager.java | 11 +++++++ .../impl/LiferayGroupManager.java | 14 ++++++++- .../impl/LiferayUserManager.java | 29 +++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/GroupManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/GroupManager.java index 2c7eec6..cda1813 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/GroupManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/GroupManager.java @@ -163,6 +163,15 @@ public interface GroupManager { * @throws GroupRetrievalFault */ Set listGroupsByUserAndSite(long userId, final String serverName) throws UserRetrievalFault, UserManagementSystemException, GroupRetrievalFault, VirtualGroupNotExistingException; + /** + * @param userId the LR userId + * @param siteGroupId the LR groupId from which is sending the request + * @return a set of VREs where the user is registered as @see {@link GCubeGroup} on the current Site (e.g i-marine.d4science.org) + * @throws UserRetrievalFault + * @throws UserManagementSystemException + * @throws GroupRetrievalFault + */ + Set listGroupsByUserAndSiteGroupId(long userId, long siteGroupId) throws UserRetrievalFault, UserManagementSystemException, GroupRetrievalFault, VirtualGroupNotExistingException; /** * * @param userId the LR userId diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java index 011f815..315aec0 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java @@ -3,6 +3,7 @@ package org.gcube.vomanagement.usermanagement; import java.io.Serializable; import java.util.List; import java.util.Map; +import java.util.Set; import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.RoleRetrievalFault; @@ -226,6 +227,16 @@ public interface UserManager { * @throws UserRetrievalFault */ List listUsersByGroupName(String name) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; + /** + * @param scopeGroupId the liferay groupid number of the current Site + * @param userId the LR userid for which you need to fetch the contacts + * @return a set containing all portal active users that the user can contact/see (depending on the scopeGroupId he/she can see the users a VRE, or the users of all the VREs he/she is subscribed) + * + * @throws UserManagementSystemException . + * @throws GroupRetrievalFault . + * @throws UserRetrievalFault . + */ + Set getUserContactsByGroup(long userId, long scopeGroupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; /** * * @param groupId the LR groupId 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 405bb9a..78d1207 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayGroupManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayGroupManager.java @@ -419,9 +419,21 @@ public class LiferayGroupManager implements GroupManager { */ @Override public Set listGroupsByUserAndSite(long userId, final String serverName) throws UserRetrievalFault, UserManagementSystemException, GroupRetrievalFault, VirtualGroupNotExistingException { + try { + return listGroupsByUserAndSiteGroupId(userId, ManagementUtils.getSiteGroupIdFromServletRequest(serverName)); + } catch (SystemException | PortalException e) { + e.printStackTrace(); + } + return null; + } + /** + * {@inheritDoc} + */ + @Override + public Set listGroupsByUserAndSiteGroupId(long userId, long siteGroupId) throws UserRetrievalFault, UserManagementSystemException, GroupRetrievalFault, VirtualGroupNotExistingException { Set toReturn = new HashSet<>(); try { - List currSiteVirtualGroups = getVirtualGroups(ManagementUtils.getSiteGroupIdFromServletRequest(serverName)); + List currSiteVirtualGroups = getVirtualGroups(siteGroupId); for (GCubeGroup userGroup : listGroupsByUser(userId)) { if (isVRE(userGroup.getGroupId())) { diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayUserManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayUserManager.java index 26559ca..ed94664 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayUserManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayUserManager.java @@ -3,10 +3,12 @@ package org.gcube.vomanagement.usermanagement.impl; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.UserManager; @@ -16,8 +18,10 @@ import org.gcube.vomanagement.usermanagement.exception.TeamRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.VirtualGroupNotExistingException; import org.gcube.vomanagement.usermanagement.model.CustomAttributeKeys; import org.gcube.vomanagement.usermanagement.model.Email; +import org.gcube.vomanagement.usermanagement.model.GCubeGroup; import org.gcube.vomanagement.usermanagement.model.GCubeMembershipRequest; import org.gcube.vomanagement.usermanagement.model.GCubeRole; import org.gcube.vomanagement.usermanagement.model.GCubeUser; @@ -707,10 +711,35 @@ public class LiferayUserManager implements UserManager { } return toReturn; } + /** + * {@inheritDoc} + */ + @Override + public Set getUserContactsByGroup(long userId, long scopeGroupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault { + Set users = new HashSet<>(); + GroupManager gm = new LiferayGroupManager(); + try { + if (gm.isRootVO(scopeGroupId)) { + Set userGroups = gm.listGroupsByUserAndSiteGroupId(userId, scopeGroupId); + for (GCubeGroup userGroup : userGroups) { + if (gm.isVRE(userGroup.getGroupId())) { + users.addAll(listUsersByGroup(userGroup.getGroupId())); + _log.debug("getUserContactsByGroup added users of group " + userGroup.getGroupId() + " for userid="+userId); + } + } + } else { //is a VRE + users.addAll(listUsersByGroup(scopeGroupId)); + } + } catch (UserManagementSystemException | GroupRetrievalFault | UserRetrievalFault | VirtualGroupNotExistingException e) { + e.printStackTrace(); + } + return users; + } /* * END LISTING ENTITIES */ + /* * MEMBERSHIP REQUESTS