From 3b30e72ee23f39efba468a2ef1b1f37a7057a74e Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Wed, 13 Apr 2016 16:00:19 +0000 Subject: [PATCH] added other methods for managing teams git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vo-management/usermanagement-core@128064 82a268e6-3cf1-43bd-a215-b396298e98cf --- .settings/org.eclipse.wst.common.component | 2 - .../usermanagement/RoleManager.java | 115 ++++++++++++------ .../usermanagement/UserManager.java | 10 ++ .../impl/LiferayRoleManager.java | 47 +++++++ .../impl/LiferayUserManager.java | 24 ++++ 5 files changed, 157 insertions(+), 41 deletions(-) diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 4103a61..2ff2051 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,8 +1,6 @@ - - diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/RoleManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/RoleManager.java index 3c953fd..f4d0256 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/RoleManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/RoleManager.java @@ -60,32 +60,6 @@ public interface RoleManager { * @throws UserManagementSystemException */ boolean createRole(String roleName, String roleDescription) throws UserManagementSystemException; - /** - * The notion of a Team is somewhat similar to a Role but a Role is a portal wide entity, (Role exists in any Site) - * while a Team is restricted to a particular Site. - * - * @param groupId the site group id where the team exists - * @param teamName the name you want to assign to this team - * @param teamDescription - * @return the GCubeTeam if the team is created succesfully, null otherwise - * @throws UserManagementSystemException - */ - GCubeTeam createTeam(long groupId, String teamName, String teamDescription) throws GroupRetrievalFault, TeamRetrievalFault, UserManagementSystemException; - /** - * @param groupId the site group id where the team exists - * @param teamId the LR team Id - * @return the team instance that was removed - * @throws UserManagementSystemException - * @throws RoleRetrievalFault - */ - GCubeTeam deleteTeam(long teamId) throws UserManagementSystemException, TeamRetrievalFault ; - /** - * - * @param groupId the LR GroupId of the Site - * @return true if the teams are deleted succesfully, false otherwise - * @throws UserManagementSystemException - */ - boolean deleteTeams(long groupId) throws UserManagementSystemException; /** * * @param roleId @@ -128,14 +102,7 @@ public interface RoleManager { * @throws RoleRetrievalFault */ GCubeRole getRole(long roleId) throws UserManagementSystemException, RoleRetrievalFault; - /** - * - * @param teamId - * @return the GCubeTeam istance - * @throws UserManagementSystemException - * @throws RoleRetrievalFault - */ - GCubeTeam getTeam(long teamId) throws UserManagementSystemException, TeamRetrievalFault; + /** * @param roleName * @param groupId the LR groupId @@ -163,10 +130,6 @@ public interface RoleManager { * @return a list of {@link GcubeRole} independent from the roleType */ List listAllRoles(); - /** - * @return a list of {@link GCubeTeam} belonging to a give group - */ - List listTeamsByGroup(long groupId); /** * @return a list of {@link GcubeRole} of type Site Role (Type=2) */ @@ -179,6 +142,76 @@ public interface RoleManager { * @throws UserRetrievalFault */ List listRolesByUserAndGroup(long userId, long groupId) throws GroupRetrievalFault,UserRetrievalFault; + + + /******************************* + * + * TEAM MANAGEMENTS PART + * + * The notion of a Team is somewhat similar to a Role but a Role is a portal wide entity, (Role exists in any Site) + * while a Team is restricted to a particular Site. + * + * */ + + + /** + * @param groupId the site group id where the team exists + * @param teamName the name you want to assign to this team + * @param teamDescription + * @return the GCubeTeam if the team is created succesfully, null otherwise + * @throws UserManagementSystemException + */ + GCubeTeam createTeam(long groupId, String teamName, String teamDescription) throws GroupRetrievalFault, TeamRetrievalFault, UserManagementSystemException; + /** + * + * @param groupId + * @param teamName + * @return + * @throws GroupRetrievalFault + * @throws TeamRetrievalFault + */ + GCubeTeam getTeam(long groupId, String teamName) throws GroupRetrievalFault, TeamRetrievalFault; + /** + * + * @param teamId + * @return the GCubeTeam istance + * @throws UserManagementSystemException + * @throws RoleRetrievalFault + */ + GCubeTeam getTeam(long teamId) throws UserManagementSystemException, TeamRetrievalFault; + /** + * @param groupId the site group id where the team exists + * @param teamId the LR team Id + * @return the team instance that was removed + * @throws UserManagementSystemException + * @throws RoleRetrievalFault + */ + GCubeTeam deleteTeam(long teamId) throws UserManagementSystemException, TeamRetrievalFault ; + /** + * + * @param groupId the LR GroupId of the Site + * @return true if the teams are deleted succesfully, false otherwise + * @throws UserManagementSystemException + */ + boolean deleteTeams(long groupId) throws UserManagementSystemException; + /** + * delete a user from a list of teams + * @param userId + * @param teamIds + * @return + * @throws UserRetrievalFault + * @throws TeamRetrievalFault + */ + boolean deleteUserTeams(long userId, long[] teamIds); + /** + * delete a user from a list of teams + * @param userId + * @param teams + * @return + * @throws UserRetrievalFault + * @throws TeamRetrievalFault + */ + boolean deleteUserTeams(long userId, List teams); /** * @param roleId * @param roleName @@ -193,5 +226,9 @@ public interface RoleManager { * @return * @throws TeamRetrievalFault if a system exception occurred or a team does not exists */ - boolean setUserTeams(long userId, long[] teamIds) throws TeamRetrievalFault; + boolean setUserTeams(long userId, long[] teamIds) throws TeamRetrievalFault; + /** + * @return a list of {@link GCubeTeam} belonging to a give group + */ + List listTeamsByGroup(long groupId); } diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java index a650d60..a59c945 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java @@ -5,6 +5,7 @@ import java.util.Map; import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.RoleRetrievalFault; +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; @@ -221,6 +222,15 @@ public interface UserManager { * @throws UserRetrievalFault */ List listUsersByGroupAndRole(long groupId, long roleId) throws UserManagementSystemException, RoleRetrievalFault, GroupRetrievalFault, UserRetrievalFault; + /** + * + * @parmam teamId the LR teamId + * @return the list of {@link GCubeUser} having teamId that matches + * @throws TeamRetrievalFault + * @throws UserManagementSystemException + * @throws UserRetrievalFault + */ + List listUsersByTeam(long teamId) throws UserManagementSystemException, TeamRetrievalFault, UserRetrievalFault; /** * this method assigns the user to the Group and perform other necessary actions (such as adding him to the HL Folder) * @param groupId LR groupId diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayRoleManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayRoleManager.java index d451530..09a1703 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayRoleManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayRoleManager.java @@ -433,4 +433,51 @@ public class LiferayRoleManager implements RoleManager { } return true; } + /** + * {@inheritDoc} + */ + @Override + public boolean deleteUserTeams(long userId, long[] teamIds) { + try { + TeamLocalServiceUtil.deleteUserTeams(userId, teamIds); + } catch (SystemException e) { + e.printStackTrace(); + return false; + } + return true; + } + /** + * {@inheritDoc} + */ + @Override + public boolean deleteUserTeams(long userId, List teams) { + long[] teamIds = new long[teams.size()]; + int i = 0; + for (GCubeTeam r : teams) { + teamIds[i] = r.getTeamId(); + i++; + } + try { + TeamLocalServiceUtil.deleteUserTeams(userId, teamIds); + } catch (SystemException e) { + e.printStackTrace(); + return false; + } + return true; + } + /** + * {@inheritDoc} + */ + @Override + public GCubeTeam getTeam(long groupId, String teamName) throws GroupRetrievalFault, TeamRetrievalFault { + GCubeTeam toReturn = null; + try { + toReturn = mapLRTeam(TeamLocalServiceUtil.getTeam(groupId, teamName)); + } catch (PortalException e) { + throw new TeamRetrievalFault("The teamId or groupdid does not exists", e); + } catch (SystemException e) { + e.printStackTrace(); + } + return toReturn; + } } 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 6a313fa..5041a72 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayUserManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayUserManager.java @@ -10,6 +10,7 @@ import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.UserManager; import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.RoleRetrievalFault; +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; @@ -31,6 +32,7 @@ import com.liferay.portal.model.Group; import com.liferay.portal.model.MembershipRequest; import com.liferay.portal.model.Role; import com.liferay.portal.model.RoleConstants; +import com.liferay.portal.model.Team; import com.liferay.portal.model.User; import com.liferay.portal.security.auth.PrincipalThreadLocal; import com.liferay.portal.security.permission.PermissionChecker; @@ -42,6 +44,7 @@ import com.liferay.portal.service.MembershipRequestLocalServiceUtil; import com.liferay.portal.service.RoleLocalServiceUtil; import com.liferay.portal.service.RoleServiceUtil; import com.liferay.portal.service.ServiceContext; +import com.liferay.portal.service.TeamLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.util.PortalUtil; import com.liferay.portal.webserver.WebServerServletTokenUtil; @@ -523,6 +526,27 @@ public class LiferayUserManager implements UserManager { } return toReturn; } + /** + * {@inheritDoc} + */ + @Override + public List listUsersByTeam(long teamId) throws UserManagementSystemException, TeamRetrievalFault, UserRetrievalFault { + List toReturn = new ArrayList(); + Team askedTeam = null; + try { + askedTeam = TeamLocalServiceUtil.getTeam(teamId); + _log.debug("Asked for users of team: "+askedTeam.getName()); + List users = UserLocalServiceUtil.getTeamUsers(teamId); + for (User user : users) { + toReturn.add(mapLRUser(user)); + } + } catch (PortalException e) { + throw new TeamRetrievalFault("Team not existing (I think you better check) teamId="+teamId, e); + } catch (SystemException e) { + e.printStackTrace(); + } + return toReturn; + } /* * END LISTING ENTITIES */