diff --git a/.classpath b/.classpath index cf152f5..a90cbbc 100644 --- a/.classpath +++ b/.classpath @@ -29,9 +29,9 @@ - + - + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 69c31cd..443e085 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,8 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 2ff2051..4103a61 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,6 +1,8 @@ + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml index c78d932..4f92af5 100644 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,5 +1,5 @@ - + diff --git a/pom.xml b/pom.xml index 08d22a5..04aba0c 100644 --- a/pom.xml +++ b/pom.xml @@ -95,8 +95,8 @@ maven-compiler-plugin 3.0 - 1.6 - 1.6 + 1.7 + 1.7 diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/RoleManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/RoleManager.java index 82b4c6a..3c953fd 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/RoleManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/RoleManager.java @@ -5,12 +5,17 @@ import java.util.List; 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.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; import org.gcube.vomanagement.usermanagement.model.GCubeRole; +import org.gcube.vomanagement.usermanagement.model.GCubeTeam; /** - * This interface defines the manager class that manages the roles. + * This interface defines the manager class that manages the Roles and the Teams. + * Groups (Sites) can group a set of user by creating a team. + * 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. * * @author Massimiliano Assante, CNR-ISTI * @@ -55,15 +60,41 @@ 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 + * @return true if the role is deleted succesfully, false otherwise * @throws UserManagementSystemException * @throws RoleRetrievalFault */ boolean deleteRole(long roleId) throws UserManagementSystemException, RoleRetrievalFault ; /** - * * @param userId * @param groupId * @param roleId @@ -75,7 +106,6 @@ public interface RoleManager { */ boolean removeRoleFromUser(long userId, long groupId, long roleId) throws UserManagementSystemException, UserRetrievalFault, GroupRetrievalFault,RoleRetrievalFault; /** - * * @param userId * @param groupIds * @return @@ -84,9 +114,7 @@ public interface RoleManager { * @throws GroupRetrievalFault */ boolean removeAllRolesFromUser(long userId, long... groupIds) throws UserManagementSystemException, UserRetrievalFault, GroupRetrievalFault; - /** - * * @param roleId * @param roleName * @param roleDescription @@ -94,7 +122,6 @@ public interface RoleManager { */ GCubeRole updateRole(long roleId, String roleName, String roleDescription) throws RoleRetrievalFault; /** - * * @param roleId * @return * @throws UserManagementSystemException @@ -103,6 +130,13 @@ public interface RoleManager { 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 * @return an instance of {@link GcubeRole} if the roleName exists, null otherwise @@ -111,8 +145,7 @@ public interface RoleManager { */ GCubeRole getRole(String roleName, long groupId) throws RoleRetrievalFault, GroupRetrievalFault; /** - * - * @param roleName + * * @param roleName * @param groupId the LR groupId * @return the LR RoleId if the roleName exists * @throws RoleRetrievalFault if the roleName does not exist @@ -120,8 +153,7 @@ public interface RoleManager { */ long getRoleId(String roleName, long groupId) throws RoleRetrievalFault, GroupRetrievalFault; /** - * - * @param roleName + * * @param roleName * @return the LR RoleId if the roleName exists * @throws RoleRetrievalFault if the roleName does not exist */ @@ -131,12 +163,15 @@ 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) */ List listAllGroupRoles(); - /** - * + /** * @param groupId * @param userId * @return a list of {@link GcubeRole} of type Site Role (Type=2) @@ -144,5 +179,19 @@ public interface RoleManager { * @throws UserRetrievalFault */ List listRolesByUserAndGroup(long userId, long groupId) throws GroupRetrievalFault,UserRetrievalFault; - + /** + * @param roleId + * @param roleName + * @param roleDescription + * @return + */ + GCubeTeam updateTeam(long teamId, String teamName, String teamDescription) throws TeamRetrievalFault; + /** + * associate or not associate teams to a user + * @param userId + * @param teamIds + * @return + * @throws TeamRetrievalFault if a system exception occurred or a team does not exists + */ + boolean setUserTeams(long userId, long[] teamIds) throws TeamRetrievalFault; } diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/exception/TeamRetrievalFault.java b/src/main/java/org/gcube/vomanagement/usermanagement/exception/TeamRetrievalFault.java new file mode 100644 index 0000000..4550c57 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/exception/TeamRetrievalFault.java @@ -0,0 +1,33 @@ +package org.gcube.vomanagement.usermanagement.exception; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.liferay.portal.kernel.exception.PortalException; +import com.liferay.portal.kernel.exception.SystemException; + + + +@SuppressWarnings("serial") +public class TeamRetrievalFault extends Exception{ + private static final Logger _log = LoggerFactory.getLogger(TeamRetrievalFault.class); + public TeamRetrievalFault(String errorMsg) { + _log.error(errorMsg); + } + /** + * + */ + public TeamRetrievalFault(String errorMsg, SystemException e){ + _log.error(errorMsg + e); + } + + public TeamRetrievalFault(String errorMsg, PortalException e){ + _log.error(errorMsg); + e.printStackTrace(); + } + + public TeamRetrievalFault(String errorMsg, String roleId , PortalException e){ + _log.error(errorMsg + roleId); + e.printStackTrace(); + } +} \ No newline at end of file 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 68fcfa5..d451530 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayRoleManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayRoleManager.java @@ -7,21 +7,26 @@ import java.util.List; import org.gcube.vomanagement.usermanagement.RoleManager; 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.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; import org.gcube.vomanagement.usermanagement.model.GCubeRole; +import org.gcube.vomanagement.usermanagement.model.GCubeTeam; import org.gcube.vomanagement.usermanagement.util.ManagementUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.liferay.counter.service.CounterLocalServiceUtil; +import com.liferay.portal.DuplicateTeamException; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.model.Role; +import com.liferay.portal.model.Team; import com.liferay.portal.model.UserGroupRole; import com.liferay.portal.service.ClassNameLocalServiceUtil; import com.liferay.portal.service.GroupLocalServiceUtil; import com.liferay.portal.service.RoleLocalServiceUtil; +import com.liferay.portal.service.TeamLocalServiceUtil; import com.liferay.portal.service.UserGroupRoleLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.util.PortalUtil; @@ -42,6 +47,15 @@ public class LiferayRoleManager implements RoleManager { else return null; } + + //simple team mapping + protected static GCubeTeam mapLRTeam(Team t) throws PortalException, SystemException { + if (t != null) { + return new GCubeTeam(t.getGroupId(), t.getTeamId(), t.getName(), t.getDescription()); + } + else + return null; + } /** * {@inheritDoc} */ @@ -184,9 +198,7 @@ public class LiferayRoleManager implements RoleManager { RoleLocalServiceUtil.addRole(role); _log.debug("CreateRole " + roleName + " SUCCESS"); return true; - } catch (SystemException e) { - e.printStackTrace(); - } catch (PortalException e) { + } catch (SystemException | PortalException e) { e.printStackTrace(); } } else { @@ -272,9 +284,7 @@ public class LiferayRoleManager implements RoleManager { for (Role role : roles) { toReturn.add(mapLRRole(role)); } - } catch (SystemException e) { - e.printStackTrace(); - } catch (PortalException e) { + } catch (SystemException | PortalException e) { e.printStackTrace(); } return toReturn; @@ -285,15 +295,14 @@ public class LiferayRoleManager implements RoleManager { @Override public List listAllGroupRoles() { List toReturn = new ArrayList(); - try { - List roles = RoleLocalServiceUtil.getRoles(ManagementUtils.getCompany().getCompanyId()); + List roles; + try { + roles = RoleLocalServiceUtil.getRoles(ManagementUtils.getCompany().getCompanyId()); for (Role role : roles) { if (role.getType()==ROLE_TYPE) toReturn.add(mapLRRole(role)); } - } catch (SystemException e) { - e.printStackTrace(); - } catch (PortalException e) { + } catch (SystemException | PortalException e) { e.printStackTrace(); } return toReturn; @@ -317,6 +326,111 @@ public class LiferayRoleManager implements RoleManager { } return toReturn; } - - + /** + * {@inheritDoc} + */ + @Override + public GCubeTeam createTeam(long groupId, String teamName, String teamDescription) throws GroupRetrievalFault, TeamRetrievalFault, UserManagementSystemException { + long userId = LiferayUserManager.getAdmin().getUserId(); + try { + return mapLRTeam(TeamLocalServiceUtil.addTeam(userId, groupId, teamName, teamDescription)); + } + catch (DuplicateTeamException ex) { + throw new TeamRetrievalFault("A Team with this name exists already: name="+teamName); + } + catch (PortalException e) { + throw new GroupRetrievalFault("The groupId could not be found", e); + } catch (SystemException e) { + e.printStackTrace(); + } + return null; + } + /** + * {@inheritDoc} + */ + @Override + public GCubeTeam deleteTeam(long teamId) throws UserManagementSystemException, TeamRetrievalFault { + try { + Team deleted = TeamLocalServiceUtil.deleteTeam(teamId); + return mapLRTeam(deleted); + } catch (PortalException e) { + throw new TeamRetrievalFault("The teamId does not exists", e); + } catch (SystemException e) { + e.printStackTrace(); + } + return null; + } + /** + * {@inheritDoc} + */ + @Override + public boolean deleteTeams(long groupId) throws UserManagementSystemException { + try { + TeamLocalServiceUtil.deleteTeams(groupId); + } catch (PortalException | SystemException e) { + e.printStackTrace(); + return false; + } + return true; + } + /** + * {@inheritDoc} + */ + @Override + public GCubeTeam getTeam(long teamId) throws UserManagementSystemException, TeamRetrievalFault { + try { + return mapLRTeam(TeamLocalServiceUtil.getTeam(teamId)); + } catch (PortalException e) { + _log.warn(teamId + " Team id not existing"); + } catch (SystemException e) { + _log.error("Liferay SystemException"); + } + return null; + } + /** + * {@inheritDoc} + */ + @Override + public List listTeamsByGroup(long groupId) { + List toReturn = new ArrayList<>(); + List teams; + try { + teams = TeamLocalServiceUtil.getGroupTeams(groupId); + for (Team team : teams) { + toReturn.add(mapLRTeam(team)); + } + } catch (SystemException | PortalException e) { + e.printStackTrace(); + } + return toReturn; + } + /** + * {@inheritDoc} + */ + @Override + public GCubeTeam updateTeam(long teamId, String teamName, String teamDescription) throws TeamRetrievalFault { + Team toEdit; + try { + toEdit = TeamLocalServiceUtil.updateTeam(teamId, teamName, teamDescription); + return mapLRTeam(toEdit); + } catch (PortalException e) { + throw new TeamRetrievalFault("The teamId does not exists", e); + } catch (SystemException e) { + e.printStackTrace(); + } + return null; + } + /** + * {@inheritDoc} + */ + @Override + public boolean setUserTeams(long userId, long[] teamIds) throws TeamRetrievalFault { + try { + TeamLocalServiceUtil.setUserTeams(userId, teamIds); + } catch (SystemException e) { + e.printStackTrace(); + return false; + } + return true; + } } diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/model/GCubeTeam.java b/src/main/java/org/gcube/vomanagement/usermanagement/model/GCubeTeam.java new file mode 100644 index 0000000..aef3e56 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/model/GCubeTeam.java @@ -0,0 +1,89 @@ +package org.gcube.vomanagement.usermanagement.model; + +import java.io.Serializable; + +@SuppressWarnings("serial") +public class GCubeTeam implements Serializable { + private long groupId; + private long teamId; + private String teamName; + private String description; + + + public GCubeTeam(){ + + } + + + + public GCubeTeam(long groupId, long teamId, String teamName, + String description) { + super(); + this.groupId = groupId; + this.teamId = teamId; + this.teamName = teamName; + this.description = description; + } + + + + public long getGroupId() { + return groupId; + } + + + + public void setGroupId(long groupId) { + this.groupId = groupId; + } + + + + public long getTeamId() { + return teamId; + } + + + + public void setTeamId(long teamId) { + this.teamId = teamId; + } + + + + public String getTeamName() { + return teamName; + } + + + + public void setTeamName(String teamName) { + this.teamName = teamName; + } + + + + public String getDescription() { + return description; + } + + + + public void setDescription(String description) { + this.description = description; + } + + + + @Override + public String toString() { + return "GCubeTeam [groupId=" + groupId + ", teamId=" + teamId + + ", teamName=" + teamName + ", description=" + description + + "]"; + } + + + + + +}