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:
Costantino Perciante 2016-09-02 09:18:11 +00:00
parent d93fc8f59c
commit e101fe9786
4 changed files with 34 additions and 24 deletions

View File

@ -231,7 +231,8 @@ public interface CKanUtils {
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 datasetIdObject
* @param apiKey

View File

@ -1009,16 +1009,15 @@ public class CKanUtilsImpl implements CKanUtils{
return false;
}
@SuppressWarnings("unchecked")
@Override
public List<CkanDatasetRelationship> getRelationshipDatasets(
String datasetIdSubject, String datasetIdObject, String apiKey) {
// checks
checkNotNull(datasetIdSubject);
checkNotNull(datasetIdObject);
checkNotNull(apiKey);
checkArgument(!datasetIdSubject.isEmpty());
checkArgument(!datasetIdObject.isEmpty());
checkArgument(!apiKey.isEmpty());
try(CloseableHttpClient httpClient = HttpClientBuilder.create().build();){
@ -1028,17 +1027,25 @@ public class CKanUtilsImpl implements CKanUtils{
// we need to use the apis to make it
String path = "/api/3/action/package_relationships_list";
String parameter;
// Request parameters to be replaced
String parameter = "{"
+ "\"id\":\"SUBJECT\","
+ "\"id2\":\"OBJECT\""
+ "}";
if(datasetIdObject == null || datasetIdObject.isEmpty())
parameter = "{"
+ "\"id\":\"SUBJECT\""
+ "}";
else
parameter = "{"
+ "\"id\":\"SUBJECT\","
+ "\"id2\":\"OBJECT\""
+ "}";
// replace those values
parameter = parameter.replace("SUBJECT", datasetIdSubject);
parameter = parameter.replace("OBJECT", datasetIdObject);
if(datasetIdObject != null && !datasetIdObject.isEmpty())
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);
request.addHeader("Authorization", apiKey);

View File

@ -16,13 +16,12 @@ package org.gcube.datacatalogue.ckanutillibrary.models;
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public enum DatasetRelationships {
depends_on,
// dependency_of,
dependency_of,
derives_from,
// has_derivation,
has_derivation,
child_of,
// parent_of,
links_to
// linked_from
parent_of,
links_to,
linked_from
}

View File

@ -21,6 +21,8 @@ public class TestCKanLib {
private CkanUtilsFactory factory;
private String scope = "/gcube/devsec/devVRE";
private String testUser = "costantino_perciante";
String subjectId = "aa_father4";
String objectId = "bb_son4";
//@Before
public void before(){
@ -28,21 +30,25 @@ public class TestCKanLib {
}
//@Test
public void datasetsRelationshipCreateDelete() throws Exception{
public void datasetsRelationshipCreate() throws Exception{
CKanUtilsImpl instance = factory.getUtilsPerScope(scope);
String subjectId = "lucio_organization";
String objectId = "test_for_visibility";
DatasetRelationships relation = DatasetRelationships.depends_on;
DatasetRelationships relation = DatasetRelationships.parent_of;
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));
logger.debug("ResC is " + resC);
logger.debug("ResD is " + resD);
}
@ -51,9 +57,6 @@ public class TestCKanLib {
CKanUtilsImpl instance = factory.getUtilsPerScope(scope);
String subjectId = "lucio_organization";
String objectId = "test_for_visibility";
List<CkanDatasetRelationship> res = instance.getRelationshipDatasets(subjectId, objectId, instance.getApiKeyFromUsername(testUser));
logger.debug("Relationships " + res);