Search in sources :

Example 1 with API_RESOURCE_PATH

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));
    }
}
Also used : WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) FilteringHelper.setFilteringParams(org.hisp.dhis.webapi.controller.dataitem.helper.FilteringHelper.setFilteringParams) CollectionNode(org.hisp.dhis.node.types.CollectionNode) QueryExecutor(org.hisp.dhis.dataitem.query.QueryExecutor) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) DXF_2_0(org.hisp.dhis.common.DxfNamespaces.DXF_2_0) String.join(java.lang.String.join) User(org.hisp.dhis.user.User) LinkService(org.hisp.dhis.webapi.service.LinkService) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) Pager(org.hisp.dhis.common.Pager) FieldFilterService(org.hisp.dhis.fieldfilter.FieldFilterService) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) DataItem(org.hisp.dhis.dataitem.DataItem) Set(java.util.Set) CacheProvider(org.hisp.dhis.cache.CacheProvider) QueryParam(org.hisp.dhis.dataitem.query.shared.QueryParam) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Component(org.springframework.stereotype.Component) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) API_RESOURCE_PATH(org.hisp.dhis.webapi.controller.dataitem.DataItemQueryController.API_RESOURCE_PATH) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) NodeUtils.createPager(org.hisp.dhis.node.NodeUtils.createPager) Cache(org.hisp.dhis.cache.Cache) RootNode(org.hisp.dhis.node.types.RootNode) AtomicLong(java.util.concurrent.atomic.AtomicLong) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Pager(org.hisp.dhis.common.Pager) NodeUtils.createPager(org.hisp.dhis.node.NodeUtils.createPager)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 String.join (java.lang.String.join)1 List (java.util.List)1 Set (java.util.Set)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 CollectionUtils.isNotEmpty (org.apache.commons.collections4.CollectionUtils.isNotEmpty)1 Cache (org.hisp.dhis.cache.Cache)1 CacheProvider (org.hisp.dhis.cache.CacheProvider)1 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)1 DXF_2_0 (org.hisp.dhis.common.DxfNamespaces.DXF_2_0)1 Pager (org.hisp.dhis.common.Pager)1 DataItem (org.hisp.dhis.dataitem.DataItem)1 QueryExecutor (org.hisp.dhis.dataitem.query.QueryExecutor)1 QueryParam (org.hisp.dhis.dataitem.query.shared.QueryParam)1 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)1 FieldFilterService (org.hisp.dhis.fieldfilter.FieldFilterService)1 NodeUtils.createPager (org.hisp.dhis.node.NodeUtils.createPager)1 CollectionNode (org.hisp.dhis.node.types.CollectionNode)1 RootNode (org.hisp.dhis.node.types.RootNode)1