removed embedded mapping for production root

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@131363 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-09-14 16:00:10 +00:00
parent ff6df17384
commit 40459ae18b
2 changed files with 54 additions and 44 deletions

View File

@ -56,10 +56,10 @@ import eu.trentorise.opendata.jackan.model.CkanUser;
*/
public class CKanUtilsImpl implements CKanUtils{
// TO BE REMOVED TODO
public final static String PRODUCTION_SCOPE_ROOT = "/d4science.research-infrastructures.eu";
public final static String PRODUCTION_CKAN_ORGNAME_ROOT = "d4science";
public final static String PRODUCTION_LIFERAY_ORGNAME_ROOT = "d4science.research-infrastructures.eu";
// public final static String PRODUCTION_SCOPE_ROOT = "/d4science.research-infrastructures.eu";
// public final static String PRODUCTION_CKAN_ORGNAME_ROOT = "d4science";
// public final static String PRODUCTION_LIFERAY_ORGNAME_ROOT = "d4science.research-infrastructures.eu";
private static final Logger logger = LoggerFactory.getLogger(CKanUtilsImpl.class);
@ -167,7 +167,7 @@ public class CKanUtilsImpl implements CKanUtils{
logger.debug("Api key retrieved for user " + ckanUsername);
break;
}
}catch(Exception e){
logger.error("Unable to retrieve key for user " + ckanUsername, e);
}finally{
@ -181,7 +181,7 @@ public class CKanUtilsImpl implements CKanUtils{
@Override
public CKanUserWrapper getUserFromApiKey(String apiKey) {
logger.debug("Request user whose api key is = " + apiKey);
logger.debug("Request user whose api key is = " + apiKey.substring(0, 3) + "*************");
// checks
checkNotNull(apiKey);
@ -474,42 +474,42 @@ public class CKanUtilsImpl implements CKanUtils{
+ "}";
// replace with right data
parameter = parameter.replace("ORGANIZATION_ID", organizationId);
parameter = parameter.replace("DATASET_ID", datasetId);
// replace with right data
parameter = parameter.replace("ORGANIZATION_ID", organizationId);
parameter = parameter.replace("DATASET_ID", datasetId);
if(priv){
try(CloseableHttpClient httpClient = HttpClientBuilder.create().build();) {
HttpPost request = new HttpPost(CKAN_CATALOGUE_URL + pathSetPrivate);
request.addHeader("Authorization", apiKey);
StringEntity params = new StringEntity(parameter);
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
logger.debug("[PRIVATE]Response code is " + response.getStatusLine().getStatusCode() + " and response message is " + response.getStatusLine().getReasonPhrase());
if(priv){
try(CloseableHttpClient httpClient = HttpClientBuilder.create().build();) {
HttpPost request = new HttpPost(CKAN_CATALOGUE_URL + pathSetPrivate);
request.addHeader("Authorization", apiKey);
StringEntity params = new StringEntity(parameter);
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
logger.debug("[PRIVATE]Response code is " + response.getStatusLine().getStatusCode() + " and response message is " + response.getStatusLine().getReasonPhrase());
if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
return true;
if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
return true;
}catch (Exception ex) {
logger.error("Error while trying to set private the dataset ", ex);
}
}else
{
try(CloseableHttpClient httpClient = HttpClientBuilder.create().build();) {
HttpPost request = new HttpPost(CKAN_CATALOGUE_URL + pathSetPublic);
StringEntity params =new StringEntity(parameter);
request.addHeader("Authorization", apiKey);
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
logger.debug("[PUBLIC]Response code is " + response.getStatusLine().getStatusCode() + " and response message is " + response.getStatusLine().getReasonPhrase());
if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
return true;
}catch (Exception ex) {
logger.error("Error while trying to set public the dataset ", ex);
}
}catch (Exception ex) {
logger.error("Error while trying to set private the dataset ", ex);
}
}else
{
try(CloseableHttpClient httpClient = HttpClientBuilder.create().build();) {
HttpPost request = new HttpPost(CKAN_CATALOGUE_URL + pathSetPublic);
StringEntity params =new StringEntity(parameter);
request.addHeader("Authorization", apiKey);
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
logger.debug("[PUBLIC]Response code is " + response.getStatusLine().getStatusCode() + " and response message is " + response.getStatusLine().getReasonPhrase());
if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
return true;
}catch (Exception ex) {
logger.error("Error while trying to set public the dataset ", ex);
}
}
return false;
}
@ -713,7 +713,7 @@ public class CKanUtilsImpl implements CKanUtils{
res.getOrganization().getId(),
res.getId(),
CKAN_TOKEN_SYS); // use sysadmin api key to be sure it will be set
logger.debug("Was visibility set to " + (setPublic ? "public" : "private") + "? " + visibilitySet);
return res.getId();
@ -779,10 +779,10 @@ public class CKanUtilsImpl implements CKanUtils{
// check if this role is already present in ckan for this user within the organization
String organizationNameToCheck;
if(organizationName.equals(PRODUCTION_LIFERAY_ORGNAME_ROOT))
organizationNameToCheck = PRODUCTION_CKAN_ORGNAME_ROOT;
else
organizationNameToCheck = organizationName.toLowerCase();
// if(organizationName.equals(PRODUCTION_LIFERAY_ORGNAME_ROOT))
// organizationNameToCheck = PRODUCTION_CKAN_ORGNAME_ROOT;
// else
organizationNameToCheck = organizationName.toLowerCase();
boolean alreadyPresent = isRoleAlreadySet(ckanUsername, organizationNameToCheck, correspondentRoleToCheck);

View File

@ -1,6 +1,7 @@
package org.gcube.datacatalogue.ckanutillibrary;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -22,7 +23,7 @@ public class TestCKanLib {
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestCKanLib.class);
private CkanUtilsFactory factory;
private String scope = "/gcube/devsec/devVRE";
private String scope = "/gcube/devNext/NextNext";
private String testUser = "costantino_perciante";
String subjectId = "aa_father4";
String objectId = "bb_son4";
@ -31,6 +32,15 @@ public class TestCKanLib {
public void before(){
factory = CkanUtilsFactory.getFactory();
}
//@Test
public void getRole() throws Exception{
CKanUtilsImpl instance = factory.getUtilsPerScope(scope);
instance.getGroupsAndRolesByUser(testUser, Arrays.asList(RolesIntoOrganization.ADMIN, RolesIntoOrganization.EDITOR, RolesIntoOrganization.MEMBER
));
}
//@Test
public void datasetsRelationshipCreate() throws Exception{