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:
parent
53eb63ead6
commit
a37ce79aca
|
@ -4,6 +4,15 @@
|
||||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
<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/java"/>
|
||||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
<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="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"/>
|
<property name="java-output-path" value="/gcube-ckan-datacatalog/target/gcube-ckan-datacatalog-1.0.0-SNAPSHOT/WEB-INF/classes"/>
|
||||||
</wb-module>
|
</wb-module>
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server;
|
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -56,67 +55,36 @@ public class UserUtil {
|
||||||
UserManager userManager = new LiferayUserManager();
|
UserManager userManager = new LiferayUserManager();
|
||||||
RoleManager roleManager = new LiferayRoleManager();
|
RoleManager roleManager = new LiferayRoleManager();
|
||||||
Map<String, String> mapRoleByGroupSingleVre = new HashMap<String, String>();
|
Map<String, String> mapRoleByGroupSingleVre = new HashMap<String, String>();
|
||||||
Map<String, String> mapRoleByGroupExtrasVre = new HashMap<String, String>();
|
|
||||||
GCubeUser user;
|
GCubeUser user;
|
||||||
try {
|
try {
|
||||||
user = userManager.getUserByEmail(userEMail);
|
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.
|
// 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);
|
long groupIdContext = groupManager.getGroupIdFromInfrastructureScope(context);
|
||||||
GCubeGroup groupContext = groupManager.getGroup(groupIdContext);
|
GCubeGroup currentVRE = groupManager.getGroup(groupIdContext);
|
||||||
Iterator<GCubeGroup> iterator = listOfGroups.iterator();
|
String localRole = RolesCkanGroupOrOrg.convertToCkanCapacity(getLiferayHighestRoleInOrg(roleManager.listRolesByUserAndGroup(user.getUserId(), currentVRE.getGroupId())));
|
||||||
if(groupManager.isVRE(groupIdContext)){
|
mapRoleByGroupSingleVre.put(currentVRE.getGroupName().toLowerCase(),
|
||||||
long parentId = groupContext.getParentGroupId();
|
localRole);
|
||||||
while (iterator.hasNext()) {
|
|
||||||
GCubeGroup gCubeGroup = (GCubeGroup) iterator.next();
|
// check if extra roles must be assigned
|
||||||
if(gCubeGroup.getParentGroupId() != parentId)
|
logger.debug("Checking if there is the need to extend role " + localRole + " for user " + user.getUsername() + " in other vres");
|
||||||
iterator.remove();
|
instance.assignRolesOtherOrganization(user.getUsername(),
|
||||||
}
|
currentVRE.getGroupName().toLowerCase(),
|
||||||
}else if(groupManager.isVO(groupIdContext)){
|
RolesCkanGroupOrOrg.convertFromCapacity(localRole));
|
||||||
// get the list of vres
|
|
||||||
while (iterator.hasNext()) {
|
// perform further checks
|
||||||
GCubeGroup gCubeGroup = (GCubeGroup) iterator.next();
|
if(!isViewPerVREEnabled){
|
||||||
if(groupIdContext != gCubeGroup.getParentGroupId())
|
List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(user.getUserId());
|
||||||
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)
|
|
||||||
new AddUserToOrganizationThread(
|
new AddUserToOrganizationThread(
|
||||||
instance,
|
instance,
|
||||||
user.getUsername(),
|
user,
|
||||||
mapRoleByGroupExtrasVre).
|
listOfGroups,
|
||||||
|
isViewPerVREEnabled,
|
||||||
|
groupIdContext,
|
||||||
|
roleManager,
|
||||||
|
groupManager).
|
||||||
start();
|
start();
|
||||||
|
}
|
||||||
logger.debug("Returning Map to the ckan connector : " + mapRoleByGroupSingleVre);
|
logger.debug("Returning Map to the ckan connector : " + mapRoleByGroupSingleVre);
|
||||||
return mapRoleByGroupSingleVre;
|
return mapRoleByGroupSingleVre;
|
||||||
}catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) {
|
}catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) {
|
||||||
|
@ -274,7 +242,7 @@ public class UserUtil {
|
||||||
* @param roles
|
* @param roles
|
||||||
* @return MEMBER/EDITOR/ADMIN role
|
* @return MEMBER/EDITOR/ADMIN role
|
||||||
*/
|
*/
|
||||||
private static RolesCkanGroupOrOrg getLiferayHighestRoleInOrg(
|
public static RolesCkanGroupOrOrg getLiferayHighestRoleInOrg(
|
||||||
List<GCubeRole> roles) {
|
List<GCubeRole> roles) {
|
||||||
|
|
||||||
// NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog
|
// NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog
|
||||||
|
|
|
@ -1,11 +1,19 @@
|
||||||
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server.thread;
|
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;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg;
|
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.Log;
|
||||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
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 static final Log logger = LogFactoryUtil.getLog(AddUserToOrganizationThread.class);
|
||||||
private DataCatalogue instance;
|
private DataCatalogue instance;
|
||||||
private String username;
|
private GCubeUser user;
|
||||||
private Map<String, String> orgAndCapacity;
|
private List<GCubeGroup> listOfGroups;
|
||||||
|
private boolean isViewPerVREEnabled;
|
||||||
|
private long groupIdContext;
|
||||||
|
private GroupManager groupManager;
|
||||||
|
private RoleManager roleManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param instance
|
* @param instance
|
||||||
* @param username
|
* @param user
|
||||||
* @param orgAndCapacity
|
* @param listOfGroups
|
||||||
|
* @param isViewPerVREEnabled
|
||||||
|
* @param groupIdContext
|
||||||
|
* @param groupManager
|
||||||
|
* @param roleManager
|
||||||
*/
|
*/
|
||||||
public AddUserToOrganizationThread(DataCatalogue instance, String username,
|
public AddUserToOrganizationThread(DataCatalogue instance, GCubeUser user,
|
||||||
Map<String, String> orgAndCapacity) {
|
List<GCubeGroup> listOfGroups,
|
||||||
|
boolean isViewPerVREEnabled,
|
||||||
|
long groupIdContext, RoleManager roleManager, GroupManager groupManager) {
|
||||||
super();
|
super();
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
this.username = username;
|
this.user = user;
|
||||||
this.orgAndCapacity = orgAndCapacity;
|
this.listOfGroups = listOfGroups;
|
||||||
|
this.isViewPerVREEnabled= isViewPerVREEnabled;
|
||||||
|
this.groupIdContext = groupIdContext;
|
||||||
|
this.roleManager = roleManager;
|
||||||
|
this.groupManager = groupManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
logger.debug("Thread for role association started. Organizations and roles are in the map: " + orgAndCapacity);
|
try{
|
||||||
Set<Entry<String, String>> entrySet = orgAndCapacity.entrySet();
|
|
||||||
for (Entry<String, String> entry : entrySet) {
|
Map<String, String> orgAndCapacity = new HashMap<String, String>();
|
||||||
if(instance.getOrganizationByName(entry.getKey()) != null){
|
String username = user.getUsername();
|
||||||
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");
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue