diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClient.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClient.java index 4edd7c9..094e61f 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClient.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClient.java @@ -21,16 +21,13 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.Cont import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.request.RequestInfo; import org.gcube.informationsystem.types.reference.Type; /** * @author Luca Frosini (ISTI - CNR) */ -public interface ResourceRegistryClient { - - public boolean isHierarchicalMode(); - - public void setHierarchicalMode(boolean hierarchicalMode); +public interface ResourceRegistryClient extends RequestInfo { /** * Use {@link #includeContexts()} instead @@ -46,10 +43,6 @@ public interface ResourceRegistryClient { @Deprecated public void setIncludeContextsInHeader(boolean includeContexts); - public boolean includeContexts(); - - public void includeContexts(boolean includeContexts); - public void addHeader(String name, String value); 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 2e53ab0..73b8b11 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java @@ -15,11 +15,13 @@ import org.gcube.common.gxhttp.reference.GXConnection; import org.gcube.common.gxhttp.request.GXHTTPStringRequest; import org.gcube.common.http.GXHTTPUtility; import org.gcube.informationsystem.base.reference.Direction; +import org.gcube.informationsystem.base.reference.IdentifiableElement; import org.gcube.informationsystem.contexts.reference.entities.Context; import org.gcube.informationsystem.model.reference.ERElement; import org.gcube.informationsystem.model.reference.entities.Entity; import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Resource; +import org.gcube.informationsystem.model.reference.properties.Metadata; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; import org.gcube.informationsystem.model.reference.relations.Relation; @@ -61,9 +63,27 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { protected Map headers; + /** + * Track if the client must request the hierarchicalMode + */ protected boolean hierarchicalMode; + + /** + * Track if the client must request to include contexts + */ protected boolean includeContexts; + /** + * Track if the client must request to include {@link Metadata} + */ + protected boolean includeMeta; + + /** + * Track if the client must request to include {@link Metadata} in all + * {@link IdentifiableElement} or just in the root instance + */ + protected boolean allMeta; + protected ContextCache contextCache; @Override @@ -85,7 +105,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { @Deprecated @Override public void setIncludeContextsInHeader(boolean includeContexts) { - includeContexts(includeContexts); + setIncludeContexts(includeContexts); } @Override @@ -94,37 +114,69 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { } @Override - public void includeContexts(boolean includeContexts) { + public void setIncludeContexts(boolean includeContexts) { this.includeContexts = includeContexts; } + public boolean includeMeta() { + return includeMeta; + } + + public void setIncludeMeta(boolean includeMeta) { + this.includeMeta = includeMeta; + } + + public boolean allMeta() { + return allMeta; + } + + public void setAllMeta(boolean allMeta) { + this.allMeta = allMeta; + } + + + private void addOptionalQueryParameters(Map queryParams) throws UnsupportedEncodingException { + addHierarchicalMode(queryParams); + addIncludeContexts(queryParams); + addIncludeMeta(queryParams); + addIncludeAllMeta(queryParams); + } + private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{ - return includeAdditionalQueryParameters(gxHTTPStringRequest, null); + Map queryParams = new HashMap<>(); + return includeAdditionalQueryParameters(gxHTTPStringRequest, queryParams); } private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest, Map queryParams) throws UnsupportedEncodingException{ - gxHTTPStringRequest = checkHierarchicalMode(gxHTTPStringRequest, queryParams); - return checkIncludeContextsInInstance(gxHTTPStringRequest, queryParams); + if(queryParams==null) { + queryParams = new HashMap<>(); + } + addOptionalQueryParameters(queryParams); + return gxHTTPStringRequest.queryParams(queryParams); } - private GXHTTPStringRequest checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest, Map queryParams) throws UnsupportedEncodingException{ + private void addHierarchicalMode(Map queryParams) throws UnsupportedEncodingException{ if(hierarchicalMode) { - if(queryParams==null) { - queryParams = new HashMap<>(); - } queryParams.put(AccessPath.HIERARCHICAL_MODE_QUERY_PARAMETER, Boolean.toString(hierarchicalMode)); } - return gxHTTPStringRequest.queryParams(queryParams); } - private GXHTTPStringRequest checkIncludeContextsInInstance(GXHTTPStringRequest gxHTTPStringRequest, Map queryParams) throws UnsupportedEncodingException{ + private void addIncludeContexts(Map queryParams) throws UnsupportedEncodingException{ if(includeContexts) { - if(queryParams==null) { - queryParams = new HashMap<>(); - } queryParams.put(AccessPath.INCLUDE_CONTEXTS_QUERY_PARAMETER, Boolean.toString(includeContexts)); } - return gxHTTPStringRequest.queryParams(queryParams); + } + + private void addIncludeMeta(Map queryParams) throws UnsupportedEncodingException{ + if(includeMeta) { + queryParams.put(AccessPath.INCLUDE_META_QUERY_PARAMETER, Boolean.toString(includeMeta)); + } + } + + private void addIncludeAllMeta(Map queryParams) throws UnsupportedEncodingException{ + if(allMeta) { + queryParams.put(AccessPath.INCLUDE_META_IN_ALL_INSTANCES_QUERY_PARAMETER, Boolean.toString(allMeta)); + } } protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() { @@ -158,6 +210,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { this.address = address; this.hierarchicalMode = false; this.includeContexts = false; + this.includeMeta = false; + this.allMeta = false; this.headers = new HashMap<>(); if(sharedContextCache) { contextCache = ContextCache.getInstance(); @@ -427,7 +481,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(uuid.toString()); - includeAdditionalQueryParameters(gxHTTPStringRequest); + Map queryParams = new HashMap<>(); + addHierarchicalMode(queryParams); + gxHTTPStringRequest.queryParams(queryParams); HttpURLConnection httpURLConnection = gxHTTPStringRequest.head(); HTTPUtility.getResponse(String.class, httpURLConnection); @@ -507,7 +563,12 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { parameters.put(AccessPath.Q_QUERY_PARAMETER, query); parameters.put(AccessPath.RAW_QUERY_PARAMETER, Boolean.toString(raw)); - includeAdditionalQueryParameters(gxHTTPStringRequest, parameters); + if(raw) { + addHierarchicalMode(parameters); + gxHTTPStringRequest.queryParams(parameters); + } else { + includeAdditionalQueryParameters(gxHTTPStringRequest, parameters); + } HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();