added getResource method

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@162550 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2018-01-24 20:28:42 +00:00
parent 8cf12d1593
commit 749f67101d
2 changed files with 25 additions and 0 deletions

View File

@ -644,4 +644,9 @@ public interface DataCatalogue {
* @return an email address for sending email to this catalogue
*/
String getCatalogueEmail();
/**
* Retrieve a resource by id
*/
CkanResource getResource(String id, String apiKey);
}

View File

@ -1886,6 +1886,26 @@ public class DataCatalogueImpl implements DataCatalogue{
}
return false;
}
@Override
public CkanResource getResource(String id, String apiKey) {
logger.info("Request ckan resource with id " + id);
// checks
checkNotNull(id);
checkArgument(!id.isEmpty());
checkNotNull(apiKey);
checkArgument(!apiKey.isEmpty());
try{
CheckedCkanClient client = new CheckedCkanClient(CKAN_CATALOGUE_URL, apiKey);
return client.getResource(id);
}catch(Exception e){
logger.error("Unable to retrieve such resource, returning null ...", e);
}
return null;
}
@Override
public CkanDataset getDataset(String datasetId, String apiKey) {