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 a7e64ce..70eccbb 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientFactory.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientFactory.java @@ -25,6 +25,16 @@ public class ResourceRegistryClientFactory { protected static Map clients; + protected static boolean hierarchicalMode; + + public static boolean isHierarchicalMode() { + return ResourceRegistryClientFactory.hierarchicalMode; + } + + public static void setHierarchicalMode(boolean hierarchicalMode) { + ResourceRegistryClientFactory.hierarchicalMode = hierarchicalMode; + } + static { clients = new HashMap<>(); } @@ -33,8 +43,11 @@ public class ResourceRegistryClientFactory { protected static void forceToURL(String url){ FORCED_URL = url; + hierarchicalMode = false; } + + private static String classFormat = "$resource/Profile/ServiceClass/text() eq '%1s'"; private static String nameFormat = "$resource/Profile/ServiceName/text() eq '%1s'"; private static String statusFormat = "$resource/Profile/DeploymentData/Status/text() eq 'ready'"; 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 01796c6..b8c8f14 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java @@ -1,5 +1,6 @@ package org.gcube.informationsystem.resourceregistry.client; +import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.util.HashMap; import java.util.List; @@ -45,6 +46,20 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { this.address = address; } + private void checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{ + checkHierarchicalMode(gxHTTPStringRequest, null); + } + + private void 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); + } + @Override public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException { try { @@ -187,6 +202,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(uuid.toString()); + checkHierarchicalMode(gxHTTPStringRequest); + HttpURLConnection httpURLConnection = gxHTTPStringRequest.head(); HTTPUtility.getResponse(String.class, httpURLConnection); @@ -227,6 +244,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(uuid.toString()); + checkHierarchicalMode(gxHTTPStringRequest); + HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); String ret = HTTPUtility.getResponse(String.class, httpURLConnection); @@ -267,7 +286,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { Map parameters = new HashMap<>(); parameters.put(AccessPath.POLYMORPHIC_PARAM, polymorphic.toString()); - gxHTTPStringRequest.queryParams(parameters); + checkHierarchicalMode(gxHTTPStringRequest, parameters); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); @@ -314,7 +333,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { parameters.put(AccessPath.FETCH_PLAN_PARAM, fetchPlan); } - gxHTTPStringRequest.queryParams(parameters); + checkHierarchicalMode(gxHTTPStringRequest, parameters); + HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); String ret = HTTPUtility.getResponse(String.class, httpURLConnection); @@ -363,7 +383,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { parameters.put(AccessPath.REFERENCE_PARAM, referenceEntity.toString()); } - gxHTTPStringRequest.queryParams(parameters); + checkHierarchicalMode(gxHTTPStringRequest, parameters); + HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); String json = HTTPUtility.getResponse(String.class, httpURLConnection);