Improved limit offset request for contexts

This commit is contained in:
luca.frosini 2023-11-09 18:52:54 +01:00
parent 5189194b5e
commit 848d1ee835
1 changed files with 21 additions and 4 deletions

View File

@ -128,12 +128,20 @@ public class ResourceRegistryClientImpl extends BaseRequestInfo implements Resou
} }
private void addOffset(Map<String,String> queryParams) throws UnsupportedEncodingException{ 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) { if(offset!=null) {
queryParams.put(AccessPath.OFFSET_QUERY_PARAMETER, offset.toString()); queryParams.put(AccessPath.OFFSET_QUERY_PARAMETER, offset.toString());
} }
} }
private void addLimit(Map<String,String> queryParams) throws UnsupportedEncodingException{ 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) { if(limit!=null) {
queryParams.put(AccessPath.LIMIT_QUERY_PARAMETER, limit.toString()); queryParams.put(AccessPath.LIMIT_QUERY_PARAMETER, limit.toString());
} }
@ -143,7 +151,7 @@ public class ResourceRegistryClientImpl extends BaseRequestInfo implements Resou
@Override @Override
public List<Context> renew() throws ResourceRegistryException { public List<Context> renew() throws ResourceRegistryException {
return getAllContextFromServer(); return getAllContextFromServer(0, BaseRequestInfo.UNBOUNDED_LIMIT);
} }
}; };
@ -186,7 +194,6 @@ public class ResourceRegistryClientImpl extends BaseRequestInfo implements Resou
} }
/** /**
* It reads all the contexts from server. * It reads all the contexts from server.
* The cache used for contexts is bypassed and not updated. * The cache used for contexts is bypassed and not updated.
@ -194,6 +201,16 @@ public class ResourceRegistryClientImpl extends BaseRequestInfo implements Resou
* @throws ResourceRegistryException * @throws ResourceRegistryException
*/ */
public List<Context> getAllContextFromServer() throws ResourceRegistryException { public List<Context> getAllContextFromServer() throws ResourceRegistryException {
return getAllContextFromServer(offset, limit);
}
/**
* 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
*/
protected List<Context> getAllContextFromServer(Integer offset, Integer limit) throws ResourceRegistryException {
try { try {
logger.info("Going to read all {}s", Context.NAME); logger.info("Going to read all {}s", Context.NAME);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest(); GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
@ -203,8 +220,8 @@ public class ResourceRegistryClientImpl extends BaseRequestInfo implements Resou
Map<String,String> parameters = new HashMap<>(); Map<String,String> parameters = new HashMap<>();
addIncludeMeta(parameters); addIncludeMeta(parameters);
addOffset(parameters); addOffset(parameters, offset);
addLimit(parameters); addLimit(parameters, limit);
gxHTTPStringRequest.queryParams(parameters); gxHTTPStringRequest.queryParams(parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();