From 3ea46fbac1e74e698c96cc59697bf975554adff5 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 3 Nov 2020 16:29:44 +0100 Subject: [PATCH] Rationalised code --- .../client/ResourceRegistryClientImpl.java | 98 +++++++------------ 1 file changed, 38 insertions(+), 60 deletions(-) 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 b8c8f14..bb66dae 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java @@ -60,66 +60,6 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { gxHTTPStringRequest.queryParams(queryParams); } - @Override - public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException { - try { - logger.info("Going to get current {} ", Context.NAME); - 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.CONTEXTS_PATH_PART); - gxHTTPStringRequest.path(AccessPath.CURRENT_CONTEXT); - - HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); - Context context = HTTPUtility.getResponse(Context.class, httpURLConnection); - - logger.debug("Got Context is {}", ElementMapper.marshal(context)); - return context; - } catch(ResourceRegistryException e) { - // logger.trace("Error while getting {} schema for {}", polymorphic ? - // AccessPath.POLYMORPHIC_PARAM + " " : "", - // type, e); - throw e; - } catch(Exception e) { - // logger.trace("Error while getting {}schema for {}", polymorphic ? - // AccessPath.POLYMORPHIC_PARAM + " " : "", - // type, e); - throw new RuntimeException(e); - } - } - - - @Override - public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException { - try { - logger.info("Going to get {} with UUID {}", Context.NAME, uuid.toString()); - - 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.CONTEXTS_PATH_PART); - gxHTTPStringRequest.path(uuid.toString()); - - HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); - Context context = HTTPUtility.getResponse(Context.class, httpURLConnection); - - logger.debug("Got Context is {}", ElementMapper.marshal(context)); - return context; - } catch(ResourceRegistryException e) { - // logger.trace("Error while getting {} schema for {}", polymorphic ? - // AccessPath.POLYMORPHIC_PARAM + " " : "", - // type, e); - throw e; - } catch(Exception e) { - // logger.trace("Error while getting {}schema for {}", polymorphic ? - // AccessPath.POLYMORPHIC_PARAM + " " : "", - // type, e); - throw new RuntimeException(e); - } - } - @Override public List getAllContext() throws ContextNotFoundException, ResourceRegistryException { try { @@ -148,6 +88,44 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { } } + protected Context getContext(String id) throws ContextNotFoundException, ResourceRegistryException { + try { + logger.info("Going to get current {} ", Context.NAME); + 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.CONTEXTS_PATH_PART); + gxHTTPStringRequest.path(id); + + HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); + Context context = HTTPUtility.getResponse(Context.class, httpURLConnection); + + logger.debug("Got Context is {}", ElementMapper.marshal(context)); + return context; + } catch(ResourceRegistryException e) { + // logger.trace("Error while getting {} schema for {}", polymorphic ? + // AccessPath.POLYMORPHIC_PARAM + " " : "", + // type, e); + throw e; + } catch(Exception e) { + // logger.trace("Error while getting {}schema for {}", polymorphic ? + // AccessPath.POLYMORPHIC_PARAM + " " : "", + // type, e); + throw new RuntimeException(e); + } + } + + @Override + public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException { + return getContext(uuid.toString()); + } + + @Override + public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException { + return getContext(AccessPath.CURRENT_CONTEXT); + } + @Override public List getSchema(Class clazz, Boolean polymorphic) throws SchemaNotFoundException, ResourceRegistryException {