minor improvement

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@130613 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-07-20 22:06:36 +00:00
parent 22969be193
commit 02fcf099df
1 changed files with 70 additions and 88 deletions

View File

@ -12,6 +12,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBea
import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.RoleManager; import org.gcube.vomanagement.usermanagement.RoleManager;
import org.gcube.vomanagement.usermanagement.UserManager; import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
@ -21,6 +22,7 @@ import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeRole; import org.gcube.vomanagement.usermanagement.model.GCubeRole;
import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames; import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames;
import eu.trentorise.opendata.jackan.model.CkanOrganization; import eu.trentorise.opendata.jackan.model.CkanOrganization;
@ -209,41 +211,15 @@ public class UserUtil {
// get the role of the users in this group // get the role of the users in this group
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userid, groupManager.getGroupId(gCubeGroupName)); List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userid, groupManager.getGroupId(gCubeGroupName));
// the default one // get highest role
RolesIntoOrganization correspondentRoleToCheck = RolesIntoOrganization.MEMBER; RolesIntoOrganization correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
// NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog
for (GCubeRole gCubeRole : roles) {
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_ADMIN.getRoleName())){
logger.debug("User " + username + " has role " + gCubeRole.getRoleName() + " in " + gCubeGroupName);
correspondentRoleToCheck = RolesIntoOrganization.ADMIN;
break;
}
}
// if the role is member, continue // if the role is member, continue
if(correspondentRoleToCheck.equals(RolesIntoOrganization.MEMBER)) if(correspondentRoleToCheck.equals(RolesIntoOrganization.MEMBER))
continue; continue;
// with this invocation, we check if the role is present in ckan and if it is not it will be added checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, correspondentRoleToCheck, workspaceInstance,
CKanUtils ckanUtils = workspaceInstance.getCkanUtilsObj(groupManager.getInfrastructureScope(gCubeGroup.getGroupId())); groupManager, gCubeGroup.getGroupId(), orgsInWhichAdminRole);
// if there is an instance of ckan in this scope..
if(ckanUtils != null){
boolean res = ckanUtils.checkRole(username, gCubeGroupName, correspondentRoleToCheck);
if(res){
// get the orgs of the user
List<CkanOrganization> ckanOrgs = ckanUtils.getOrganizationsByUser(username);
for (CkanOrganization ckanOrganization : ckanOrgs) {
if(ckanOrganization.getName().equals(gCubeGroupName.toLowerCase())){
orgsInWhichAdminRole.add(new OrganizationBean(ckanOrganization.getTitle(), ckanOrganization.getName()));
break;
}
}
}
}else
logger.error("It seems there is no ckan instance into scope " + groupManager.getInfrastructureScope(gCubeGroup.getGroupId()));
} }
}else if(groupManager.isVO(currentGroupId)){ }else if(groupManager.isVO(currentGroupId)){
@ -260,41 +236,15 @@ public class UserUtil {
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userid, groupManager.getGroupId(gCubeGroupName)); List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userid, groupManager.getGroupId(gCubeGroupName));
// the default one // get highest role
RolesIntoOrganization correspondentRoleToCheck = RolesIntoOrganization.MEMBER; RolesIntoOrganization correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
// NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog
for (GCubeRole gCubeRole : roles) {
logger.debug("User " + username + " has role " + gCubeRole.getRoleName() + " in " + gCubeGroupName);
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_ADMIN.getRoleName())){
correspondentRoleToCheck = RolesIntoOrganization.ADMIN;
break;
}
}
// if the role is member, continue // if the role is member, continue
if(correspondentRoleToCheck.equals(RolesIntoOrganization.MEMBER)) if(correspondentRoleToCheck.equals(RolesIntoOrganization.MEMBER))
continue; continue;
// with this invocation, we check if the role is present in ckan and if it is not it will be added checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, correspondentRoleToCheck, workspaceInstance,
CKanUtils ckanUtils = workspaceInstance.getCkanUtilsObj(groupManager.getInfrastructureScope(gCubeGroup.getGroupId())); groupManager, gCubeGroup.getGroupId(), orgsInWhichAdminRole);
// if there is an instance of ckan in this scope..
if(ckanUtils != null){
boolean res = ckanUtils.checkRole(username, gCubeGroupName, correspondentRoleToCheck);
if(res){
// get the orgs of the user
List<CkanOrganization> ckanOrgs = ckanUtils.getOrganizationsByUser(username);
for (CkanOrganization ckanOrganization : ckanOrgs) {
if(ckanOrganization.getName().equals(gCubeGroupName.toLowerCase())){
orgsInWhichAdminRole.add(new OrganizationBean(ckanOrganization.getTitle(), ckanOrganization.getName()));
break;
}
}
}
}else
logger.error("It seems there is no ckan instance into scope " + groupManager.getInfrastructureScope(gCubeGroup.getGroupId()));
} }
}else if(groupManager.isVRE(currentGroupId)){ }else if(groupManager.isVRE(currentGroupId)){
@ -302,38 +252,14 @@ public class UserUtil {
logger.debug("The current scope is the vre " + groupName); logger.debug("The current scope is the vre " + groupName);
// the default one // get highest role
String mainRole = "Catalogue-Member"; RolesIntoOrganization correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
RolesIntoOrganization correspondentRoleToCheck = RolesIntoOrganization.MEMBER;
// NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog
for (GCubeRole role : roles) {
logger.debug("User " + username + " has role " + role.getRoleName() + " in " + currentScope);
if(role.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_ADMIN.getRoleName())){
mainRole = GatewayRolesNames.CATALOGUE_ADMIN.getRoleName();
correspondentRoleToCheck = RolesIntoOrganization.ADMIN;
break;
}
}
// if it the role is ADMIN we have to be sure to set it // if it the role is ADMIN we have to be sure to set it
if(correspondentRoleToCheck.equals(RolesIntoOrganization.ADMIN)){ if(correspondentRoleToCheck.equals(RolesIntoOrganization.ADMIN)){
// with this invocation, we check if the role is present in ckan and if it is not it will be added checkIfRoleIsSetInCkanInstance(username, groupName, correspondentRoleToCheck, workspaceInstance,
CKanUtils ckanUtils = workspaceInstance.getCkanUtilsObj(groupManager.getInfrastructureScope(currentGroupId)); groupManager, currentGroupId, orgsInWhichAdminRole);
boolean res = ckanUtils.checkRole(username, groupName, correspondentRoleToCheck);
if(res){
// get the orgs of the user
List<CkanOrganization> ckanOrgs = ckanUtils.getOrganizationsByUser(username);
for (CkanOrganization ckanOrganization : ckanOrgs) {
if(ckanOrganization.getName().equals(groupName.toLowerCase())){
orgsInWhichAdminRole.add(new OrganizationBean(ckanOrganization.getTitle(), ckanOrganization.getName()));
break;
}
}
}
} }
} }
}catch(Exception e){ }catch(Exception e){
@ -349,4 +275,60 @@ public class UserUtil {
logger.debug("Returning role " + toReturn + " for user " + username); logger.debug("Returning role " + toReturn + " for user " + username);
return toReturn; return toReturn;
} }
/**
* Check if the role admin is set or must be set into the ckan instance at this scope
* @param username
* @param gCubeGroupName
* @param correspondentRoleToCheck
* @param workspaceInstance
* @param groupManager
* @param groupId
* @param orgsInWhichAdminRole
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
*/
private static void checkIfRoleIsSetInCkanInstance(String username,
String gCubeGroupName,
RolesIntoOrganization correspondentRoleToCheck,
GWTWorkspaceServiceImpl workspaceInstance,
GroupManager groupManager, long groupId, List<OrganizationBean> orgsInWhichAdminRole) throws UserManagementSystemException, GroupRetrievalFault {
// with this invocation, we check if the role is present in ckan and if it is not it will be added
CKanUtils ckanUtils = workspaceInstance.getCkanUtilsObj(groupManager.getInfrastructureScope(groupId));
// if there is an instance of ckan in this scope..
if(ckanUtils != null){
boolean res = ckanUtils.checkRole(username, gCubeGroupName, correspondentRoleToCheck);
if(res){
// get the orgs of the user
List<CkanOrganization> ckanOrgs = ckanUtils.getOrganizationsByUser(username);
for (CkanOrganization ckanOrganization : ckanOrgs) {
if(ckanOrganization.getName().equals(gCubeGroupName.toLowerCase())){
orgsInWhichAdminRole.add(new OrganizationBean(ckanOrganization.getTitle(), ckanOrganization.getName()));
break;
}
}
}
}else
logger.error("It seems there is no ckan instance into scope " + groupManager.getInfrastructureScope(groupId));
}
/**
* Retrieve the ckan roles among a list of liferay roles
* @param roles
* @return
*/
private static RolesIntoOrganization getLiferayHighestRoleInOrg(
List<GCubeRole> roles) {
// NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog
for (GCubeRole gCubeRole : roles) {
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_ADMIN.getRoleName())){
return RolesIntoOrganization.ADMIN;
}
}
return RolesIntoOrganization.MEMBER;
}
} }