Search in sources :

Example 1 with Pager

use of org.hisp.dhis.common.Pager in project dhis2-core by dhis2.

the class AuditController method getDataApprovalAudit.

@RequestMapping(value = "dataApproval", method = RequestMethod.GET)
@ResponseBody
public RootNode getDataApprovalAudit(@RequestParam(required = false, defaultValue = "") List<String> dal, @RequestParam(required = false, defaultValue = "") List<String> wf, @RequestParam(required = false, defaultValue = "") List<String> ou, @RequestParam(required = false, defaultValue = "") List<String> aoc, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) throws WebMessageException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    DataApprovalAuditQueryParams params = new DataApprovalAuditQueryParams();
    params.setLevels(new HashSet<>(getDataApprovalLevel(dal)));
    params.setWorkflows(new HashSet<>(getDataApprovalWorkflow(wf)));
    params.setOrganisationUnits(new HashSet<>(getOrganisationUnit(ou)));
    params.setAttributeOptionCombos(new HashSet<>(getCategoryOptionCombo(aoc)));
    params.setStartDate(startDate);
    params.setEndDate(endDate);
    List<DataApprovalAudit> audits = dataApprovalAuditService.getDataApprovalAudits(params);
    Pager pager = null;
    RootNode rootNode = NodeUtils.createMetadata();
    if (!skipPaging) {
        pager = new Pager(page, audits.size(), pageSize);
        audits = audits.subList(pager.getOffset(), pager.getOffset() + pager.getPageSize() < audits.size() ? pager.getOffset() + pager.getPageSize() : audits.size());
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    CollectionNode dataApprovalAudits = rootNode.addChild(new CollectionNode("dataApprovalAudits", true));
    dataApprovalAudits.addChildren(fieldFilterService.filter(DataApprovalAudit.class, audits, fields).getChildren());
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DataApprovalAuditQueryParams(org.hisp.dhis.dataapproval.DataApprovalAuditQueryParams) Pager(org.hisp.dhis.common.Pager) DataApprovalAudit(org.hisp.dhis.dataapproval.DataApprovalAudit) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with Pager

use of org.hisp.dhis.common.Pager in project dhis2-core by dhis2.

the class AbstractCrudController method getObjectList.

//--------------------------------------------------------------------------
// GET
//--------------------------------------------------------------------------
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public RootNode getObjectList(@RequestParam Map<String, String> rpParameters, OrderParams orderParams, HttpServletResponse response, HttpServletRequest request, User currentUser) throws QueryParserException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    List<Order> orders = orderParams.getOrders(getSchema());
    if (fields.isEmpty()) {
        fields.addAll(Preset.defaultPreset().getFields());
    }
    WebOptions options = new WebOptions(rpParameters);
    WebMetadata metadata = new WebMetadata();
    if (!aclService.canRead(currentUser, getEntityClass())) {
        throw new ReadAccessDeniedException("You don't have the proper permissions to read objects of this type.");
    }
    List<T> entities = getEntityList(metadata, options, filters, orders);
    Pager pager = metadata.getPager();
    if (options.hasPaging() && pager == null) {
        pager = new Pager(options.getPage(), entities.size(), options.getPageSize());
        entities = PagerUtils.pageCollection(entities, pager);
    }
    postProcessEntities(entities);
    postProcessEntities(entities, options, rpParameters);
    handleLinksAndAccess(entities, fields, false, currentUser);
    linkService.generatePagerLinks(pager, getEntityClass());
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.getConfig().setInclusionStrategy(getInclusionStrategy(rpParameters.get("inclusionStrategy")));
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    rootNode.addChild(fieldFilterService.filter(getEntityClass(), entities, fields));
    return rootNode;
}
Also used : Order(org.hisp.dhis.query.Order) RootNode(org.hisp.dhis.node.types.RootNode) Pager(org.hisp.dhis.common.Pager) ReadAccessDeniedException(org.hisp.dhis.hibernate.exception.ReadAccessDeniedException) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with Pager

use of org.hisp.dhis.common.Pager in project dhis2-core by dhis2.

the class AuditController method getAggregateDataValueAudit.

@RequestMapping(value = "dataValue", method = RequestMethod.GET)
@ResponseBody
public RootNode getAggregateDataValueAudit(@RequestParam(required = false, defaultValue = "") List<String> ds, @RequestParam(required = false, defaultValue = "") List<String> de, @RequestParam(required = false, defaultValue = "") List<String> pe, @RequestParam(required = false, defaultValue = "") List<String> ou, @RequestParam(required = false) String co, @RequestParam(required = false) String cc, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) throws WebMessageException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    List<DataElement> dataElements = new ArrayList<>();
    dataElements.addAll(getDataElements(de));
    dataElements.addAll(getDataElementsByDataSet(ds));
    List<Period> periods = getPeriods(pe);
    List<OrganisationUnit> organisationUnits = getOrganisationUnit(ou);
    DataElementCategoryOptionCombo categoryOptionCombo = getCategoryOptionCombo(co);
    DataElementCategoryOptionCombo attributeOptionCombo = getAttributeOptionCombo(cc);
    List<DataValueAudit> dataValueAudits;
    Pager pager = null;
    if (skipPaging) {
        dataValueAudits = dataValueAuditService.getDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
    } else {
        int total = dataValueAuditService.countDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
        pager = new Pager(page, total, pageSize);
        dataValueAudits = dataValueAuditService.getDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType, pager.getOffset(), pager.getPageSize());
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("dataValueAudits", true));
    trackedEntityAttributeValueAudits.addChildren(fieldFilterService.filter(DataValueAudit.class, dataValueAudits, fields).getChildren());
    return rootNode;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) RootNode(org.hisp.dhis.node.types.RootNode) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) CollectionNode(org.hisp.dhis.node.types.CollectionNode) DataElement(org.hisp.dhis.dataelement.DataElement) Pager(org.hisp.dhis.common.Pager) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with Pager

