minor fixes

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@163073 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2018-02-08 16:59:01 +00:00
parent 53eb63ead6
commit a37ce79aca
3 changed files with 119 additions and 77 deletions

View File

@ -4,6 +4,15 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="grsf-manage-widget-1.3.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/grsf-manage-widget/grsf-manage-widget">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="grsf-common-library-1.0.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/grsf-common-library/grsf-common-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="ckan-util-library-2.4.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/ckan-util-library/ckan-util-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="gcube-ckan-datacatalog"/>
<property name="java-output-path" value="/gcube-ckan-datacatalog/target/gcube-ckan-datacatalog-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</wb-module>

View File

@ -4,7 +4,6 @@
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -56,67 +55,36 @@ public class UserUtil {
UserManager userManager = new LiferayUserManager();
RoleManager roleManager = new LiferayRoleManager();
Map<String, String> mapRoleByGroupSingleVre = new HashMap<String, String>();
Map<String, String> mapRoleByGroupExtrasVre = new HashMap<String, String>();
GCubeUser user;
try {
user = userManager.getUserByEmail(userEMail);
List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(user.getUserId());
// filter according the current context: if it is a VO/VRE, we send all the VRES under the VO. If it is the root vo, we send all user's vres.
long groupIdContext = groupManager.getGroupIdFromInfrastructureScope(context);
GCubeGroup groupContext = groupManager.getGroup(groupIdContext);
Iterator<GCubeGroup> iterator = listOfGroups.iterator();
if(groupManager.isVRE(groupIdContext)){
long parentId = groupContext.getParentGroupId();
while (iterator.hasNext()) {
GCubeGroup gCubeGroup = (GCubeGroup) iterator.next();
if(gCubeGroup.getParentGroupId() != parentId)
iterator.remove();
}
}else if(groupManager.isVO(groupIdContext)){
// get the list of vres
while (iterator.hasNext()) {
GCubeGroup gCubeGroup = (GCubeGroup) iterator.next();
if(groupIdContext != gCubeGroup.getParentGroupId())
iterator.remove();
}
}else{
// only the vres
while (iterator.hasNext()) {
GCubeGroup gCubeGroup = (GCubeGroup) iterator.next();
if(!groupManager.isVRE(gCubeGroup.getGroupId()))
iterator.remove();
}
}
// retrieve the role
for (GCubeGroup vre: listOfGroups) {
if(vre.getGroupId() == groupIdContext){
String localRole = RolesCkanGroupOrOrg.convertToCkanCapacity(getLiferayHighestRoleInOrg(roleManager.listRolesByUserAndGroup(user.getUserId(), vre.getGroupId())));
mapRoleByGroupSingleVre.put(vre.getGroupName().toLowerCase(),
localRole);
// check if extra roles must be assigned
logger.debug("Checking if there is the need to extend role " + localRole + " for user " + user.getUsername() + " in other vres");
instance.assignRolesOtherOrganization(user.getUsername(),
vre.getGroupName().toLowerCase(),
RolesCkanGroupOrOrg.convertFromCapacity(localRole));
if(isViewPerVREEnabled)
break;
}else if(!isViewPerVREEnabled)
mapRoleByGroupExtrasVre.put(vre.getGroupName().toLowerCase(),
RolesCkanGroupOrOrg.convertToCkanCapacity(getLiferayHighestRoleInOrg(roleManager.listRolesByUserAndGroup(user.getUserId(), vre.getGroupId()))));
}
// schedule the thread for the groups other than the vre to be checked in the local ckan instance
if(mapRoleByGroupExtrasVre.size() > 0)
GCubeGroup currentVRE = groupManager.getGroup(groupIdContext);
String localRole = RolesCkanGroupOrOrg.convertToCkanCapacity(getLiferayHighestRoleInOrg(roleManager.listRolesByUserAndGroup(user.getUserId(), currentVRE.getGroupId())));
mapRoleByGroupSingleVre.put(currentVRE.getGroupName().toLowerCase(),
localRole);
// check if extra roles must be assigned
logger.debug("Checking if there is the need to extend role " + localRole + " for user " + user.getUsername() + " in other vres");
instance.assignRolesOtherOrganization(user.getUsername(),
currentVRE.getGroupName().toLowerCase(),
RolesCkanGroupOrOrg.convertFromCapacity(localRole));
// perform further checks
if(!isViewPerVREEnabled){
List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(user.getUserId());
new AddUserToOrganizationThread(
instance,
user.getUsername(),
mapRoleByGroupExtrasVre).
user,
listOfGroups,
isViewPerVREEnabled,
groupIdContext,
roleManager,
groupManager).
start();
}
logger.debug("Returning Map to the ckan connector : " + mapRoleByGroupSingleVre);
return mapRoleByGroupSingleVre;
}catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) {
@ -274,7 +242,7 @@ public class UserUtil {
* @param roles
* @return MEMBER/EDITOR/ADMIN role
*/
private static RolesCkanGroupOrOrg getLiferayHighestRoleInOrg(
public static RolesCkanGroupOrOrg getLiferayHighestRoleInOrg(
List<GCubeRole> roles) {
// NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog

View File

@ -1,11 +1,19 @@
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server.thread;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server.UserUtil;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.RoleManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
@ -18,39 +26,96 @@ public class AddUserToOrganizationThread extends Thread {
private static final Log logger = LogFactoryUtil.getLog(AddUserToOrganizationThread.class);
private DataCatalogue instance;
private String username;
private Map<String, String> orgAndCapacity;
private GCubeUser user;
private List<GCubeGroup> listOfGroups;
private boolean isViewPerVREEnabled;
private long groupIdContext;
private GroupManager groupManager;
private RoleManager roleManager;
/**
* @param instance
* @param username
* @param orgAndCapacity
* @param user
* @param listOfGroups
* @param isViewPerVREEnabled
* @param groupIdContext
* @param groupManager
* @param roleManager
*/
public AddUserToOrganizationThread(DataCatalogue instance, String username,
Map<String, String> orgAndCapacity) {
public AddUserToOrganizationThread(DataCatalogue instance, GCubeUser user,
List<GCubeGroup> listOfGroups,
boolean isViewPerVREEnabled,
long groupIdContext, RoleManager roleManager, GroupManager groupManager) {
super();
this.instance = instance;
this.username = username;
this.orgAndCapacity = orgAndCapacity;
this.user = user;
this.listOfGroups = listOfGroups;
this.isViewPerVREEnabled= isViewPerVREEnabled;
this.groupIdContext = groupIdContext;
this.roleManager = roleManager;
this.groupManager = groupManager;
}
@Override
public void run() {
logger.debug("Thread for role association started. Organizations and roles are in the map: " + orgAndCapacity);
Set<Entry<String, String>> entrySet = orgAndCapacity.entrySet();
for (Entry<String, String> entry : entrySet) {
if(instance.getOrganizationByName(entry.getKey()) != null){
instance.checkRoleIntoOrganization(username, entry.getKey(), RolesCkanGroupOrOrg.convertFromCapacity(entry.getValue()));
instance.assignRolesOtherOrganization(username, entry.getKey(), RolesCkanGroupOrOrg.convertFromCapacity(entry.getValue()));
}
else if(instance.getGroupByName(entry.getKey()) != null){
RolesCkanGroupOrOrg roleInGroup = RolesCkanGroupOrOrg.convertFromCapacity(entry.getValue());
roleInGroup = roleInGroup.equals(RolesCkanGroupOrOrg.EDITOR) ? RolesCkanGroupOrOrg.MEMBER : roleInGroup;
instance.checkRoleIntoGroup(username, entry.getKey(), roleInGroup);
}
}
logger.debug("Thread for role association ended");
try{
Map<String, String> orgAndCapacity = new HashMap<String, String>();
String username = user.getUsername();
GCubeGroup groupContext = groupManager.getGroup(groupIdContext);
Iterator<GCubeGroup> iterator = listOfGroups.iterator();
if(groupManager.isVRE(groupIdContext)){
long parentId = groupContext.getParentGroupId();
while (iterator.hasNext()) {
GCubeGroup gCubeGroup = (GCubeGroup) iterator.next();
if(gCubeGroup.getParentGroupId() != parentId)
iterator.remove();
}
}else if(groupManager.isVO(groupIdContext)){
// get the list of vres
while (iterator.hasNext()) {
GCubeGroup gCubeGroup = (GCubeGroup) iterator.next();
if(groupIdContext != gCubeGroup.getParentGroupId())
iterator.remove();
}
}else{
// only the vres
while (iterator.hasNext()) {
GCubeGroup gCubeGroup = (GCubeGroup) iterator.next();
if(!groupManager.isVRE(gCubeGroup.getGroupId()))
iterator.remove();
}
}
// retrieve the role
for (GCubeGroup vre: listOfGroups) {
if(vre.getGroupId() == groupIdContext){
continue;
}else if(!isViewPerVREEnabled)
orgAndCapacity.put(vre.getGroupName().toLowerCase(),
RolesCkanGroupOrOrg.convertToCkanCapacity(UserUtil.getLiferayHighestRoleInOrg(roleManager.listRolesByUserAndGroup(user.getUserId(), vre.getGroupId()))));
}
logger.debug("Thread for role association started. Organizations and roles are in the map: " + orgAndCapacity);
Set<Entry<String, String>> entrySet = orgAndCapacity.entrySet();
for (Entry<String, String> entry : entrySet) {
if(instance.getOrganizationByName(entry.getKey()) != null){
instance.checkRoleIntoOrganization(username, entry.getKey(), RolesCkanGroupOrOrg.convertFromCapacity(entry.getValue()));
instance.assignRolesOtherOrganization(username, entry.getKey(), RolesCkanGroupOrOrg.convertFromCapacity(entry.getValue()));
}
else if(instance.getGroupByName(entry.getKey()) != null){
RolesCkanGroupOrOrg roleInGroup = RolesCkanGroupOrOrg.convertFromCapacity(entry.getValue());
roleInGroup = roleInGroup.equals(RolesCkanGroupOrOrg.EDITOR) ? RolesCkanGroupOrOrg.MEMBER : roleInGroup;
instance.checkRoleIntoGroup(username, entry.getKey(), roleInGroup);
}
}
logger.debug("Thread for role association ended");
}catch(Exception e){
logger.error("Failed while adding user to other organization", e);
}
}
}