|
|
|
@ -14,14 +14,13 @@ import org.gcube.common.gxhttp.reference.GXConnection;
|
|
|
|
|
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
|
|
|
|
import org.gcube.common.http.GXHTTPUtility;
|
|
|
|
|
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.ContextCacheRenewal;
|
|
|
|
|
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.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.httputils.HTTPUtility;
|
|
|
|
|
import org.gcube.informationsystem.serialization.ElementMapper;
|
|
|
|
@ -32,7 +31,7 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
/**
|
|
|
|
|
* @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);
|
|
|
|
|
|
|
|
|
@ -43,21 +42,8 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
|
|
|
|
|
|
|
|
|
|
protected Map<String, String> headers;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Track if the client must request to include {@link Metadata}
|
|
|
|
|
*/
|
|
|
|
|
protected boolean includeMeta;
|
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
addIncludeMeta(queryParams);
|
|
|
|
|
}
|
|
|
|
@ -76,8 +62,36 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
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
|
|
|
|
|
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 {
|
|
|
|
|
logger.trace("Going to read {} with UUID {}", Context.NAME);
|
|
|
|
|
logger.info("Going to read all {}s", Context.NAME);
|
|
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
|
|
|
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
|
|
|
|
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();
|
|
|
|
|
String all = HTTPUtility.getResponse(String.class, httpURLConnection);
|
|
|
|
@ -158,6 +187,11 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
|
|
|
|
|
return contextCache.getContexts();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ContextCache getContextCache() {
|
|
|
|
|
return contextCache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected String internalCreate(Context context) throws ContextAlreadyPresentException, ResourceRegistryException {
|
|
|
|
|
try {
|
|
|
|
|
UUID uuid = context.getID();
|
|
|
|
|