use of org.hisp.dhis.common.Pager in project dhis2-core by dhis2.

the class AuditController method getTrackedEntityAttributeValueAudit.

@RequestMapping(value = "trackedEntityAttributeValue", method = RequestMethod.GET)
@ResponseBody
public RootNode getTrackedEntityAttributeValueAudit(@RequestParam(required = false, defaultValue = "") List<String> tea, @RequestParam(required = false, defaultValue = "") List<String> tei, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) throws WebMessageException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<TrackedEntityAttribute> trackedEntityAttributes = getTrackedEntityAttributes(tea);
    List<TrackedEntityInstance> trackedEntityInstances = getTrackedEntityInstances(tei);
    List<TrackedEntityAttributeValueAudit> attributeValueAudits;
    Pager pager = null;
    if (skipPaging) {
        attributeValueAudits = trackedEntityAttributeValueAuditService.getTrackedEntityAttributeValueAudits(trackedEntityAttributes, trackedEntityInstances, auditType);
    } else {
        int total = trackedEntityAttributeValueAuditService.countTrackedEntityAttributeValueAudits(trackedEntityAttributes, trackedEntityInstances, auditType);
        pager = new Pager(page, total, pageSize);
        attributeValueAudits = trackedEntityAttributeValueAuditService.getTrackedEntityAttributeValueAudits(trackedEntityAttributes, trackedEntityInstances, auditType, pager.getOffset(), pager.getPageSize());
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("trackedEntityAttributeValueAudits", true));
    trackedEntityAttributeValueAudits.addChildren(fieldFilterService.filter(TrackedEntityAttributeValueAudit.class, attributeValueAudits, fields).getChildren());
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Pager(org.hisp.dhis.common.Pager) TrackedEntityAttributeValueAudit(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAudit) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with Pager

use of org.hisp.dhis.common.Pager in project dhis2-core by dhis2.

the class DataElementOperandController method getObjectList.

@GetMapping
@SuppressWarnings("unchecked")
@ResponseBody
public RootNode getObjectList(@RequestParam Map<String, String> rpParameters, OrderParams orderParams) throws QueryParserException {
    Schema schema = schemaService.getDynamicSchema(DataElementOperand.class);
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    List<Order> orders = orderParams.getOrders(schema);
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    WebOptions options = new WebOptions(rpParameters);
    WebMetadata metadata = new WebMetadata();
    List<DataElementOperand> dataElementOperands;
    if (options.isTrue("persisted")) {
        dataElementOperands = Lists.newArrayList(manager.getAll(DataElementOperand.class));
    } else {
        boolean totals = options.isTrue("totals");
        String deg = CollectionUtils.popStartsWith(filters, "dataElement.dataElementGroups.id:eq:");
        deg = deg != null ? deg.substring("dataElement.dataElementGroups.id:eq:".length()) : null;
        String ds = options.get("dataSet");
        if (deg != null) {
            DataElementGroup dataElementGroup = manager.get(DataElementGroup.class, deg);
            dataElementOperands = dataElementCategoryService.getOperands(dataElementGroup.getMembers(), totals);
        } else if (ds != null) {
            DataSet dataSet = manager.get(DataSet.class, ds);
            dataElementOperands = dataElementCategoryService.getOperands(dataSet, totals);
        } else {
            List<DataElement> dataElements = new ArrayList<>(manager.getAllSorted(DataElement.class));
            dataElementOperands = dataElementCategoryService.getOperands(dataElements, totals);
        }
    }
    Query query = queryService.getQueryFromUrl(DataElementOperand.class, filters, orders, options.getRootJunction());
    query.setDefaultOrder();
    query.setObjects(dataElementOperands);
    dataElementOperands = (List<DataElementOperand>) queryService.query(query);
    Pager pager = metadata.getPager();
    if (options.hasPaging() && pager == null) {
        pager = new Pager(options.getPage(), dataElementOperands.size(), options.getPageSize());
        linkService.generatePagerLinks(pager, DataElementOperand.class);
        dataElementOperands = PagerUtils.pageCollection(dataElementOperands, pager);
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    rootNode.addChild(fieldFilterService.filter(DataElementOperand.class, dataElementOperands, fields));
    return rootNode;
}
Also used : Order(org.hisp.dhis.query.Order) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) RootNode(org.hisp.dhis.node.types.RootNode) Query(org.hisp.dhis.query.Query) DataSet(org.hisp.dhis.dataset.DataSet) Schema(org.hisp.dhis.schema.Schema) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) Pager(org.hisp.dhis.common.Pager) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) ArrayList(java.util.ArrayList) List(java.util.List) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Pager (org.hisp.dhis.common.Pager)42 RootNode (org.hisp.dhis.node.types.RootNode)18 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)17 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)13 GetMapping (org.springframework.web.bind.annotation.GetMapping)13 List (java.util.List)12 CollectionNode (org.hisp.dhis.node.types.CollectionNode)12 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)11 Schema (org.hisp.dhis.schema.Schema)11 HashMap (java.util.HashMap)10 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)9 ArrayList (java.util.ArrayList)8 WebMetadata (org.hisp.dhis.webapi.webdomain.WebMetadata)8 Test (org.junit.jupiter.api.Test)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Order (org.hisp.dhis.query.Order)5 Grid (org.hisp.dhis.common.Grid)4 Query (org.hisp.dhis.query.Query)4 Map (java.util.Map)3 DataElement (org.hisp.dhis.dataelement.DataElement)3