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:
parent
ff6df17384
commit
40459ae18b
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
@ -32,6 +33,15 @@ public class TestCKanLib {
|
|||
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{
|
||||
|
||||
|
|
Loading…
Reference in New Issue