From 64ec6c94d59b07fefe256bd44096e2307f5d0a6f Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 5 May 2023 12:20:57 +0200 Subject: [PATCH] Added missing query parameters to requests --- .../ResourceRegistryPublisherImpl.java | 60 ++++++++++++++++--- 1 file changed, 53 insertions(+), 7 deletions(-) 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 bffe928..94c1518 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java @@ -133,7 +133,6 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher this.allMeta = allMeta; } - private void addOptionalQueryParameters(Map queryParams) throws UnsupportedEncodingException { addHierarchicalMode(queryParams); addIncludeContexts(queryParams); @@ -208,6 +207,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher public ResourceRegistryPublisherImpl(String address, boolean sharedContextCache) { this.address = address; this.headers = new HashMap<>(); + this.hierarchicalMode = false; + this.includeContexts = false; + this.includeMeta = false; + this.allMeta = false; if(sharedContextCache) { contextCache = ContextCache.getInstance(); }else { @@ -216,6 +219,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher contextCache.setContextCacheRenewal(contextCacheRenewal); } + /** + * It reads all the contexts from server. + * The cache used for contexts is bypassed and not updated. + * @return All Contexts read from server + * @throws ResourceRegistryException + */ public List getAllContextFromServer() throws ResourceRegistryException { try { logger.info("Going to read all {}s", Context.NAME); @@ -224,6 +233,11 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART); gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART); + Map parameters = new HashMap<>(); + addIncludeMeta(parameters); + addIncludeAllMeta(parameters); + gxHTTPStringRequest.queryParams(parameters); + HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); String ret = HTTPUtility.getResponse(String.class, httpURLConnection); @@ -248,15 +262,32 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher return contextCache.getContexts(); } - protected Context getContextFromServer(String id) throws ContextNotFoundException, ResourceRegistryException { + /** + * It reads the context from server. + * The cache used for contexts is bypassed and not updated. + * @param uuid + * @return the Contexts read from server + * @throws ContextNotFoundException + * @throws ResourceRegistryException + */ + public Context getContextFromServer(UUID uuid) throws ContextNotFoundException, ResourceRegistryException { + return getContextFromServer(uuid.toString()); + } + + protected Context getContextFromServer(String uuid) throws ContextNotFoundException, ResourceRegistryException { try { logger.info("Going to get current {} ", Context.NAME); GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest(); gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8); gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART); gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART); - gxHTTPStringRequest.path(id); + gxHTTPStringRequest.path(uuid); + Map parameters = new HashMap<>(); + addIncludeMeta(parameters); + addIncludeAllMeta(parameters); + gxHTTPStringRequest.queryParams(parameters); + HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); Context context = HTTPUtility.getResponse(Context.class, httpURLConnection); @@ -357,7 +388,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(uuid.toString()); - includeAdditionalQueryParameters(gxHTTPStringRequest); + Map parameters = new HashMap<>(); + addIncludeContexts(parameters); + addIncludeMeta(parameters); + addIncludeAllMeta(parameters); + gxHTTPStringRequest.queryParams(parameters); + HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(json); String ret = HTTPUtility.getResponse(String.class, httpURLConnection); @@ -595,7 +631,11 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(uuid.toString()); - includeAdditionalQueryParameters(gxHTTPStringRequest); + Map parameters = new HashMap<>(); + addIncludeContexts(parameters); + addIncludeMeta(parameters); + addIncludeAllMeta(parameters); + gxHTTPStringRequest.queryParams(parameters); HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(json); String ret = HTTPUtility.getResponse(String.class, httpURLConnection); @@ -870,7 +910,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher Boolean forceAddToContext = getCurrentContextUUID().compareTo(contextUUID)==0; queryParams.put(SharingPath.FORCE_ADD_TO_CONTEXT_QUERY_PARAMETER, forceAddToContext.toString()); - includeAdditionalQueryParameters(gxHTTPStringRequest, queryParams); + addIncludeMeta(queryParams); + addIncludeAllMeta(queryParams); + addIncludeContexts(queryParams); + gxHTTPStringRequest.queryParams(queryParams); HttpURLConnection httpURLConnection = gxHTTPStringRequest.post(); String jsonArray = HTTPUtility.getResponse(String.class, httpURLConnection); @@ -936,7 +979,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher queryParams.put(SharingPath.OPERATION_QUERY_PARAMETER, SharingOperation.REMOVE.name()); queryParams.put(SharingPath.DRY_RUN_QUERY_QUERY_PARAMETER, dryRun.toString()); - includeAdditionalQueryParameters(gxHTTPStringRequest, queryParams); + addIncludeMeta(queryParams); + addIncludeAllMeta(queryParams); + addIncludeContexts(queryParams); + gxHTTPStringRequest.queryParams(queryParams); HttpURLConnection httpURLConnection = gxHTTPStringRequest.post();