|
|
|
@ -13,14 +13,13 @@ 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.request.BaseRequestInfo;
|
|
|
|
|
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;
|
|
|
|
@ -31,7 +30,7 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
/**
|
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
|
*/
|
|
|
|
|
public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistryQueryTemplateClient {
|
|
|
|
|
public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo implements ResourceRegistryQueryTemplateClient {
|
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryQueryTemplateClientImpl.class);
|
|
|
|
|
|
|
|
|
@ -42,66 +41,7 @@ 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);
|
|
|
|
|
}
|
|
|
|
@ -119,18 +59,6 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|
|
|
|
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));
|
|
|
|
@ -143,6 +71,18 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addOffset(Map<String,String> queryParams) throws UnsupportedEncodingException{
|
|
|
|
|
if(offset!=null) {
|
|
|
|
|
queryParams.put(AccessPath.OFFSET_QUERY_PARAMETER, offset.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addLimit(Map<String,String> queryParams) throws UnsupportedEncodingException{
|
|
|
|
|
if(limit!=null) {
|
|
|
|
|
queryParams.put(AccessPath.LIMIT_QUERY_PARAMETER, limit.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void addHeader(String name, String value) {
|
|
|
|
|
headers.put(name, value);
|
|
|
|
@ -177,6 +117,8 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|
|
|
|
Map<String,String> parameters = new HashMap<>();
|
|
|
|
|
addIncludeMeta(parameters);
|
|
|
|
|
addIncludeAllMeta(parameters);
|
|
|
|
|
addOffset(parameters);
|
|
|
|
|
addLimit(parameters);
|
|
|
|
|
gxHTTPStringRequest.queryParams(parameters);
|
|
|
|
|
|
|
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
|
|
|
|