Search in sources :

Example 1 with DataApprovalAudit

use of org.hisp.dhis.dataapproval.DataApprovalAudit 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)

Aggregations

Pager (org.hisp.dhis.common.Pager)1 DataApprovalAudit (org.hisp.dhis.dataapproval.DataApprovalAudit)1 DataApprovalAuditQueryParams (org.hisp.dhis.dataapproval.DataApprovalAuditQueryParams)1 CollectionNode (org.hisp.dhis.node.types.CollectionNode)1 RootNode (org.hisp.dhis.node.types.RootNode)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1