From 6a40c1cd8bf9b9173f40ef6a6e3741878d02c84d Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 26 Mar 2020 09:47:04 +0100 Subject: [PATCH] Added getRandomAdmin user method --- .../usermanagement/UserManager.java | 8 ++++ .../impl/LiferayUserManager.java | 45 +++++++++++++++++++ .../impl/ws/LiferayWSUserManager.java | 6 +++ 3 files changed, 59 insertions(+) diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java index a9deb14..c9723e1 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java @@ -363,6 +363,14 @@ public interface UserManager { * @throws UserRetrievalFault */ List listUsersByGroupAndRole(long groupId, long roleId) throws UserManagementSystemException, RoleRetrievalFault, GroupRetrievalFault, UserRetrievalFault; + /** + * + * @param groupId + * @param roleId + * @return the list of userId having group and role that matches + */ + long[] listUserIdsByGroupAndRole(long groupId, long roleId); + /** /** * * @parmam teamId the LR teamId 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 9e04d82..9ced8f5 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayUserManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayUserManager.java @@ -25,6 +25,7 @@ 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; +import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames; import org.gcube.vomanagement.usermanagement.model.MembershipRequestStatus; import org.gcube.vomanagement.usermanagement.util.ManagementUtils; @@ -96,6 +97,31 @@ public class LiferayUserManager implements UserManager { } return null; } + /** + * + * @param contextGroupId + * @param gatewayRole + * @return the User if a user having the role exists in the Site group (Gateway, VO or VRE) + */ + public static User getRandomUserWithRole(long contextGroupId, GatewayRolesNames gatewayRole) { + final long companyId = PortalUtil.getDefaultCompanyId(); + try { + Role theRole = RoleLocalServiceUtil.getRole(companyId, gatewayRole.getRoleName()) ; + if (theRole == null) { + _log.warn("No user has the role with this groupId " + gatewayRole.getRoleName() + ":" + contextGroupId); + return null; + } + List list = UserGroupRoleLocalServiceUtil.getUserGroupRolesByGroupAndRole(contextGroupId, theRole.getRoleId()); + for (UserGroupRole userGroupRole : list) { + User admin = userGroupRole.getUser(); + if (admin.isActive()) + return admin; + } + } catch (final Exception e) { + _log.error("Utils::getInfrastructureManager Exception", e); + } + return null; + } public static Role getRoleById(final long companyId, final String roleStrId) { try { return RoleLocalServiceUtil.getRole(companyId, roleStrId); @@ -770,6 +796,25 @@ public class LiferayUserManager implements UserManager { * {@inheritDoc} */ @Override + public long[] listUserIdsByGroupAndRole(long groupId, long roleId) { + List listTriplet = null; + try { + listTriplet = UserGroupRoleLocalServiceUtil.getUserGroupRolesByGroupAndRole(groupId, roleId); + } catch (SystemException e) { + e.printStackTrace(); + } + long[] toReturn = new long[listTriplet.size()]; + int i = 0; + for (UserGroupRole userGroupRole : listTriplet) { + toReturn[i] = userGroupRole.getUserId(); + i++; + } + return toReturn; + } + /** + * {@inheritDoc} + */ + @Override public List listUsersByTeam(long teamId) throws UserManagementSystemException, TeamRetrievalFault, UserRetrievalFault { List toReturn = new ArrayList(); Team askedTeam = null; diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/ws/LiferayWSUserManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/ws/LiferayWSUserManager.java index 04cfc9b..cef0358 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/ws/LiferayWSUserManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/ws/LiferayWSUserManager.java @@ -820,4 +820,10 @@ public class LiferayWSUserManager implements UserManager{ return 0; } + @Override + public long[] listUserIdsByGroupAndRole(long groupId, long roleId) { + // TODO Auto-generated method stub + return null; + } + }