Compare commits

...

3 Commits

Author SHA1 Message Date
Luca Frosini c7bc13c359 Removed uneeded dependency 2024-05-24 11:00:44 +02:00
luca.frosini ef5b530800 Fixed query parameters 2023-11-09 19:11:12 +01:00
luca.frosini adc1827da1 Added support for paginated results 2023-11-09 19:04:36 +01:00
4 changed files with 64 additions and 26 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 Context Client # Changelog for Resource Registry Context Client
## [v4.2.0-SNAPSHOT]
- Added support for paginated results [#24648]
## [v4.1.1] ## [v4.1.1]
- Migrated code to reorganized E/R format [#24992] - Migrated code to reorganized E/R format [#24992]

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.information-system</groupId> <groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry-context-client</artifactId> <artifactId>resource-registry-context-client</artifactId>
<version>4.1.1</version> <version>4.2.0-SNAPSHOT</version>
<name>Resource Registry Context Client</name> <name>Resource Registry Context Client</name>
<description>Resource Registry Context Client is a library designed to interact with Resource Registry Context APIs</description> <description>Resource Registry Context Client is a library designed to interact with Resource Registry Context APIs</description>
@ -50,10 +50,6 @@
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>gxHTTP</artifactId> <artifactId>gxHTTP</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-utility-sg3</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>

View File

@ -4,6 +4,7 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.gcube.informationsystem.contexts.reference.entities.Context; import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; 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.ContextAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException;
@ -15,6 +16,8 @@ public interface ResourceRegistryContextClient {
public void addHeader(String name, String value); public void addHeader(String name, String value);
public ContextCache getContextCache();
public List<Context> all() throws ResourceRegistryException; public List<Context> all() throws ResourceRegistryException;
public Context create(Context context) throws ContextAlreadyPresentException, ResourceRegistryException; public Context create(Context context) throws ContextAlreadyPresentException, ResourceRegistryException;

View File

@ -14,14 +14,13 @@ import org.gcube.common.gxhttp.reference.GXConnection;
import org.gcube.common.gxhttp.request.GXHTTPStringRequest; import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
import org.gcube.common.http.GXHTTPUtility; import org.gcube.common.http.GXHTTPUtility;
import org.gcube.informationsystem.contexts.reference.entities.Context; import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.model.reference.properties.Metadata;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache; import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal; import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; 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.ContextAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath; import org.gcube.informationsystem.resourceregistry.api.request.BaseRequestInfo;
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath; import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath;
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility; import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
import org.gcube.informationsystem.serialization.ElementMapper; import org.gcube.informationsystem.serialization.ElementMapper;
@ -32,7 +31,7 @@ import org.slf4j.LoggerFactory;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*/ */
public class ResourceRegistryContextClientImpl implements ResourceRegistryContextClient { public class ResourceRegistryContextClientImpl extends BaseRequestInfo implements ResourceRegistryContextClient {
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryContextClientImpl.class); private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryContextClientImpl.class);
@ -43,21 +42,8 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
protected Map<String, String> headers; protected Map<String, String> headers;
/**
* Track if the client must request to include {@link Metadata}
*/
protected boolean includeMeta;
protected ContextCache contextCache; protected ContextCache contextCache;
public boolean includeMeta() {
return includeMeta;
}
public void setIncludeMeta(boolean includeMeta) {
this.includeMeta = includeMeta;
}
private void addOptionalQueryParameters(Map<String,String> queryParams) throws UnsupportedEncodingException { private void addOptionalQueryParameters(Map<String,String> queryParams) throws UnsupportedEncodingException {
addIncludeMeta(queryParams); addIncludeMeta(queryParams);
} }
@ -76,8 +62,36 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
} }
private void addIncludeMeta(Map<String,String> queryParams) throws UnsupportedEncodingException{ private void addIncludeMeta(Map<String,String> queryParams) throws UnsupportedEncodingException{
addIncludeMeta(queryParams, includeMeta);
}
private void addIncludeMeta(Map<String,String> queryParams, boolean includeMeta) throws UnsupportedEncodingException{
if(includeMeta) { if(includeMeta) {
queryParams.put(AccessPath.INCLUDE_META_QUERY_PARAMETER, Boolean.toString(includeMeta)); queryParams.put(ContextPath.INCLUDE_META_QUERY_PARAMETER, Boolean.toString(includeMeta));
}
}
/*
private void addOffset(Map<String,String> queryParams) throws UnsupportedEncodingException{
addOffset(queryParams, offset);
}
*/
private void addOffset(Map<String,String> queryParams, Integer offset) throws UnsupportedEncodingException{
if(offset!=null) {
queryParams.put(ContextPath.OFFSET_QUERY_PARAMETER, offset.toString());
}
}
/*
private void addLimit(Map<String,String> queryParams) throws UnsupportedEncodingException{
addLimit(queryParams, limit);
}
*/
private void addLimit(Map<String,String> queryParams, Integer limit) throws UnsupportedEncodingException{
if(limit!=null) {
queryParams.put(ContextPath.LIMIT_QUERY_PARAMETER, limit.toString());
} }
} }
@ -85,7 +99,7 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
@Override @Override
public List<Context> renew() throws ResourceRegistryException { public List<Context> renew() throws ResourceRegistryException {
return getAllContextFromServer(); return getAllContextFromServer(true, 0, BaseRequestInfo.UNBOUNDED_LIMIT);
} }
}; };
@ -129,14 +143,29 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
} }
} }
protected List<Context> getAllContextFromServer() throws ResourceRegistryException {
/**
* 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<Context> getAllContextFromServer() throws ResourceRegistryException {
return getAllContextFromServer(includeMeta, offset, limit);
}
protected List<Context> getAllContextFromServer(boolean includeMeta, Integer offset, Integer limit) throws ResourceRegistryException {
try { try {
logger.trace("Going to read {} with UUID {}", Context.NAME); logger.info("Going to read all {}s", Context.NAME);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest(); GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8); gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(ContextPath.CONTEXTS_PATH_PART); gxHTTPStringRequest.path(ContextPath.CONTEXTS_PATH_PART);
includeAdditionalQueryParameters(gxHTTPStringRequest); Map<String,String> parameters = new HashMap<>();
addIncludeMeta(parameters, includeMeta);
addOffset(parameters, offset);
addLimit(parameters, limit);
gxHTTPStringRequest.queryParams(parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
String all = HTTPUtility.getResponse(String.class, httpURLConnection); String all = HTTPUtility.getResponse(String.class, httpURLConnection);
@ -158,6 +187,11 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
return contextCache.getContexts(); return contextCache.getContexts();
} }
@Override
public ContextCache getContextCache() {
return contextCache;
}
protected String internalCreate(Context context) throws ContextAlreadyPresentException, ResourceRegistryException { protected String internalCreate(Context context) throws ContextAlreadyPresentException, ResourceRegistryException {
try { try {
UUID uuid = context.getID(); UUID uuid = context.getID();