Minor fix: there is a bug into the jackan library, the list of users retrieved by organization.getUsers() is always null. We need to invoke client.getOrganization(orgName).getUsers();

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@129447 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-06-27 08:04:07 +00:00
parent 43b4e938c0
commit b19e751083
2 changed files with 20 additions and 17 deletions

View File

@ -230,8 +230,8 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
// iterate over them
for (CkanOrganization ckanOrganization : organizations) {
// get the list of users in it
List<CkanUser> users = ckanOrganization.getUsers();
// get the list of users in it (if you try ckanOrganization.getUsers() it returns null.. maybe a bug TODO)
List<CkanUser> users = client.getOrganization(ckanOrganization.getName()).getUsers();
// check if the current user is among them
for (CkanUser ckanUser : users) {
@ -271,8 +271,8 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
// iterate over them
for (CkanOrganization ckanOrganization : organizationsByUser) {
// get the list of users in it
List<CkanUser> users = ckanOrganization.getUsers();
// get the list of users in it (if you try ckanOrganization.getUsers() it returns null.. maybe a bug TODO)
List<CkanUser> users = client.getOrganization(ckanOrganization.getName()).getUsers();
// check if the current user is among them
for (CkanUser ckanUser : users) {
@ -743,11 +743,8 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
try{
// get this organization
CkanOrganization organization = client.getOrganization(organizationName);
// get the users
List<CkanUser> users = organization.getUsers();
// get the users (if you try ckanOrganization.getUsers() it returns null.. maybe a bug TODO)
List<CkanUser> users = client.getOrganization(organizationName).getUsers();
for (CkanUser ckanUser : users) {
if(ckanUser.getName().equals(ckanUsername) && ckanUser.getCapacity().equals(correspondentRoleToCheck.toString().toLowerCase()))

View File

@ -1,16 +1,16 @@
package org.gcube.datacatalogue.ckanutillibrary;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.gcube.datacatalogue.ckanutillibrary.models.CKanUserWrapper;
import org.gcube.datacatalogue.ckanutillibrary.models.RolesIntoOrganization;
import org.slf4j.LoggerFactory;
import eu.trentorise.opendata.jackan.CkanClient;
import eu.trentorise.opendata.jackan.model.CkanOrganization;
import eu.trentorise.opendata.jackan.model.CkanUser;
public class TestCKanLib {
@ -87,14 +87,20 @@ public class TestCKanLib {
instance = new CKanUtilsImpl("/gcube");
CkanClient client = new CkanClient(instance.getCatalogueUrl());
List<RolesIntoOrganization> rolesToMatch = new ArrayList<RolesIntoOrganization>();
rolesToMatch.add(RolesIntoOrganization.ADMIN);
rolesToMatch.add(RolesIntoOrganization.EDITOR);
CkanOrganization org = client.getOrganization("devvre");
List<CkanUser> users = org.getUsers();
Map<String, List<RolesIntoOrganization>> orgs = instance.getGroupsAndRolesByUser("costantino_perciante", rolesToMatch);
Iterator<Entry<String, List<RolesIntoOrganization>>> iterator = orgs.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<java.lang.String, java.util.List<org.gcube.datacatalogue.ckanutillibrary.models.RolesIntoOrganization>> entry = (Map.Entry<java.lang.String, java.util.List<org.gcube.datacatalogue.ckanutillibrary.models.RolesIntoOrganization>>) iterator
.next();
logger.debug("Org is " + entry.getKey() + " and role is " + entry.getValue().get(0));
for (CkanUser ckanUser : users) {
logger.debug("User is " + ckanUser.getName());
logger.debug("Capacity is " + ckanUser.getCapacity());
}
}