Commit 427cbca4 authored by Artem Hrybeniuk's avatar Artem Hrybeniuk Committed by Matija Obreza
Browse files

Pageable default page size


Signed-off-by: Matija Obreza's avatarMatija Obreza <matija.obreza@croptrust.org>
parent 08fedc38
......@@ -100,49 +100,49 @@ public abstract class ActionController<T extends AbstractAction<T>, F extends Ac
@Operation(operationId = "listActions", description = "List actions matching the filter", summary = "List actions by filter")
public FilteredPage<T, F> listActions(@Parameter(hidden = true) final Pagination page, @RequestBody(required = false) final F filter) throws IOException {
var normalizedFilter = shortFilterService.normalizeFilter(filter, filterType());
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return new FilteredPage<>(normalizedFilter, actionService.listActions(filter, pageable));
}
@PostMapping(value = "/action/list/completed", produces = { MediaType.APPLICATION_JSON_VALUE })
public FilteredPage<T, ASF> listCompletedActions(@Parameter(hidden = true) final Pagination page, @RequestBody(required = true) final ASF filter) throws IOException {
var normalizedFilter = shortFilterService.normalizeFilter(filter, getActionScheduleFilterType());
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return new FilteredPage<>(normalizedFilter, actionService.listCompletedActions(filter, pageable));
}
@PostMapping(value = "/action/list/inProgress", produces = { MediaType.APPLICATION_JSON_VALUE })
public FilteredPage<T, ASF> listInProgressActions(@Parameter(hidden = true) final Pagination page, @RequestBody(required = true) final ASF filter) throws IOException {
var normalizedFilter = shortFilterService.normalizeFilter(filter, getActionScheduleFilterType());
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return new FilteredPage<>(normalizedFilter, actionService.listInProgressActions(filter, pageable));
}
@PostMapping(value = "/action/list/scheduled", produces = { MediaType.APPLICATION_JSON_VALUE })
public FilteredPage<T, ASF> listScheduledActions(@Parameter(hidden = true) final Pagination page, @RequestBody(required = true) final ASF filter) throws IOException {
var normalizedFilter = shortFilterService.normalizeFilter(filter, getActionScheduleFilterType());
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return new FilteredPage<>(normalizedFilter, actionService.listScheduledActions(filter, pageable));
}
@PostMapping(value = "/action/list/added", produces = { MediaType.APPLICATION_JSON_VALUE })
public FilteredPage<T, ASF> listAddedActions(@Parameter(hidden = true) final Pagination page, @RequestBody(required = true) final ASF filter) throws IOException {
var normalizedFilter = shortFilterService.normalizeFilter(filter, getActionScheduleFilterType());
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return new FilteredPage<>(normalizedFilter, actionService.listAddedActions(filter, pageable));
}
@PostMapping(value = "/action/list/created", produces = { MediaType.APPLICATION_JSON_VALUE })
public FilteredPage<T, ASF> listCreatedActions(@Parameter(hidden = true) final Pagination page, @RequestBody(required = true) final ASF filter) throws IOException {
var normalizedFilter = shortFilterService.normalizeFilter(filter, getActionScheduleFilterType());
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return new FilteredPage<>(normalizedFilter, actionService.listCreatedActions(filter, pageable));
}
@PostMapping(value = "/action/list/overdue", produces = { MediaType.APPLICATION_JSON_VALUE })
public FilteredPage<T, ASF> listOverdueActions(@Parameter(hidden = true) final Pagination page, @RequestBody(required = true) final ASF filter) throws IOException {
var normalizedFilter = shortFilterService.normalizeFilter(filter, getActionScheduleFilterType());
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return new FilteredPage<>(normalizedFilter, actionService.listOverdueActions(filter, pageable));
}
......
......@@ -31,7 +31,8 @@ public abstract class ApiBaseController {
public static final String APIv1_BASE = "/api/v1";
public static final String APIv1_ADMIN_BASE = APIv1_BASE + "/admin";
protected static final int MAX_PAGE_SIZE = 500;
protected static final int MAX_PAGE_SIZE = 200;
protected static final int DEFAULT_PAGE_SIZE = 50;
public ApiBaseController() {
super();
......
......@@ -181,7 +181,7 @@ public abstract class CRUDController<E extends EmptyModel, S extends CRUDService
@Operation(description = "Retrieve list of records", summary = "List")
@PageableAsQueryParam
public Page<E> list(@Parameter(hidden = true) final Pagination page) {
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return crudService.list(pageable);
}
......
......@@ -62,7 +62,7 @@ public abstract class FilteredCRUDController<E extends EmptyModel, S extends Fil
public FilteredPage<E, F> list(@Parameter(hidden = true) final Pagination page, @RequestBody(required = false) final F filter) throws SearchException, IOException {
F normalizedFilter = shortFilterService.normalizeFilter(filter, filterType());
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
FilteredPage<E, F> results = new FilteredPage<>(normalizedFilter, crudService.list(filter, pageable));
return results;
}
......@@ -91,7 +91,7 @@ public abstract class FilteredCRUDController<E extends EmptyModel, S extends Fil
}
FilterInfo<F> filterInfo = shortFilterService.processFilter(filterCode, filter, filterType());
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
FilteredPage<E, F> results = new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, crudService.list(filterInfo.filter, pageable));
return results;
......
......@@ -183,8 +183,8 @@ public class Pagination {
* @param maxPageSize the max page size
* @return the pageable
*/
public Pageable toPageRequest(final int maxPageSize) {
return PageRequest.of(p == null ? 0 : p, Integer.min(l == null ? maxPageSize : l, maxPageSize), Sort.by(getSortOrders(getDirections(DEFAULT_SORT_DIRECTION),
public Pageable toPageRequest(final int maxPageSize, final int defaultPageSize) {
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))));
}
......@@ -196,8 +196,8 @@ public class Pagination {
* @param defaultSort the default sort
* @return the pageable
*/
public Pageable toPageRequest(final int maxPageSize, final Direction defaultDir, final String... defaultSort) {
return PageRequest.of(p == null ? 0 : p, Integer.min(l == null ? maxPageSize : l, maxPageSize), Sort.by(getSortOrders(getDirections(defaultDir),
public Pageable toPageRequest(final int maxPageSize, final int defaultPageSize, final Direction defaultDir, final String... defaultSort) {
return PageRequest.of(p == null ? 0 : p, Integer.min(l == null ? defaultPageSize : l, maxPageSize), Sort.by(getSortOrders(getDirections(defaultDir),
getSortProperties(defaultSort))));
}
......@@ -209,8 +209,8 @@ public class Pagination {
* @param defaultSort the default sort
* @return the pageable
*/
public Pageable toPageRequest(final int maxPageSize, final Direction[] defaultDirs, final String... defaultSort) {
return PageRequest.of(p == null ? 0 : p, Integer.min(l == null ? maxPageSize : l, maxPageSize), Sort.by(getSortOrders(getDirections(defaultDirs),
public Pageable toPageRequest(final int maxPageSize, final int defaultPageSize, final Direction[] defaultDirs, final String... defaultSort) {
return PageRequest.of(p == null ? 0 : p, Integer.min(l == null ? defaultPageSize : l, maxPageSize), Sort.by(getSortOrders(getDirections(defaultDirs),
getSortProperties(defaultSort))));
}
......@@ -235,9 +235,9 @@ public class Pagination {
* @param orders Using QDSL order specifiers
* @return
*/
public Pageable toPageRequest(int maxPageSize, OrderSpecifier<?>... orders) {
public Pageable toPageRequest(int maxPageSize, int defaultPageSize, OrderSpecifier<?>... orders) {
if (orders == null || orders.length == 0) {
return toPageRequest(maxPageSize);
return toPageRequest(maxPageSize, defaultPageSize);
}
var sorts = Arrays.stream(orders).map(o -> {
......@@ -256,7 +256,7 @@ public class Pagination {
return order;
}).collect(Collectors.toList());
return PageRequest.of(p == null ? 0 : p, Integer.min(l == null ? maxPageSize : l, maxPageSize), Sort.by(sorts));
return PageRequest.of(p == null ? 0 : p, Integer.min(l == null ? defaultPageSize : l, maxPageSize), Sort.by(sorts));
}
}
......@@ -134,7 +134,7 @@ public abstract class TranslatedCRUDController<E extends TranslatedCooperatorOwn
public FilteredPage<T, F> list(@Parameter(hidden = true) final Pagination page, @RequestBody(required = false) final F filter) throws SearchException, IOException {
F normalizedFilter = shortFilterService.normalizeFilter(filter, filterType());
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
FilteredPage<T, F> results = new FilteredPage<>(normalizedFilter, translatedCrudService.listFiltered(filter, pageable));
return results;
}
......
......@@ -141,7 +141,7 @@ public class AccessionController extends FilteredCRUDController<Accession, Acces
@RequestBody AccessionFilter filter) throws SearchException, IOException {
final var filterInfo = shortFilterService.processFilter(filterCode, filter, AccessionFilter.class);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, crudService.listMCPD(filterInfo.filter, pageable));
}
......@@ -170,7 +170,7 @@ public class AccessionController extends FilteredCRUDController<Accession, Acces
filter.entityId().eq().add(crudService.get(accessionId).getId());
filter.classname = Accession.class.getName();
return auditService.listAuditLogs(filter, page.toPageRequest(100));
return auditService.listAuditLogs(filter, page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE));
}
@PostMapping(value = "/acquire", produces = { MediaType.APPLICATION_JSON_VALUE })
......
......@@ -51,7 +51,7 @@ public class AdminAlertsController extends ApiBaseController {
@Operation(description = "Retrieve list of admin alerts", summary = "List")
@PageableAsQueryParam
public Page<TransientMessageService.TransientMessage> list(@Parameter(hidden = true) final Pagination page) {
return transientMessageService.listAdminAlerts(page.toPageRequest(100));
return transientMessageService.listAdminAlerts(page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE));
}
@DeleteMapping(value = "/{uuid}", produces = { MediaType.APPLICATION_JSON_VALUE })
......
......@@ -87,7 +87,7 @@ public class CooperatorController extends FilteredCRUDController<Cooperator, Coo
filter.entityId().eq().add(crudService.get(cooperatorId).getId());
filter.classname = Cooperator.class.getName();
return auditService.listAuditLogs(filter, page.toPageRequest(100));
return auditService.listAuditLogs(filter, page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE));
}
/**
......
......@@ -185,7 +185,7 @@ public class CropController extends FilteredCRUDController<Crop, CropService, Cr
public FilteredPage<TaxonomySpecies, TaxonomySpeciesFilter> listSpecies(@PathVariable("cropId") final long id, @Parameter(hidden = true) final Pagination page, @RequestBody(required = false) final TaxonomySpeciesFilter filter) throws IOException {
TaxonomySpeciesFilter normalizedFilter = shortFilterService.normalizeFilter(filter, TaxonomySpeciesFilter.class);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
FilteredPage<TaxonomySpecies, TaxonomySpeciesFilter> results = new FilteredPage<>(normalizedFilter, crudService.listSpecies(crudService.get(id), filter, pageable));
return results;
}
......
......@@ -113,7 +113,7 @@ public class CropTraitController extends TranslatedCRUDController<CropTrait, Tra
public CropTraitObservationService.FilteredObservations filterObservations(@Parameter(hidden = true) final Pagination page,
@RequestBody(required = true) final CropTraitObservationFilter filter) {
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, observationsDefaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, observationsDefaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return observationService.filter(filter, pageable);
}
......@@ -122,7 +122,7 @@ public class CropTraitController extends TranslatedCRUDController<CropTrait, Tra
public CropTraitObservationDataService.FilteredObservationsData filterObservationsData(@Parameter(hidden = true) final Pagination page,
@RequestBody(required = true) final CropTraitObservationDataFilter filter) {
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, observationsDataDefaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, observationsDataDefaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return observationDataService.filter(filter, pageable);
}
......
......@@ -150,7 +150,7 @@ public class InventoryController extends FilteredCRUDController<Inventory, Inven
filter.entityId().eq().add(crudService.get(inventoryId).getId());
filter.classname = Inventory.class.getName();
return auditService.listAuditLogs(filter, page.toPageRequest(100));
return auditService.listAuditLogs(filter, page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE));
}
/**
......@@ -187,7 +187,7 @@ public class InventoryController extends FilteredCRUDController<Inventory, Inven
@Operation(operationId = "aggregateQuantity", description = "Returns the aggregate of inventory quantities.", summary = "Sum inventory quantities.")
public FilteredPage<InventoryRepositoryCustom.AggregatedInventoryQuantity, InventoryFilter> aggregateQuantity(@Parameter(hidden = true) final Pagination page, @RequestBody InventoryFilter filter) throws IOException {
InventoryFilter normalizedFilter = shortFilterService.normalizeFilter(filter, filterType());
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, QInventory.inventory.formTypeCode.asc()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, QInventory.inventory.formTypeCode.asc()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return new FilteredPage<>(normalizedFilter, crudService.aggregateQuantity(filter, pageable));
}
......
......@@ -73,7 +73,7 @@ public class InventoryGroupController extends FilteredCRUDController<AccessionIn
@Operation(operationId = "listMembers", description = "Fetch members of the group", summary = "List or filter order items")
public Page<AccessionInvGroupMap> filterItems(@PathVariable("id") final Long groupId, @Parameter(hidden = true) Pagination page) throws SearchException {
final AccessionInvGroup accessionInvGroup = crudService.get(groupId);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultMemberSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultMemberSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return crudService.listMembers(accessionInvGroup, pageable);
}
......
......@@ -127,7 +127,7 @@ public class InventoryViabilityController extends FilteredCRUDController<Invento
actionFilter.actionNameCode = Set.of(CommunityCodeValues.INVENTORY_ACTION_VABILITYTEST.value);
actionFilter.states = Set.of(ActionState.PENDING, ActionState.SCHEDULED);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, QInventoryAction.inventoryAction.notBeforeDate.asc().nullsFirst()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, QInventoryAction.inventoryAction.notBeforeDate.asc().nullsFirst()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return new FilteredPage<>(normalizedFilter, inventoryActionService.listActions(actionFilter, pageable));
}
......
......@@ -83,7 +83,7 @@ public class InventoryViabilityRuleController extends FilteredCRUDController<Inv
@PostMapping(value = "/{id}/species/list", produces = { MediaType.APPLICATION_JSON_VALUE })
public Page<InventoryViabilityRuleMap> listSpecies(@PathVariable("id") final Long ruleId, @Parameter(hidden = true) final Pagination page) {
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultSpeciesSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultSpeciesSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return iViabilityRuleService.listSpecies(iViabilityRuleService.get(ruleId), pageable);
}
......
......@@ -53,7 +53,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping(value = { KPIController.API_URL })
@PreAuthorize("isAuthenticated()")
@Tag(name = "KPI")
public class KPIController {
public class KPIController extends ApiBaseController{
/** The Constant API_URL. */
public static final String API_URL = ApiBaseController.APIv1_BASE + "/kpi";
......@@ -79,7 +79,7 @@ public class KPIController {
@GetMapping(value="/parameters")
public Page<KPIParameter> listParameters(final Pagination page) {
return kpiService.listParameters(page.toPageRequest(100));
return kpiService.listParameters(page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE));
}
......@@ -108,7 +108,7 @@ public class KPIController {
@JsonView(JsonViews.Minimal.class)
@GetMapping(value="/dimensions")
public Page<Dimension<?>> listDimensions(final Pagination page) {
return kpiService.listDimensions(page.toPageRequest(100));
return kpiService.listDimensions(page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE));
}
/**
......@@ -130,7 +130,7 @@ public class KPIController {
@JsonView(JsonViews.Minimal.class)
@GetMapping(value="/executions")
public Page<Execution> listExecution(final Pagination page) {
return kpiService.listExecutions(page.toPageRequest(100));
return kpiService.listExecutions(page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE));
}
@PostMapping(value = "/executions/{name:.+}/execute")
......@@ -150,7 +150,7 @@ public class KPIController {
@GetMapping(value = "/executions/{name:.+}/runs")
public Page<ExecutionRun> executionRuns(final @PathVariable String name, final Pagination page) {
return kpiService.listExecutionRuns(kpiService.getExecution(name), page.toPageRequest(100));
return kpiService.listExecutionRuns(kpiService.getExecution(name), page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE));
}
@GetMapping(value = "/executions/{name:.+}/run")
......
......@@ -27,6 +27,8 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.querydsl.core.Tuple;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.gringlobal.api.v1.ApiBaseController;
import org.gringlobal.api.v1.Pagination;
import org.gringlobal.model.kpi.Execution;
import org.gringlobal.model.kpi.Observation;
......@@ -48,7 +50,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping(value = { KPIController.API_URL })
@PreAuthorize("isAuthenticated()")
@Tag(name = "KPI")
public class KPIReadController {
public class KPIReadController extends ApiBaseController {
@Autowired
private KPIService kpiService;
......@@ -97,7 +99,7 @@ public class KPIReadController {
from = startDate.getTime();
}
Page<Tuple> observations = kpiService.listObservations(execution, from, to, keys, pagination.toPageRequest(1000, Sort.Direction.DESC, "id"));
Page<Tuple> observations = kpiService.listObservations(execution, from, to, keys, pagination.toPageRequest(1000, DEFAULT_PAGE_SIZE, Sort.Direction.DESC, "id"));
return observations.map(this::toMap);
}
......
......@@ -197,7 +197,7 @@ public class OAuthManagementController extends ApiBaseController {
filterCode = shortFilterService.getCode(filter);
}
ShortFilterService.FilterInfo<OAuthClientFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, OAuthClientFilter.class);
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, clientDetailsService.listClientDetails(page.toPageRequest(100, Sort.Direction.ASC, "clientId")));
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, clientDetailsService.listClientDetails(page.toPageRequest(100, DEFAULT_PAGE_SIZE, Sort.Direction.ASC, "clientId")));
}
@PostMapping(value = "/{clientId}/set-recaptcha-keys")
......
......@@ -122,7 +122,7 @@ public class OrderRequestController extends FilteredCRUDController<OrderRequest,
@PostMapping(value = "/{id}/action/list", produces = { MediaType.APPLICATION_JSON_VALUE })
@Operation(description = "List actions by order request", summary = "List actions by order")
public Page<OrderRequestAction> listByOrderRequest(@PathVariable("id") final Long orderId, @Parameter(hidden = true) final Pagination page) {
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return actionService.listByOrderRequest(orderRequestService.get(orderId), pageable);
}
}
......@@ -218,7 +218,7 @@ public class OrderRequestController extends FilteredCRUDController<OrderRequest,
@PostMapping(value = "/{id}/action/list", produces = { MediaType.APPLICATION_JSON_VALUE })
@Operation(description = "List actions by order request", summary = "List actions by order")
public Page<OrderRequestItemAction> listByOrderRequest(@PathVariable("id") final Long orderId, @Parameter(hidden = true) final Pagination page) {
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return actionService.listByOrderRequest(orderRequestService.get(orderId), pageable);
}
}
......@@ -244,7 +244,7 @@ public class OrderRequestController extends FilteredCRUDController<OrderRequest,
public FilteredPage<OrderRequestItem, OrderRequestItemFilter> filterItems(@PathVariable("id") final Long orderId, @Parameter(hidden = true) Pagination page, @RequestBody(required = true) final OrderRequestItemFilter filter) throws SearchException, IOException {
final OrderRequest orderRequest = orderRequestService.get(orderId);
OrderRequestItemFilter normalizedFilter = shortFilterService.normalizeFilter(filter, OrderRequestItemFilter.class);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(100, defaultItemSort()) : page.toPageRequest(100);
Pageable pageable = ArrayUtils.isEmpty(page.getS()) ? page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, defaultItemSort()) : page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
return new FilteredPage<>(normalizedFilter, orderRequestService.filterItems(orderRequest, filter, pageable));
}
......
......@@ -227,7 +227,7 @@ public class RepositoryController extends ApiBaseController {
@JsonView(JsonViews.Protected.class)
public Page<RepositoryFolder> getFolderSubfolders(final HttpServletRequest request, final Pagination page) throws InvalidRepositoryPathException {
final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/folder").length());
return repositoryService.listFolders(Paths.get(folderPath), page.toPageRequest(50));
return repositoryService.listFolders(Paths.get(folderPath), page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE));
}
/**
......@@ -243,7 +243,7 @@ public class RepositoryController extends ApiBaseController {
@JsonView(JsonViews.Protected.class)
public Page<RepositoryFile> getFolderFiles(final HttpServletRequest request, final Pagination page) throws InvalidRepositoryPathException {
final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/folder").length());
return repositoryService.listFiles(Paths.get(folderPath), page.toPageRequest(50));
return repositoryService.listFiles(Paths.get(folderPath), page.toPageRequest(MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE));
}
/**
......
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