From 79f4fe330b1b02d231c03e312ea9b967a164ea91 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 5 Jul 2021 17:32:29 +0200 Subject: [PATCH] Reordered methods --- .../client/ResourceRegistryClient.java | 11 ++- .../client/ResourceRegistryClientImpl.java | 86 +++++++++---------- 2 files changed, 48 insertions(+), 49 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClient.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClient.java index ab54080..0bab975 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClient.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClient.java @@ -25,6 +25,11 @@ import org.gcube.informationsystem.types.reference.Type; */ public interface ResourceRegistryClient { + public List getInstances(Class clazz, Boolean polymorphic) + throws ResourceRegistryException; + + public String getInstances(String type, Boolean polymorphic) throws ResourceRegistryException; + public boolean exists(Class clazz, UUID uuid) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException; @@ -37,12 +42,6 @@ public interface ResourceRegistryClient { public String getInstance(String type, UUID uuid) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException; - public List getInstances(Class clazz, Boolean polymorphic) - throws ResourceRegistryException; - - public String getInstances(String type, Boolean polymorphic) throws ResourceRegistryException; - - public , F extends Facet> List getResourcesFromReferenceFacet( Class resourceClass, Class consistsOfClass, Class facetClass, F referenceFacet, boolean polymorphic) throws ResourceRegistryException; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java index 60fda21..547061e 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java @@ -216,6 +216,49 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { } } + @SuppressWarnings("unchecked") + @Override + public List getInstances(Class clazz, Boolean polymorphic) + throws ResourceRegistryException { + String type = Utility.getTypeName(clazz); + String ret = getInstances(type, polymorphic); + try { + return (List) ElementMapper.unmarshalList(Resource.class, ret); + } catch(Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public String getInstances(String type, Boolean polymorphic) throws ResourceRegistryException { + try { + logger.info("Going to get all instances of {} ", type); + GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address); + gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName()); + gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8); + gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART); + gxHTTPStringRequest.path(AccessPath.INSTANCES_PATH_PART); + gxHTTPStringRequest.path(type); + + Map parameters = new HashMap<>(); + parameters.put(AccessPath.POLYMORPHIC_PARAM, polymorphic.toString()); + includeAdditionalQueryParameters(gxHTTPStringRequest, parameters); + + HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); + + String ret = HTTPUtility.getResponse(String.class, httpURLConnection); + + logger.debug("Got instances of {} are {}", type, ret); + return ret; + } catch(ResourceRegistryException e) { + // logger.trace("Error while getting {} instances", type, e); + throw e; + } catch(Exception e) { + // logger.trace("Error while getting {} instances", type, e); + throw new RuntimeException(e); + } + } + @Override public boolean exists(Class clazz, UUID uuid) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { @@ -294,49 +337,6 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { } } - @SuppressWarnings("unchecked") - @Override - public List getInstances(Class clazz, Boolean polymorphic) - throws ResourceRegistryException { - String type = Utility.getTypeName(clazz); - String ret = getInstances(type, polymorphic); - try { - return (List) ElementMapper.unmarshalList(Resource.class, ret); - } catch(Exception e) { - throw new RuntimeException(e); - } - } - - @Override - public String getInstances(String type, Boolean polymorphic) throws ResourceRegistryException { - try { - logger.info("Going to get all instances of {} ", type); - GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address); - gxHTTPStringRequest.from(ResourceRegistryClient.class.getSimpleName()); - gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8); - gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART); - gxHTTPStringRequest.path(AccessPath.INSTANCES_PATH_PART); - gxHTTPStringRequest.path(type); - - Map parameters = new HashMap<>(); - parameters.put(AccessPath.POLYMORPHIC_PARAM, polymorphic.toString()); - includeAdditionalQueryParameters(gxHTTPStringRequest, parameters); - - HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); - - String ret = HTTPUtility.getResponse(String.class, httpURLConnection); - - logger.debug("Got instances of {} are {}", type, ret); - return ret; - } catch(ResourceRegistryException e) { - // logger.trace("Error while getting {} instances", type, e); - throw e; - } catch(Exception e) { - // logger.trace("Error while getting {} instances", type, e); - throw new RuntimeException(e); - } - } - @Override public String query(String query, int limit, String fetchPlan) throws InvalidQueryException, ResourceRegistryException {