Added support for paginated result

This commit is contained in:
luca.frosini 2023-11-09 19:17:37 +01:00
parent d8cb6081bf
commit 1168cb3bbf
3 changed files with 22 additions and 75 deletions

View File

@ -2,6 +2,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for Resource Registry Query Template Client
## [v1.2.0-SNAPSHOT]
- Added support for paginated results [#24648]
## [v1.1.1]
- Migrated code to reorganized E/R format [#24992]

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry-query-template-client</artifactId>
<version>1.1.1</version>
<version>1.2.0-SNAPSHOT</version>
<name>Resource Registry Query Template Client</name>
<description>Resource Registry Query Template Client is a library designed to interact with Resource Registry Query Template APIs</description>

View File

@ -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();