Search in sources :

Example 1 with DataApprovalAuditQueryParams

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

use of org.hisp.dhis.dataapproval.DataApprovalAuditQueryParams in project dhis2-core by dhis2.

the class AuditController method getDataApprovalAudit.

@GetMapping("dataApproval")
@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) Boolean paging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) {
    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;
    RootNode rootNode = NodeUtils.createMetadata();
    if (!PagerUtils.isSkipPaging(skipPaging, paging)) {
        pager = new Pager(page, audits.size(), pageSize);
        audits = audits.subList(pager.getOffset(), Math.min(pager.getOffset() + pager.getPageSize(), audits.size()));
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    CollectionNode dataApprovalAudits = rootNode.addChild(new CollectionNode("dataApprovalAudits", true));
    dataApprovalAudits.addChildren(fieldFilterService.toCollectionNode(DataApprovalAudit.class, new FieldFilterParams(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) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) DataApprovalAudit(org.hisp.dhis.dataapproval.DataApprovalAudit) CollectionNode(org.hisp.dhis.node.types.CollectionNode) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

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