Added missing query parameters to requests
This commit is contained in:
parent
6510a1dac9
commit
9933344e63
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.informationsystem.resourceregistry.schema;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -9,12 +10,16 @@ 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.Element;
|
||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.TypePath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
|
||||
import org.gcube.informationsystem.types.TypeMapper;
|
||||
|
@ -37,6 +42,63 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|||
|
||||
protected Map<String, String> headers;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
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 {
|
||||
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 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);
|
||||
|
@ -54,6 +116,8 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|||
public ResourceRegistrySchemaClientImpl(String address) {
|
||||
this.address = address;
|
||||
this.headers = new HashMap<>();
|
||||
this.includeMeta = false;
|
||||
this.allMeta = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,6 +147,8 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|||
gxHTTPStringRequest.path(TypePath.TYPES_PATH_PART);
|
||||
gxHTTPStringRequest.path(typeDefinitionObj.getName());
|
||||
|
||||
includeAdditionalQueryParameters(gxHTTPStringRequest);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(typeDefinitition);
|
||||
String c = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
||||
|
@ -162,7 +228,7 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|||
if(polymorphic != null) {
|
||||
parameters.put(TypePath.POLYMORPHIC_QUERY_PARAMETER, polymorphic.toString());
|
||||
}
|
||||
gxHTTPStringRequest.queryParams(parameters);
|
||||
includeAdditionalQueryParameters(gxHTTPStringRequest, parameters);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
||||
String json = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
|
Loading…
Reference in New Issue