fixed getRelationships: it now supports one parameter only too
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@131081 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d93fc8f59c
commit
e101fe9786
|
@ -231,7 +231,8 @@ public interface CKanUtils {
|
||||||
boolean deleteDatasetRelationship(String datasetIdSubject, String datasetIdObject, DatasetRelationships relation, String apiKey);
|
boolean deleteDatasetRelationship(String datasetIdSubject, String datasetIdObject, DatasetRelationships relation, String apiKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of relationships between dataset datasetIdSubject and dataset datasetIdObject.
|
* Returns the list of relationships between dataset datasetIdSubject and dataset datasetIdObject. If datasetIdObject is missing, the whole list of
|
||||||
|
* relationships for dataset datasetIdSubject is returned.
|
||||||
* @param datasetIdSubject
|
* @param datasetIdSubject
|
||||||
* @param datasetIdObject
|
* @param datasetIdObject
|
||||||
* @param apiKey
|
* @param apiKey
|
||||||
|
|
|
@ -1009,16 +1009,15 @@ public class CKanUtilsImpl implements CKanUtils{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public List<CkanDatasetRelationship> getRelationshipDatasets(
|
public List<CkanDatasetRelationship> getRelationshipDatasets(
|
||||||
String datasetIdSubject, String datasetIdObject, String apiKey) {
|
String datasetIdSubject, String datasetIdObject, String apiKey) {
|
||||||
|
|
||||||
// checks
|
// checks
|
||||||
checkNotNull(datasetIdSubject);
|
checkNotNull(datasetIdSubject);
|
||||||
checkNotNull(datasetIdObject);
|
|
||||||
checkNotNull(apiKey);
|
checkNotNull(apiKey);
|
||||||
checkArgument(!datasetIdSubject.isEmpty());
|
checkArgument(!datasetIdSubject.isEmpty());
|
||||||
checkArgument(!datasetIdObject.isEmpty());
|
|
||||||
checkArgument(!apiKey.isEmpty());
|
checkArgument(!apiKey.isEmpty());
|
||||||
|
|
||||||
try(CloseableHttpClient httpClient = HttpClientBuilder.create().build();){
|
try(CloseableHttpClient httpClient = HttpClientBuilder.create().build();){
|
||||||
|
@ -1028,17 +1027,25 @@ public class CKanUtilsImpl implements CKanUtils{
|
||||||
// we need to use the apis to make it
|
// we need to use the apis to make it
|
||||||
String path = "/api/3/action/package_relationships_list";
|
String path = "/api/3/action/package_relationships_list";
|
||||||
|
|
||||||
|
String parameter;
|
||||||
|
|
||||||
// Request parameters to be replaced
|
// Request parameters to be replaced
|
||||||
String parameter = "{"
|
if(datasetIdObject == null || datasetIdObject.isEmpty())
|
||||||
|
parameter = "{"
|
||||||
|
+ "\"id\":\"SUBJECT\""
|
||||||
|
+ "}";
|
||||||
|
else
|
||||||
|
parameter = "{"
|
||||||
+ "\"id\":\"SUBJECT\","
|
+ "\"id\":\"SUBJECT\","
|
||||||
+ "\"id2\":\"OBJECT\""
|
+ "\"id2\":\"OBJECT\""
|
||||||
+ "}";
|
+ "}";
|
||||||
|
|
||||||
// replace those values
|
// replace those values
|
||||||
parameter = parameter.replace("SUBJECT", datasetIdSubject);
|
parameter = parameter.replace("SUBJECT", datasetIdSubject);
|
||||||
|
if(datasetIdObject != null && !datasetIdObject.isEmpty())
|
||||||
parameter = parameter.replace("OBJECT", datasetIdObject);
|
parameter = parameter.replace("OBJECT", datasetIdObject);
|
||||||
|
|
||||||
logger.debug("API request for delete relationship is going to be " + parameter);
|
logger.debug("API request for getting relationship is going to be " + parameter);
|
||||||
|
|
||||||
HttpPost request = new HttpPost(CKAN_CATALOGUE_URL + path);
|
HttpPost request = new HttpPost(CKAN_CATALOGUE_URL + path);
|
||||||
request.addHeader("Authorization", apiKey);
|
request.addHeader("Authorization", apiKey);
|
||||||
|
|
|
@ -16,13 +16,12 @@ package org.gcube.datacatalogue.ckanutillibrary.models;
|
||||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
*/
|
*/
|
||||||
public enum DatasetRelationships {
|
public enum DatasetRelationships {
|
||||||
|
|
||||||
depends_on,
|
depends_on,
|
||||||
// dependency_of,
|
dependency_of,
|
||||||
derives_from,
|
derives_from,
|
||||||
// has_derivation,
|
has_derivation,
|
||||||
child_of,
|
child_of,
|
||||||
// parent_of,
|
parent_of,
|
||||||
links_to
|
links_to,
|
||||||
// linked_from
|
linked_from
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ public class TestCKanLib {
|
||||||
private CkanUtilsFactory factory;
|
private CkanUtilsFactory factory;
|
||||||
private String scope = "/gcube/devsec/devVRE";
|
private String scope = "/gcube/devsec/devVRE";
|
||||||
private String testUser = "costantino_perciante";
|
private String testUser = "costantino_perciante";
|
||||||
|
String subjectId = "aa_father4";
|
||||||
|
String objectId = "bb_son4";
|
||||||
|
|
||||||
//@Before
|
//@Before
|
||||||
public void before(){
|
public void before(){
|
||||||
|
@ -28,21 +30,25 @@ public class TestCKanLib {
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Test
|
//@Test
|
||||||
public void datasetsRelationshipCreateDelete() throws Exception{
|
public void datasetsRelationshipCreate() throws Exception{
|
||||||
|
|
||||||
CKanUtilsImpl instance = factory.getUtilsPerScope(scope);
|
CKanUtilsImpl instance = factory.getUtilsPerScope(scope);
|
||||||
|
|
||||||
String subjectId = "lucio_organization";
|
DatasetRelationships relation = DatasetRelationships.parent_of;
|
||||||
String objectId = "test_for_visibility";
|
|
||||||
DatasetRelationships relation = DatasetRelationships.depends_on;
|
|
||||||
|
|
||||||
boolean resC = instance.createDatasetRelationship(subjectId, objectId, relation, "Comment for this relationship", instance.getApiKeyFromUsername(testUser));
|
boolean resC = instance.createDatasetRelationship(subjectId, objectId, relation, "Comment for this relationship", instance.getApiKeyFromUsername(testUser));
|
||||||
|
|
||||||
Thread.sleep(500);
|
logger.debug("Res is " + resC);
|
||||||
|
}
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void datasetsRelationshipDelete() throws Exception{
|
||||||
|
|
||||||
|
CKanUtilsImpl instance = factory.getUtilsPerScope(scope);
|
||||||
|
DatasetRelationships relation = DatasetRelationships.child_of;
|
||||||
|
|
||||||
boolean resD = instance.deleteDatasetRelationship(subjectId, objectId, relation, instance.getApiKeyFromUsername(testUser));
|
boolean resD = instance.deleteDatasetRelationship(subjectId, objectId, relation, instance.getApiKeyFromUsername(testUser));
|
||||||
|
|
||||||
logger.debug("ResC is " + resC);
|
|
||||||
logger.debug("ResD is " + resD);
|
logger.debug("ResD is " + resD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,9 +57,6 @@ public class TestCKanLib {
|
||||||
|
|
||||||
CKanUtilsImpl instance = factory.getUtilsPerScope(scope);
|
CKanUtilsImpl instance = factory.getUtilsPerScope(scope);
|
||||||
|
|
||||||
String subjectId = "lucio_organization";
|
|
||||||
String objectId = "test_for_visibility";
|
|
||||||
|
|
||||||
List<CkanDatasetRelationship> res = instance.getRelationshipDatasets(subjectId, objectId, instance.getApiKeyFromUsername(testUser));
|
List<CkanDatasetRelationship> res = instance.getRelationshipDatasets(subjectId, objectId, instance.getApiKeyFromUsername(testUser));
|
||||||
|
|
||||||
logger.debug("Relationships " + res);
|
logger.debug("Relationships " + res);
|
||||||
|
|
Loading…
Reference in New Issue