Added the possibility to specify Hierarchical Mode

This commit is contained in:
Luca Frosini 2020-10-29 16:54:24 +01:00
parent c8109aba4c
commit 7dc12a9d3c
2 changed files with 37 additions and 3 deletions

View File

@ -25,6 +25,16 @@ public class ResourceRegistryClientFactory {
protected static Map<String, ResourceRegistryClient> clients; protected static Map<String, ResourceRegistryClient> clients;
protected static boolean hierarchicalMode;
public static boolean isHierarchicalMode() {
return ResourceRegistryClientFactory.hierarchicalMode;
}
public static void setHierarchicalMode(boolean hierarchicalMode) {
ResourceRegistryClientFactory.hierarchicalMode = hierarchicalMode;
}
static { static {
clients = new HashMap<>(); clients = new HashMap<>();
} }
@ -33,8 +43,11 @@ public class ResourceRegistryClientFactory {
protected static void forceToURL(String url){ protected static void forceToURL(String url){
FORCED_URL = url; FORCED_URL = url;
hierarchicalMode = false;
} }
private static String classFormat = "$resource/Profile/ServiceClass/text() eq '%1s'"; private static String classFormat = "$resource/Profile/ServiceClass/text() eq '%1s'";
private static String nameFormat = "$resource/Profile/ServiceName/text() eq '%1s'"; private static String nameFormat = "$resource/Profile/ServiceName/text() eq '%1s'";
private static String statusFormat = "$resource/Profile/DeploymentData/Status/text() eq 'ready'"; private static String statusFormat = "$resource/Profile/DeploymentData/Status/text() eq 'ready'";

View File

@ -1,5 +1,6 @@
package org.gcube.informationsystem.resourceregistry.client; package org.gcube.informationsystem.resourceregistry.client;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -45,6 +46,20 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
this.address = address; this.address = address;
} }
private void checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{
checkHierarchicalMode(gxHTTPStringRequest, null);
}
private void checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> 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 @Override
public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException { public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException {
try { try {
@ -187,6 +202,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString()); gxHTTPStringRequest.path(uuid.toString());
checkHierarchicalMode(gxHTTPStringRequest);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.head(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.head();
HTTPUtility.getResponse(String.class, httpURLConnection); HTTPUtility.getResponse(String.class, httpURLConnection);
@ -227,6 +244,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString()); gxHTTPStringRequest.path(uuid.toString());
checkHierarchicalMode(gxHTTPStringRequest);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
String ret = HTTPUtility.getResponse(String.class, httpURLConnection); String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
@ -267,7 +286,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
Map<String,String> parameters = new HashMap<>(); Map<String,String> parameters = new HashMap<>();
parameters.put(AccessPath.POLYMORPHIC_PARAM, polymorphic.toString()); parameters.put(AccessPath.POLYMORPHIC_PARAM, polymorphic.toString());
gxHTTPStringRequest.queryParams(parameters); checkHierarchicalMode(gxHTTPStringRequest, parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
@ -314,7 +333,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
parameters.put(AccessPath.FETCH_PLAN_PARAM, fetchPlan); parameters.put(AccessPath.FETCH_PLAN_PARAM, fetchPlan);
} }
gxHTTPStringRequest.queryParams(parameters); checkHierarchicalMode(gxHTTPStringRequest, parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
String ret = HTTPUtility.getResponse(String.class, httpURLConnection); String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
@ -363,7 +383,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
parameters.put(AccessPath.REFERENCE_PARAM, referenceEntity.toString()); parameters.put(AccessPath.REFERENCE_PARAM, referenceEntity.toString());
} }
gxHTTPStringRequest.queryParams(parameters); checkHierarchicalMode(gxHTTPStringRequest, parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
String json = HTTPUtility.getResponse(String.class, httpURLConnection); String json = HTTPUtility.getResponse(String.class, httpURLConnection);