Minor fixes

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@129154 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-06-18 08:05:10 +00:00
parent a1e25a6208
commit 9ea6242cf0
2 changed files with 9 additions and 10 deletions

View File

@ -658,7 +658,7 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
}
@Override
public void checkRole(String username, String organizationName,
public boolean checkRole(String username, String organizationName,
RolesIntoOrganization correspondentRoleToCheck) {
logger.debug("Request for checking if " + username + " into " + organizationName + " has role " + correspondentRoleToCheck);
@ -692,7 +692,6 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
try {
HttpPost request = new HttpPost(CKAN_CATALOGUE_URL + path);
request.addHeader("Authorization", CKAN_TOKEN_SYS); // sys token
StringEntity params = new StringEntity(parameter);
@ -700,24 +699,23 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
HttpResponse response = httpClient.execute(request);
logger.debug("Response code is " + response.getStatusLine().getStatusCode() + " and response message is " + response.getStatusLine().getReasonPhrase());
if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
return;
return (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK);
}catch (Exception ex) {
logger.error("Error while trying to change the role for this user ", ex);
}
return;
return false;
}
@Override
public boolean isSysAdmin(String username, String apiKey) {
// in order to avoid errors, the username is always converted
String ckanUsername = UtilMethods.fromUsernameToCKanUsername(username);
try{
// in order to avoid errors, the username is always converted
String ckanUsername = UtilMethods.fromUsernameToCKanUsername(username);
CheckedCkanClient checkedClient = new CheckedCkanClient(CKAN_CATALOGUE_URL, apiKey);
CkanUser user = checkedClient.getUser(getUserIdByUsername(ckanUsername));
CkanUser user = checkedClient.getUser(ckanUsername);
return user.isSysadmin();
}catch(Exception e){
logger.error("Failed to check if the user " + username + " has role sysadmin", e);
@ -728,7 +726,7 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
@Override
protected void finalize() throws Throwable {
logger.debug("Closing connection poolon finalize()");
logger.debug("Closing connection pool on finalize()");
ds.close();
}
}

View File

@ -141,7 +141,8 @@ public interface CKanUtilsInterface {
* @param username
* @param organizationName
* @param correspondentRoleToCheck
* @return true if the role can be set, false if it cannot
*/
public void checkRole(String username, String organizationName,
public boolean checkRole(String username, String organizationName,
RolesIntoOrganization correspondentRoleToCheck);
}