Improving offset limit management to properly support paginated result

This commit is contained in:
luca.frosini 2023-10-31 15:25:08 +01:00
parent 8d5c498d07
commit e1b1f23e81
4 changed files with 28 additions and 21 deletions

View File

@ -8,21 +8,21 @@ import org.gcube.informationsystem.model.reference.properties.Metadata;
*/
public class BaseRequestInfo implements RequestInfo {
public static final Integer DEFAULT_LIMIT = 10;
public static final Integer UNBOUNDED_LIMIT = -1;
public static final Integer DEFAULT_OFFSET = 0;
public static final Integer DEFAULT_LIMIT = 10;
public static final Integer UNBOUNDED_LIMIT = -1;
/**
* The offset parameter indicates the starting position of the result.
*/
protected Integer offset;
/**
* To get unlimited results the limit query parameters must be set to -1.
* If the results are too much the operation could have a timeout.
*/
protected int limit;
/**
* The offset parameter indicates the starting position of the result.
*/
protected int offset;
protected Integer limit;
/**
* Track if the request requested to include {@link Metadata}
@ -47,8 +47,12 @@ public class BaseRequestInfo implements RequestInfo {
protected boolean includeContexts;
public BaseRequestInfo() {
this.limit = BaseRequestInfo.DEFAULT_LIMIT;
this.offset = BaseRequestInfo.DEFAULT_OFFSET;
this(DEFAULT_OFFSET, DEFAULT_LIMIT);
}
public BaseRequestInfo(Integer offset, Integer limit) {
this.offset = offset;
this.limit = limit;
this.includeMeta = false;
this.allMeta = false;
this.hierarchicalMode = false;
@ -56,22 +60,22 @@ public class BaseRequestInfo implements RequestInfo {
}
@Override
public int getLimit() {
public Integer getLimit() {
return limit;
}
@Override
public void setLimit(int limit) {
public void setLimit(Integer limit) {
this.limit = limit;
}
@Override
public int getOffset() {
public Integer getOffset() {
return offset;
}
@Override
public void setOffset(int offset) {
public void setOffset(Integer offset) {
this.offset = offset;
}

View File

@ -5,13 +5,13 @@ package org.gcube.informationsystem.resourceregistry.api.request;
*/
public interface RequestInfo {
public int getLimit();
public Integer getLimit();
public void setLimit(int limit);
public void setLimit(Integer limit);
public int getOffset();
public Integer getOffset();
public void setOffset(int offset);
public void setOffset(Integer offset);
public boolean includeMeta();

View File

@ -22,6 +22,10 @@ public class AccessPath {
public static final String INCLUDE_META_QUERY_PARAMETER = InstancePath.INCLUDE_META_QUERY_PARAMETER;
public static final String INCLUDE_META_IN_ALL_INSTANCES_QUERY_PARAMETER = InstancePath.INCLUDE_META_IN_ALL_INSTANCES_QUERY_PARAMETER;
public static final String OFFSET_QUERY_PARAMETER = InstancePath.OFFSET_QUERY_PARAMETER;
public static final String LIMIT_QUERY_PARAMETER = InstancePath.LIMIT_QUERY_PARAMETER;
/**
* Used only in getRelated() function
* The _ is prepended to avoid clash with field name

View File

@ -10,9 +10,8 @@ public class InstancePath {
public static final String INSTANCES_PATH_PART = "instances";
public static final String LIMIT_QUERY_PARAMETER = "limit";
public static final String OFFSET_QUERY_PARAMETER = "offset";
public static final String LIMIT_QUERY_PARAMETER = "limit";
public static final String POLYMORPHIC_QUERY_PARAMETER = "polymorphic";