Commit b93faf20 authored by Matija Obreza's avatar Matija Obreza
Browse files

Pagination: Removed "paginator" settings from application.config and dropped...

Pagination: Removed "paginator" settings from application.config and dropped ApiBaseController#maxPageSize
parent f63964c6
......@@ -16,12 +16,12 @@
package org.genesys2.server.api;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import java.util.UUID;
import com.fasterxml.jackson.annotation.JsonIgnore;
/// Base class for API controllers
public abstract class ApiBaseController {
......@@ -37,16 +37,9 @@ public abstract class ApiBaseController {
public static final String APIv2_BASE = "/api/v2";
public static final String APIv2_ADMIN_BASE = APIv2_BASE + "/admin";
@Value("${paginator.api.maxPageSize}")
protected int maxPageSize;
public ApiBaseController() {
super();
}
public void setMaxPageSize(int maxPageSize) {
this.maxPageSize = maxPageSize;
}
public static class UUIDandVersion {
public UUID uuid;
......
......@@ -61,7 +61,7 @@ public abstract class FilteredCRUDController<E extends EmptyModel, S extends Fil
public FilteredPage<E> list(@Parameter(hidden = true) final Pagination page, @RequestBody(required = false) final F filter) throws SearchException, IOException {
F normalizedFilter = shortFilterProcessor.normalizeFilter(filter, filterType());
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(maxPageSize, maxPageSize, defaultSort()) : page.toPageRequest(maxPageSize, maxPageSize);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(100, 50, defaultSort()) : page.toPageRequest(100, 50);
return new FilteredPage<>(normalizedFilter, crudService.list(filter, pageable));
}
......@@ -83,7 +83,7 @@ public abstract class FilteredCRUDController<E extends EmptyModel, S extends Fil
@RequestBody(required = false) final F filter) throws IOException, SearchException {
ShortFilterService.FilterInfo<F> filterInfo = shortFilterProcessor.processFilter(filterCode, filter, filterType());
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(maxPageSize, maxPageSize, defaultSort()) : page.toPageRequest(maxPageSize, maxPageSize);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(100, 50, defaultSort()) : page.toPageRequest(100, 50);
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, crudService.list(filterInfo.filter, pageable));
}
......
......@@ -176,9 +176,11 @@ public class Pagination {
* To page request using the {@link #DEFAULT_SORT_PROPERTIES} and ASC sort
*
* @param maxPageSize the max page size
* @param defaultPageSize use default page size when not provided
* @return the pageable
*/
public Pageable toPageRequest(int maxPageSize, int defaultPageSize) {
assert(defaultPageSize <= maxPageSize);
return PageRequest.of(p == null ? 0 : p, Integer.min(l == null ? defaultPageSize : l, maxPageSize), Sort.by(getSortOrders(getDirections(DEFAULT_SORT_DIRECTION),
getSortProperties(DEFAULT_SORT_PROPERTIES))));
}
......@@ -187,11 +189,13 @@ public class Pagination {
* To page request.
*
* @param maxPageSize the max page size
* @param defaultPageSize use default page size when not provided
* @param defaultDir the default dir
* @param defaultSort the default sort
* @return the pageable
*/
public Pageable toPageRequest(int maxPageSize, int defaultPageSize, Direction defaultDir, String... defaultSort) {
assert(defaultPageSize <= maxPageSize);
return PageRequest.of(p == null ? 0 : p, Integer.min(l == null ? defaultPageSize : l, maxPageSize), Sort.by(getSortOrders(getDirections(defaultDir),
getSortProperties(defaultSort))));
}
......@@ -200,11 +204,13 @@ public class Pagination {
* To page request.
*
* @param maxPageSize the max page size
* @param defaultPageSize use default page size when not provided
* @param defaultDirs the default directions
* @param defaultSort the default sort
* @return the pageable
*/
public Pageable toPageRequest(final int maxPageSize, final int defaultPageSize, final Direction[] defaultDirs, final String... defaultSort) {
assert(defaultPageSize <= maxPageSize);
return PageRequest.of(p == null ? 0 : p, Integer.min(l == null ? defaultPageSize : l, maxPageSize), Sort.by(getSortOrders(getDirections(defaultDirs),
getSortProperties(defaultSort))));
}
......@@ -212,22 +218,24 @@ public class Pagination {
/**
* To page request.
*
* @param maxPageSize the max page size
* @param pageSize the max page size
* @param sort the sort
* @return the pageable
*/
public static Pageable toPageRequest(int maxPageSize, Sort sort) {
return PageRequest.of(0, maxPageSize, sort);
public static Pageable toPageRequest(int pageSize, Sort sort) {
return PageRequest.of(0, pageSize, sort);
}
/**
* To page request.
*
* @param maxPageSize the max page size
* @param defaultPageSize use default page size when not provided
* @param orders Using QDSL order specifiers
* @return
*/
public Pageable toPageRequest(int maxPageSize, int defaultPageSize, OrderSpecifier<?>... orders) {
assert(defaultPageSize <= maxPageSize);
if (orders == null || orders.length == 0) {
return toPageRequest(maxPageSize, defaultPageSize);
}
......
......@@ -96,7 +96,7 @@ public class RequestsController extends ApiBaseController {
@RequestBody(required = false) MaterialSubRequestFilter filter) throws IOException {
ShortFilterService.FilterInfo<MaterialSubRequestFilter> filterInfo = shortFilterProcessor.processFilter(filterCode, filter, MaterialSubRequestFilter.class);
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, requestService.listSubRequests(filterInfo.filter, page.toPageRequest(100, 100, Sort.Direction.ASC, "id")));
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, requestService.listSubRequests(filterInfo.filter, page.toPageRequest(100, 20, Sort.Direction.ASC, "id")));
}
/**
......@@ -111,7 +111,7 @@ public class RequestsController extends ApiBaseController {
@RequestBody(required = false) MaterialSubRequestFilter filter) throws IOException {
ShortFilterService.FilterInfo<MaterialSubRequestFilter> filterInfo = shortFilterProcessor.processFilter(filterCode, filter, MaterialSubRequestFilter.class);
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, requestService.listMineSubRequests(filterInfo.filter, page.toPageRequest(100, 100, Sort.Direction.DESC, "createdDate")));
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, requestService.listMineSubRequests(filterInfo.filter, page.toPageRequest(100, 20, Sort.Direction.DESC, "createdDate")));
}
/**
......@@ -130,7 +130,7 @@ public class RequestsController extends ApiBaseController {
@RequestBody(required = false) MaterialRequestFilter filter) throws IOException {
FilterInfo<MaterialRequestFilter> filterInfo = shortFilterProcessor.processFilter(filterCode, filter, MaterialRequestFilter.class);
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, requestService.list(filterInfo.filter, page.toPageRequest(maxPageSize, maxPageSize, Sort.Direction.ASC, "id")));
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, requestService.list(filterInfo.filter, page.toPageRequest(100, 20, Sort.Direction.ASC, "id")));
}
/**
......@@ -292,7 +292,7 @@ public class RequestsController extends ApiBaseController {
final FaoInstitute institute = instituteService.getInstitute(instCode);
FilterInfo<MaterialSubRequestFilter> filterInfo = shortFilterProcessor.processFilter(filterCode, filter, MaterialSubRequestFilter.class);
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, requestService.list(institute, filterInfo.filter, page.toPageRequest(maxPageSize, maxPageSize, Sort.Direction.ASC, "id")));
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, requestService.list(institute, filterInfo.filter, page.toPageRequest(100, 20, Sort.Direction.ASC, "id")));
}
/**
......
......@@ -6,7 +6,6 @@ import org.genesys2.server.model.kpi.Execution;
import org.genesys2.server.model.kpi.ExecutionRun;
import org.genesys2.server.service.KPIService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
......@@ -22,9 +21,6 @@ public class KPIController {
@Autowired
private KPIService kpiService;
@Value("${paginator.default.pageSize}")
private int pageSize;
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(ModelMap model) {
model.addAttribute("executions", kpiService.listExecutions(PageRequest.of(0, 100)).getContent());
......@@ -36,7 +32,7 @@ public class KPIController {
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
Execution execution = kpiService.loadExecution(executionName);
model.addAttribute("execution", execution);
model.addAttribute("executionRuns", kpiService.listExecutionRuns(execution, PageRequest.of(page - 1, pageSize)));
model.addAttribute("executionRuns", kpiService.listExecutionRuns(execution, PageRequest.of(page - 1, 20)));
return "/admin/kpi/execution";
}
......@@ -46,7 +42,7 @@ public class KPIController {
@RequestParam(value = "dk", required = true) long dimensionKeyId) {
Execution execution = kpiService.loadExecution(executionName);
model.addAttribute("execution", execution);
model.addAttribute("observations", kpiService.listObservations(execution, dimensionKeyId, PageRequest.of(0, pageSize)));
model.addAttribute("observations", kpiService.listObservations(execution, dimensionKeyId, PageRequest.of(0, 20)));
return "/admin/kpi/execution";
}
......
......@@ -10,7 +10,6 @@ import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -26,8 +25,7 @@ import org.springframework.web.bind.annotation.RequestParam;
@PreAuthorize("hasRole('ADMINISTRATOR')")
public class LoggerController {
@Value("${paginator.default.pageSize}")
int defaultPageSize;
private int defaultPageSize = 100;
@RequestMapping(method = RequestMethod.GET, value = "/")
public String adjustLogger(Model model, @RequestParam(value = "page", defaultValue = "1") int page) {
......
......@@ -32,14 +32,6 @@ gelf.port=
gelf.logCustomHeaders=true
gelf.additionalFields=
# Paginator
paginator.default.maxPageSize=500
paginator.default.pageSize=50
paginator.default.fastStep=3
paginator.default.maxPage=4
# Pagination for API calls
paginator.api.maxPageSize=1000
# Default account info
default.admin.email=admin@example.com
default.admin.password=Admin123!
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment