fix in checkrole method

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@131418 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-09-15 15:41:33 +00:00
parent 5fa2475614
commit 6295a91bae
2 changed files with 50 additions and 42 deletions

View File

@ -784,6 +784,7 @@ public class CKanUtilsImpl implements CKanUtils{
// else // else
organizationNameToCheck = organizationName.toLowerCase(); organizationNameToCheck = organizationName.toLowerCase();
try{
boolean alreadyPresent = isRoleAlreadySet(ckanUsername, organizationNameToCheck, correspondentRoleToCheck); boolean alreadyPresent = isRoleAlreadySet(ckanUsername, organizationNameToCheck, correspondentRoleToCheck);
if(alreadyPresent) if(alreadyPresent)
@ -821,6 +822,10 @@ public class CKanUtilsImpl implements CKanUtils{
logger.error("Error while trying to change the role for this user ", ex); logger.error("Error while trying to change the role for this user ", ex);
} }
} }
}catch (Exception ex) {
logger.error("Unable to check if this role was already set, please check your parameters! ", ex);
}
return false; return false;
} }
@ -833,9 +838,7 @@ public class CKanUtilsImpl implements CKanUtils{
*/ */
protected boolean isRoleAlreadySet(String ckanUsername, protected boolean isRoleAlreadySet(String ckanUsername,
String organizationName, String organizationName,
RolesIntoOrganization correspondentRoleToCheck) { RolesIntoOrganization correspondentRoleToCheck) throws Exception{
try{
// get the users (if you try ckanOrganization.getUsers() it returns null.. maybe a bug TODO) // get the users (if you try ckanOrganization.getUsers() it returns null.. maybe a bug TODO)
List<CkanUser> users = client.getOrganization(organizationName).getUsers(); List<CkanUser> users = client.getOrganization(organizationName).getUsers();
@ -845,10 +848,6 @@ public class CKanUtilsImpl implements CKanUtils{
return true; return true;
} }
}catch(Exception e){
logger.error("Unable to check if this role was already set", e);
}
return false; return false;
} }

View File

@ -23,7 +23,7 @@ public class TestCKanLib {
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestCKanLib.class); private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestCKanLib.class);
private CkanUtilsFactory factory; private CkanUtilsFactory factory;
private String scope = "/gcube/devNext/NextNext"; private String scope = "/gcube";
private String testUser = "costantino_perciante"; private String testUser = "costantino_perciante";
String subjectId = "aa_father4"; String subjectId = "aa_father4";
String objectId = "bb_son4"; String objectId = "bb_son4";
@ -178,12 +178,12 @@ public class TestCKanLib {
ScopeProvider.instance.set("/gcube"); ScopeProvider.instance.set("/gcube");
String url = "https://dev4.d4science.org/group/devvre/ckan"; String url = "https://dev4.d4science.org/group/devvre/ckan";
String scopeToUse = new ApplicationProfileScopePerUrlReader().getScopePerUrl(url); String scopeToUse = ApplicationProfileScopePerUrlReader.getScopePerUrl(url);
logger.debug("Retrieved scope is " + scopeToUse); logger.debug("Retrieved scope is " + scopeToUse);
ScopeProvider.instance.reset(); // the following sysout should print null ScopeProvider.instance.reset(); // the following sysout should print null
String url2 = "https://dev4.d4science.org/group/devvre/ckan"; String url2 = "https://dev4.d4science.org/group/devvre/ckan";
String scopeToUse2 = new ApplicationProfileScopePerUrlReader().getScopePerUrl(url2); String scopeToUse2 = ApplicationProfileScopePerUrlReader.getScopePerUrl(url2);
logger.debug("Retrieved scope is " + scopeToUse2); logger.debug("Retrieved scope is " + scopeToUse2);
} }
@ -246,4 +246,13 @@ public class TestCKanLib {
// //
} }
//@Test
public void testInvalidOrgRole() throws Exception{
CKanUtilsImpl instance = factory.getUtilsPerScope(scope);
boolean res = instance.checkRole("costantino_perciante", "gcube", RolesIntoOrganization.EDITOR);
logger.debug(""+res);
}
} }