use of org.hisp.dhis.webapi.controller.dataitem.DataItemQueryController.API_RESOURCE_PATH in project dhis2-core by dhis2.
the class ResponseHandler method addPaginationToNode.
/**
* This method takes care of the pagination link and their respective
* attributes. It will count the number of results available and base on the
* WebOptions will calculate the pagination output.
*
* @param rootNode the node where the the pagination will be attached to
* @param targetEntities the list of classes which requires pagination
* @param currentUser the current logged user
* @param options holds the pagination definitions
* @param filters the query filters used in the count query
*/
void addPaginationToNode(final RootNode rootNode, final Set<Class<? extends BaseIdentifiableObject>> targetEntities, final User currentUser, final WebOptions options, final Set<String> filters) {
if (options.hasPaging() && isNotEmpty(targetEntities)) {
// Defining query params map and setting common params.
final MapSqlParameterSource paramsMap = new MapSqlParameterSource().addValue(QueryParam.USER_UID, currentUser.getUid());
setFilteringParams(filters, options, paramsMap, currentUser);
final AtomicLong count = new AtomicLong();
// Counting and summing up the results for each entity.
count.addAndGet(pageCountingCache.get(createPageCountingCacheKey(currentUser, targetEntities, filters, options), p -> countEntityRowsTotal(targetEntities, options, paramsMap)));
final Pager pager = new Pager(options.getPage(), count.get(), options.getPageSize());
linkService.generatePagerLinks(pager, API_RESOURCE_PATH);
rootNode.addChild(createPager(pager));
}
}
Aggregations