Skip to content
Snippets Groups Projects

Update to Quarkus 1.13, update to pagination count logic

9 files
+ 49
28
Compare changes
  • Side-by-side
  • Inline
Files
9
@@ -12,6 +12,7 @@ import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.ext.Provider;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.resteasy.core.ResteasyContext;
import org.jboss.resteasy.spi.LinkHeader;
@@ -24,6 +25,8 @@ import org.jboss.resteasy.spi.LinkHeader;
*/
@Provider
public class PaginatedResultsFilter implements ContainerResponseFilter {
// should be set whenever we pass a limited subset to the response to be paginated of a larger subset
public static final String MAX_RESULTS_SIZE_HEADER = "X-Max-Result-Size";
@ConfigProperty(name = "eclipse.pagination.enabled", defaultValue = "true")
Instance<Boolean> enablePagination;
@@ -42,13 +45,20 @@ public class PaginatedResultsFilter implements ContainerResponseFilter {
ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
if (enablePagination.get()) {
int pageSize = defaultPageSize.get();
Object entity = responseContext.getEntity();
// only try and paginate if there are multiple entities
if (entity instanceof List) {
List<?> listEntity = (List<?>) entity;
int page = getRequestedPage(listEntity);
int lastPage = (int) Math.ceil((double) listEntity.size() / pageSize);
// if available, use max results header value
String rawMaxSize = responseContext.getHeaderString(MAX_RESULTS_SIZE_HEADER);
int maxSize = listEntity.size();
if (StringUtils.isNumeric(rawMaxSize)) {
maxSize = Integer.valueOf(rawMaxSize);
}
int lastPage = (int) Math.ceil((double) maxSize / pageSize);
// set the sliced array as the entity
responseContext.setEntity(
listEntity.subList(
Loading