added listVresByUserMethod in GroupManager interface and implementations

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vo-management/usermanagement-core@151204 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-07-23 10:48:50 +00:00
parent 9a37eefd22
commit f8a8a6b832
4 changed files with 81 additions and 9 deletions

View File

@ -153,6 +153,12 @@ public interface GroupManager {
* @throws GroupRetrievalFault
*/
List<GCubeGroup> listGroupsByUser(long userId) throws UserRetrievalFault, UserManagementSystemException, GroupRetrievalFault;
/**
* * @return the list of user VREs
* @throws UserManagementSystemException
* @throws GroupRetrievalFault if the rootVO does not exists
*/
List<GCubeGroup> listVresByUser(long userId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault ;
/**
* @param userId the LR userId
* @param serverName the host name of the server that is sending the request (e.g. i-marine.d4science.org)
@ -237,4 +243,4 @@ public interface GroupManager {
* @return a list of gateways
*/
List<GCubeGroup> getGateways();
}
}

View File

@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@ -414,6 +415,19 @@ public class LiferayGroupManager implements GroupManager {
}
return toReturn;
}
@Override
public List<GCubeGroup> listVresByUser(long userId)
throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault {
List<GCubeGroup> toReturn = listGroupsByUser(userId);
Iterator<GCubeGroup> iterator = toReturn.iterator();
while (iterator.hasNext()) {
GCubeGroup gCubeGroup = (GCubeGroup) iterator.next();
if(!isVRE(gCubeGroup.getGroupId()))
iterator.remove();
}
return toReturn;
}
/**
* {@inheritDoc}
*/
@ -730,6 +744,4 @@ public class LiferayGroupManager implements GroupManager {
}
return gateways;
}
}
}

View File

@ -31,6 +31,10 @@ import com.liferay.portal.service.UserGroupRoleLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;
/**
* Exploit Liferay JSON Web Service to perform RoleManager's operations.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class LiferayRoleManager implements RoleManager {
/**
* logger

View File

@ -165,7 +165,10 @@ public class LiferayWSGroupManager implements GroupManager {
long logoId = 0; // TODO
long groupId = (long)jsonGroupObject.get("groupId");
if (isVRE(groupId)) {
// faster way to determine if it is a VRE or a VO or the ROOT Vo
String threePath = (String)jsonGroupObject.get("treePath");
if (isVREByThreePath(threePath)) {
logger.debug("********** IS VRE");
return new GCubeGroup(
groupId,
@ -177,7 +180,7 @@ public class LiferayWSGroupManager implements GroupManager {
null,
getMappedGroupMembershipType(((Long)jsonGroupObject.get("type")).intValue()));
}
else if (isVO(groupId)) {
else if (isVOByThreePath(threePath)) {
logger.debug("********** IS VO");
List<GCubeGroup> vres = new ArrayList<GCubeGroup>();
List<String> vreInJson = getChildren(groupId);
@ -194,7 +197,7 @@ public class LiferayWSGroupManager implements GroupManager {
logoId,
vres,
getMappedGroupMembershipType(((Long)jsonGroupObject.get("type")).intValue()));
} else if (isRootVO(groupId)) {
} else if (isRootVOByThreePath(threePath)) {
logger.debug("********** IS ROOT VO");
List<GCubeGroup> vos = new ArrayList<GCubeGroup>();
List<String> vosInJson = getChildren(groupId);
@ -222,6 +225,26 @@ public class LiferayWSGroupManager implements GroupManager {
return null;
}
private boolean isVREByThreePath(String threePath) throws Exception {
// faster way to determine if it is a VRE or a VO
if(threePath == null || threePath.isEmpty())
throw new Exception("threePath is missing");
return threePath.split("/").length == 4; // e.g. for a VRE is /21654/21657/21660/ (4)
}
private boolean isVOByThreePath(String threePath) throws Exception {
if(threePath == null || threePath.isEmpty())
throw new Exception("threePath is missing");
return threePath.split("/").length == 3; // e.g. for a VO is /21654/21657/ (3)
}
private boolean isRootVOByThreePath(String threePath) throws Exception {
if(threePath == null || threePath.isEmpty())
throw new Exception("threePath is missing");
return threePath.split("/").length == 2; // e.g. for a Root VO is /21654/ (2)
}
/**
* Retrieve the group children of the group having id groupId
* @param groupId
@ -534,6 +557,34 @@ public class LiferayWSGroupManager implements GroupManager {
return toReturn;
}
@Override
public List<GCubeGroup> listVresByUser(long userId)
throws UserManagementSystemException, GroupRetrievalFault,
UserRetrievalFault {
List<GCubeGroup> toReturn = new ArrayList<GCubeGroup>();
try{
String jsonGroups = // TODO evaluate the max number of groups to return before, somehow
executeHTTPGETRequest(API_BASE_URL + GET_GROUPS_BY_USERID.replace("$USER_ID", String.valueOf(userId)).replace("$MAX_GROUP", String.valueOf(1000)),
credsProvider, localContext, target);
if(jsonGroups != null){
logger.debug("Trying to parse json object");
JSONParser parser = new JSONParser();
JSONArray array = (JSONArray)parser.parse(jsonGroups);
for (int i = 0; i < array.size(); i++) {
String threePath = (String)((JSONObject)array.get(i)).get("treePath");
if(isVREByThreePath(threePath))
toReturn.add(mapLRGroup(((JSONObject)array.get(i)).toJSONString()));
}
return toReturn;
}
}catch(Exception e){
logger.error("Error while retrieving the group id, returning -1", e);
}
return null;
}
@Override
public Set<GCubeGroup> listGroupsByUserAndSite(long userId,
String serverName) throws UserRetrievalFault,
@ -609,7 +660,6 @@ public class LiferayWSGroupManager implements GroupManager {
logger.debug("Data is " + result);
return result;
}
@ -672,4 +722,4 @@ public class LiferayWSGroupManager implements GroupManager {
return gateways;
}
}
}