From 749f67101d8172eb1b22898678e3db50070579eb Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Wed, 24 Jan 2018 20:28:42 +0000 Subject: [PATCH] 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 --- .../ckanutillibrary/server/DataCatalogue.java | 5 +++++ .../server/DataCatalogueImpl.java | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/org/gcube/datacatalogue/ckanutillibrary/server/DataCatalogue.java b/src/main/java/org/gcube/datacatalogue/ckanutillibrary/server/DataCatalogue.java index 547fe94..0b5a3e9 100644 --- a/src/main/java/org/gcube/datacatalogue/ckanutillibrary/server/DataCatalogue.java +++ b/src/main/java/org/gcube/datacatalogue/ckanutillibrary/server/DataCatalogue.java @@ -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); } diff --git a/src/main/java/org/gcube/datacatalogue/ckanutillibrary/server/DataCatalogueImpl.java b/src/main/java/org/gcube/datacatalogue/ckanutillibrary/server/DataCatalogueImpl.java index ab4ad16..139b024 100644 --- a/src/main/java/org/gcube/datacatalogue/ckanutillibrary/server/DataCatalogueImpl.java +++ b/src/main/java/org/gcube/datacatalogue/ckanutillibrary/server/DataCatalogueImpl.java @@ -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) {