From d822121adffbae22fea482c88af7cea5e0a3f69e Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 9 Nov 2020 15:47:59 +0100 Subject: [PATCH] Added support to request contexts uuids in instances header #20012 --- .../client/ResourceRegistryClientFactory.java | 21 +++++++++++- .../client/ResourceRegistryClientImpl.java | 34 ++++++++++++++----- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientFactory.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientFactory.java index b1dceaa..e51267e 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientFactory.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientFactory.java @@ -24,14 +24,33 @@ public class ResourceRegistryClientFactory { protected static boolean HIERARCHICAL_MODE; - public static boolean isHierarchicalMode() { + protected static boolean isHierarchicalMode() { return ResourceRegistryClientFactory.HIERARCHICAL_MODE; } + /** + * The affected methods are {@link ResourceRegistryClient} instances safe methods i.e. read* and exists* + * @param hierarchicalMode + */ public static void setHierarchicalMode(boolean hierarchicalMode) { ResourceRegistryClientFactory.HIERARCHICAL_MODE = hierarchicalMode; } + protected static boolean INCLUDE_CONTEXTS_IN_INSTANCES_HEADER; + + protected static boolean includeContextsInInstanceHeader() { + return ResourceRegistryClientFactory.INCLUDE_CONTEXTS_IN_INSTANCES_HEADER; + } + + /** + * The affected methods are {@link ResourceRegistryClient} instances safe methods i.e. read* and exists* + * @param hierarchicalMode + */ + public static void includeContextsInInstanceHeader(boolean includeContextsInInstancesHeader) { + ResourceRegistryClientFactory.INCLUDE_CONTEXTS_IN_INSTANCES_HEADER = includeContextsInInstancesHeader; + } + + protected static List addresses; static { 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 fc25e0b..54f5156 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java @@ -44,20 +44,36 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { protected final String address; - private void checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{ - checkHierarchicalMode(gxHTTPStringRequest, null); + private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{ + return includeAdditionalQueryParameters(gxHTTPStringRequest, null); } - private void checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest, Map queryParams) throws UnsupportedEncodingException{ + private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest, Map queryParams) throws UnsupportedEncodingException{ + gxHTTPStringRequest = checkHierarchicalMode(gxHTTPStringRequest, queryParams); + return checkIncludeContextsInInstanceHeader(gxHTTPStringRequest, queryParams); + } + + private GXHTTPStringRequest checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest, Map queryParams) throws UnsupportedEncodingException{ if(ResourceRegistryClientFactory.isHierarchicalMode()) { if(queryParams==null) { queryParams = new HashMap<>(); } queryParams.put(AccessPath.HIERARCHICAL_MODE_PARAM, Boolean.toString(true)); } - gxHTTPStringRequest.queryParams(queryParams); + return gxHTTPStringRequest.queryParams(queryParams); } + private GXHTTPStringRequest checkIncludeContextsInInstanceHeader(GXHTTPStringRequest gxHTTPStringRequest, Map queryParams) throws UnsupportedEncodingException{ + if(ResourceRegistryClientFactory.includeContextsInInstanceHeader()) { + if(queryParams==null) { + queryParams = new HashMap<>(); + } + queryParams.put(AccessPath.INCLUDE_CONTEXTS_IN_HEADER_PARAM, Boolean.toString(true)); + } + return gxHTTPStringRequest.queryParams(queryParams); + } + + protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() { @Override @@ -218,7 +234,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(uuid.toString()); - checkHierarchicalMode(gxHTTPStringRequest); + includeAdditionalQueryParameters(gxHTTPStringRequest); HttpURLConnection httpURLConnection = gxHTTPStringRequest.head(); HTTPUtility.getResponse(String.class, httpURLConnection); @@ -260,7 +276,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(uuid.toString()); - checkHierarchicalMode(gxHTTPStringRequest); + includeAdditionalQueryParameters(gxHTTPStringRequest); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); String ret = HTTPUtility.getResponse(String.class, httpURLConnection); @@ -302,7 +318,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { Map parameters = new HashMap<>(); parameters.put(AccessPath.POLYMORPHIC_PARAM, polymorphic.toString()); - checkHierarchicalMode(gxHTTPStringRequest, parameters); + includeAdditionalQueryParameters(gxHTTPStringRequest, parameters); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); @@ -349,7 +365,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { parameters.put(AccessPath.FETCH_PLAN_PARAM, fetchPlan); } - checkHierarchicalMode(gxHTTPStringRequest, parameters); + includeAdditionalQueryParameters(gxHTTPStringRequest, parameters); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); @@ -399,7 +415,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { parameters.put(AccessPath.REFERENCE_PARAM, referenceEntity.toString()); } - checkHierarchicalMode(gxHTTPStringRequest, parameters); + includeAdditionalQueryParameters(gxHTTPStringRequest, parameters); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();