Added missing query parameters to requests
This commit is contained in:
parent
0b6700cd40
commit
1061c80911
|
@ -8,11 +8,12 @@ import org.gcube.informationsystem.queries.templates.reference.entities.QueryTem
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.request.RequestInfo;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public interface ResourceRegistryQueryTemplateClient {
|
||||
public interface ResourceRegistryQueryTemplateClient extends RequestInfo {
|
||||
|
||||
public void addHeader(String name, String value);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.informationsystem.resourceregistry.queries.templates;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -12,12 +13,15 @@ import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
|||
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.IdentifiableElement;
|
||||
import org.gcube.informationsystem.model.reference.ERElement;
|
||||
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.QueryTemplatePath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
|
||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||
|
@ -38,6 +42,107 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
|
||||
protected Map<String, String> 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;
|
||||
|
||||
@Override
|
||||
public boolean isHierarchicalMode() {
|
||||
return hierarchicalMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHierarchicalMode(boolean hierarchicalMode) {
|
||||
this.hierarchicalMode = hierarchicalMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includeContexts() {
|
||||
return includeContexts;
|
||||
}
|
||||
|
||||
@Override
|
||||
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<String,String> queryParams) throws UnsupportedEncodingException {
|
||||
addHierarchicalMode(queryParams);
|
||||
addIncludeContexts(queryParams);
|
||||
addIncludeMeta(queryParams);
|
||||
addIncludeAllMeta(queryParams);
|
||||
}
|
||||
|
||||
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{
|
||||
Map<String,String> queryParams = new HashMap<>();
|
||||
return includeAdditionalQueryParameters(gxHTTPStringRequest, queryParams);
|
||||
}
|
||||
|
||||
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{
|
||||
if(queryParams==null) {
|
||||
queryParams = new HashMap<>();
|
||||
}
|
||||
addOptionalQueryParameters(queryParams);
|
||||
return gxHTTPStringRequest.queryParams(queryParams);
|
||||
}
|
||||
|
||||
private void addHierarchicalMode(Map<String,String> queryParams) throws UnsupportedEncodingException{
|
||||
if(hierarchicalMode) {
|
||||
queryParams.put(AccessPath.HIERARCHICAL_MODE_QUERY_PARAMETER, Boolean.toString(hierarchicalMode));
|
||||
}
|
||||
}
|
||||
|
||||
private void addIncludeContexts(Map<String,String> queryParams) throws UnsupportedEncodingException{
|
||||
if(includeContexts) {
|
||||
queryParams.put(AccessPath.INCLUDE_CONTEXTS_QUERY_PARAMETER, Boolean.toString(includeContexts));
|
||||
}
|
||||
}
|
||||
|
||||
private void addIncludeMeta(Map<String,String> queryParams) throws UnsupportedEncodingException{
|
||||
if(includeMeta) {
|
||||
queryParams.put(AccessPath.INCLUDE_META_QUERY_PARAMETER, Boolean.toString(includeMeta));
|
||||
}
|
||||
}
|
||||
|
||||
private void addIncludeAllMeta(Map<String,String> queryParams) throws UnsupportedEncodingException{
|
||||
if(allMeta) {
|
||||
queryParams.put(AccessPath.INCLUDE_META_IN_ALL_INSTANCES_QUERY_PARAMETER, Boolean.toString(allMeta));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHeader(String name, String value) {
|
||||
headers.put(name, value);
|
||||
|
@ -55,6 +160,10 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
public ResourceRegistryQueryTemplateClientImpl(String address) {
|
||||
this.address = address;
|
||||
this.headers = new HashMap<>();
|
||||
this.hierarchicalMode = false;
|
||||
this.includeContexts = false;
|
||||
this.includeMeta = false;
|
||||
this.allMeta = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,6 +174,11 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
|
||||
|
||||
Map<String,String> parameters = new HashMap<>();
|
||||
addIncludeMeta(parameters);
|
||||
addIncludeAllMeta(parameters);
|
||||
gxHTTPStringRequest.queryParams(parameters);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
||||
String all = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
||||
|
@ -107,6 +221,11 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
|
||||
gxHTTPStringRequest.path(qt.getName());
|
||||
|
||||
Map<String,String> parameters = new HashMap<>();
|
||||
addIncludeMeta(parameters);
|
||||
addIncludeAllMeta(parameters);
|
||||
gxHTTPStringRequest.queryParams(parameters);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(queryTemplate);
|
||||
String c = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
||||
|
@ -172,6 +291,11 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
|
||||
gxHTTPStringRequest.path(queryTemplateName);
|
||||
|
||||
Map<String,String> parameters = new HashMap<>();
|
||||
addIncludeMeta(parameters);
|
||||
addIncludeAllMeta(parameters);
|
||||
gxHTTPStringRequest.queryParams(parameters);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
||||
String c = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
||||
|
@ -209,6 +333,12 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
|
||||
gxHTTPStringRequest.path(qt.getName());
|
||||
|
||||
Map<String,String> parameters = new HashMap<>();
|
||||
addIncludeMeta(parameters);
|
||||
addIncludeAllMeta(parameters);
|
||||
gxHTTPStringRequest.queryParams(parameters);
|
||||
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(queryTemplate);
|
||||
String c = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
||||
|
@ -261,6 +391,8 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
|
||||
gxHTTPStringRequest.path(name);
|
||||
|
||||
includeAdditionalQueryParameters(gxHTTPStringRequest);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.post(params);
|
||||
String c = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
||||
|
|
Loading…
Reference in New Issue