diff --git a/pom.xml b/pom.xml index 9b933be..0601872 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,6 @@ org.gcube.information-system resource-registry-api - [4.1.0-SNAPSHOT, 5.0.0-SNAPSHOT] org.gcube.information-system diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherFactory.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherFactory.java index 69b90b4..25b84ce 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherFactory.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherFactory.java @@ -28,10 +28,28 @@ public class ResourceRegistryPublisherFactory { return ResourceRegistryPublisherFactory.HIERARCHICAL_MODE; } + /** + * The affected methods are {@link ResourceRegistryPublisher} safe methods i.e. read* and exists* + * @param hierarchicalMode + */ public static void setHierarchicalMode(boolean hierarchicalMode) { ResourceRegistryPublisherFactory.HIERARCHICAL_MODE = hierarchicalMode; } + protected static boolean INCLUDE_CONTEXTS_IN_INSTANCES_HEADER; + + protected static boolean includeContextsInInstanceHeader() { + return ResourceRegistryPublisherFactory.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) { + ResourceRegistryPublisherFactory.INCLUDE_CONTEXTS_IN_INSTANCES_HEADER = includeContextsInInstancesHeader; + } + protected static List addresses; static { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java index 326a5a6..b82c607 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java @@ -44,18 +44,33 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher 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(ResourceRegistryPublisherFactory.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(ResourceRegistryPublisherFactory.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() { @@ -286,7 +301,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(uuid.toString()); - checkHierarchicalMode(gxHTTPStringRequest); + includeAdditionalQueryParameters(gxHTTPStringRequest); HttpURLConnection httpURLConnection = gxHTTPStringRequest.head(); HTTPUtility.getResponse(String.class, httpURLConnection); @@ -332,7 +347,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher gxHTTPStringRequest.path(identifiableElementTypeName); gxHTTPStringRequest.path(uuid.toString()); - checkHierarchicalMode(gxHTTPStringRequest); + includeAdditionalQueryParameters(gxHTTPStringRequest); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); String ret = HTTPUtility.getResponse(String.class, httpURLConnection);