diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java index e98d7b5..46ca155 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java @@ -48,7 +48,7 @@ import com.tinkerpop.blueprints.Direction; * @author Luca Frosini (ISTI - CNR) */ @Path(AccessPath.ACCESS_PATH_PART) -public class Access { +public class Access extends BaseRest { private static Logger logger = LoggerFactory.getLogger(Access.class); @@ -180,7 +180,7 @@ public class Access { @QueryParam(AccessPath.POLYMORPHIC_PARAM) @DefaultValue("true") Boolean polymorphic) throws NotFoundException, ResourceRegistryException { logger.info("Requested all {}instances of {}", polymorphic ? AccessPath.POLYMORPHIC_PARAM + " " : "", type); - + setHierarchicalMode(); /* List pathValues = new ArrayList<>(); pathValues.add(AccessPath.INSTANCES_PATH_PART); @@ -207,8 +207,9 @@ public class Access { @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) public Response instanceExists(@PathParam(AccessPath.TYPE_PATH_PARAM) String type, @PathParam(AccessPath.UUID_PATH_PARAM) String uuid) throws NotFoundException, ResourceRegistryException { - logger.info("Requested to check if {} with id {} exists", type, uuid); + setHierarchicalMode(); + /* List pathValues = new ArrayList<>(); pathValues.add(AccessPath.INSTANCES_PATH_PART); @@ -252,6 +253,8 @@ public class Access { public String getInstance(@PathParam(AccessPath.TYPE_PATH_PARAM) String type, @PathParam(AccessPath.UUID_PATH_PARAM) String uuid) throws NotFoundException, ResourceRegistryException { logger.info("Requested to read {} with id {}", type, uuid); + setHierarchicalMode(); + /* List pathValues = new ArrayList<>(); pathValues.add(AccessPath.INSTANCES_PATH_PART); @@ -300,6 +303,7 @@ public class Access { @QueryParam(AccessPath.RAW_PARAM) @DefaultValue(AccessPath.DEFAULT_RAW_PARAM) Boolean raw) throws InvalidQueryException { logger.info("Requested query (fetch plan {}, limit : {}, Raw : raw):\n{}", fetchPlan, limit, query, raw); + setHierarchicalMode(); //setRESTCalledMethodLocal(HTTPMETHOD.GET, AccessPath.QUERY_PATH_PART); CalledMethodProvider.instance.set("rawQuery"); @@ -347,6 +351,7 @@ public class Access { logger.info("Requested {} instances having a(n) {} ({}={}} with {} ({}={})", resourcetype, relationType, AccessPath.DIRECTION_PARAM, direction, referenceType, AccessPath.POLYMORPHIC_PARAM, polymorphic); + setHierarchicalMode(); /* List pathValues = new ArrayList<>(); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/BaseRest.java b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/BaseRest.java new file mode 100644 index 0000000..5d52b14 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/BaseRest.java @@ -0,0 +1,36 @@ +package org.gcube.informationsystem.resourceregistry.rest; + +import java.util.List; + +import javax.ws.rs.core.Context; +import javax.ws.rs.core.UriInfo; + +import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath; +import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BaseRest { + + private static Logger logger = LoggerFactory.getLogger(InstancesManager.class); + + @Context + protected UriInfo uriInfo; + + protected void setHierarchicalMode() { + try { + List hierarchicalQueryParameterList = uriInfo.getQueryParameters().get(InstancePath.HIERARCHICAL_MODE_PARAM); + if(hierarchicalQueryParameterList!=null && hierarchicalQueryParameterList.size()>0) { + String hierarchicalBooleanString = hierarchicalQueryParameterList.get(0); + boolean hierarchical = Boolean.valueOf(hierarchicalBooleanString); + if(hierarchical) { + logger.info("The request was performed in hierarchical mode. Going to set it."); + ContextUtility.getHierarchicalMode().set(hierarchical); + } + } + }catch (Throwable t) { + logger.warn("Unable to properly set the Hierarchical Mode is set", t.getMessage()); + } + } + +} diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/InstancesManager.java b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/InstancesManager.java index 0106036..a48a2bf 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/InstancesManager.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/InstancesManager.java @@ -32,7 +32,7 @@ import org.slf4j.LoggerFactory; * @author Luca Frosini (ISTI - CNR) */ @Path(InstancePath.INSTANCES_PATH_PART) -public class InstancesManager { +public class InstancesManager extends BaseRest { private static Logger logger = LoggerFactory.getLogger(InstancesManager.class); @@ -69,6 +69,7 @@ public class InstancesManager { @QueryParam(InstancePath.POLYMORPHIC_PARAM) @DefaultValue("true") Boolean polymorphic) throws NotFoundException, ResourceRegistryException { logger.info("Requested all {}instances of {}", polymorphic ? InstancePath.POLYMORPHIC_PARAM + " " : "", type); + setHierarchicalMode(); /* Map map = new HashMap(); map.put(InstancePath.POLYMORPHIC_PARAM, polymorphic.toString()); @@ -94,6 +95,7 @@ public class InstancesManager { @PathParam(AccessPath.UUID_PATH_PARAM) String uuid) throws NotFoundException, ResourceRegistryException { logger.info("Requested to check if {} with id {} exists", type, uuid); //setRESTCalledMethod(HTTPMETHOD.HEAD, type, true); + setHierarchicalMode(); CalledMethodProvider.instance.set("existInstance"); @SuppressWarnings("rawtypes") @@ -130,6 +132,7 @@ public class InstancesManager { public String read(@PathParam(AccessPath.TYPE_PATH_PARAM) String type, @PathParam(AccessPath.UUID_PATH_PARAM) String uuid) throws NotFoundException, ResourceRegistryException { logger.info("Requested to read {} with id {}", type, uuid); + setHierarchicalMode(); // setRESTCalledMethod(HTTPMETHOD.GET, type, true); CalledMethodProvider.instance.set("readInstance");