added team management

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vo-management/usermanagement-core@127014 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-04-12 14:31:11 +00:00
parent 7379149d2f
commit e6657b5859
9 changed files with 321 additions and 34 deletions

View File

@ -29,9 +29,9 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>

View File

@ -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

View File

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="usermanagement-core">
<wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/test/java"/>
<wb-resource deploy-path="/" source-path="/src/test/resources"/>
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
</wb-module>
</project-modules>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="1.6"/>
<installed facet="jst.utility" version="1.0"/>
<installed facet="java" version="1.7"/>
</faceted-project>

View File

@ -95,8 +95,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

View File

@ -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<GCubeRole> listAllRoles();
/**
* @return a list of {@link GCubeTeam} belonging to a give group
*/
List<GCubeTeam> listTeamsByGroup(long groupId);
/**
* @return a list of {@link GcubeRole} of type Site Role (Type=2)
*/
List<GCubeRole> 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<GCubeRole> 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;
}

View File

@ -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();
}
}

View File

@ -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<GCubeRole> listAllGroupRoles() {
List<GCubeRole> toReturn = new ArrayList<GCubeRole>();
List<Role> roles;
try {
List<Role> roles = RoleLocalServiceUtil.getRoles(ManagementUtils.getCompany().getCompanyId());
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<GCubeTeam> listTeamsByGroup(long groupId) {
List<GCubeTeam> toReturn = new ArrayList<>();
List<Team> 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;
}
}

View File

@ -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
+ "]";
}
}