diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java index a96ad0f..6b9bffa 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java @@ -481,14 +481,18 @@ public class ContextManagement extends EntityElementManagement contexts = contextCache.getContexts(); ServerRequestInfo requestInfo = RequestUtility.getRequestInfo().get(); - int limit = requestInfo.getLimit(); + Integer limit = requestInfo.getLimit(); if(forceLimit!=null) { limit = forceLimit; + }else if(limit == null) { + limit = -1; } - int offset = requestInfo.getOffset(); + Integer offset = requestInfo.getOffset(); if(forceOffset!=null) { offset = forceOffset; + }else if(offset == null) { + offset = 0; } int position = -1; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/requests/ServerRequestInfo.java b/src/main/java/org/gcube/informationsystem/resourceregistry/requests/ServerRequestInfo.java index 6c258d8..0f92eef 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/requests/ServerRequestInfo.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/requests/ServerRequestInfo.java @@ -24,6 +24,11 @@ public class ServerRequestInfo extends BaseRequestInfo implements RequestInfo { this.uriInfo = null; } + public ServerRequestInfo(int offset, int limit) { + super(offset, limit); + this.uriInfo = null; + } + public UriInfo getUriInfo() { return uriInfo; } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/BaseRest.java b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/BaseRest.java index 0eee4ff..4eb1df9 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/BaseRest.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/BaseRest.java @@ -35,15 +35,20 @@ public class BaseRest { setAccountingMethod(accountingMethod.toString()); } - - - protected ServerRequestInfo initRequestInfo() { - ServerRequestInfo requestInfo = new ServerRequestInfo(); + private ServerRequestInfo initRequestInfo(ServerRequestInfo requestInfo) { requestInfo.setUriInfo(uriInfo); - RequestUtility.getRequestInfo().set(requestInfo); - return requestInfo; } + protected ServerRequestInfo initRequestInfo(int offset, int limit) { + ServerRequestInfo requestInfo = new ServerRequestInfo(offset, limit); + return initRequestInfo(requestInfo); + } + + protected ServerRequestInfo initRequestInfo() { + ServerRequestInfo requestInfo = new ServerRequestInfo(); + return initRequestInfo(requestInfo); + } + } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/ContextManager.java b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/ContextManager.java index 5fca5b8..4c4632a 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/ContextManager.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/ContextManager.java @@ -18,6 +18,7 @@ import org.gcube.informationsystem.contexts.reference.entities.Context; import org.gcube.informationsystem.resourceregistry.ResourceInitializer; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.request.BaseRequestInfo; import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.gcube.informationsystem.resourceregistry.contexts.entities.ContextManagement; @@ -46,10 +47,9 @@ public class ContextManager extends BaseRest { logger.info("Requested to read all {}s", Context.NAME); setAccountingMethod(Method.LIST, Context.NAME); - ServerRequestInfo serverRequestInfo = initRequestInfo(); + ServerRequestInfo serverRequestInfo = initRequestInfo(BaseRequestInfo.DEFAULT_OFFSET, BaseRequestInfo.UNBOUNDED_LIMIT); serverRequestInfo.setAllMeta(true); serverRequestInfo.checkBooleanQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER); - serverRequestInfo.checkLimitOffset(0, -1); ContextManagement contextManagement = new ContextManagement(); return contextManagement.all(false);