Search in sources :

Example 1 with TrackedEntityInstanceAuditQueryParams

use of org.hisp.dhis.trackedentity.TrackedEntityInstanceAuditQueryParams in project dhis2-core by dhis2.

the class AuditController method getTrackedEnityInstanceAudit.

@GetMapping("trackedEntityInstance")
@ResponseBody
public RootNode getTrackedEnityInstanceAudit(@RequestParam(required = false, defaultValue = "") List<String> tei, @RequestParam(required = false, defaultValue = "") List<String> user, @RequestParam(required = false) AuditType auditType, @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());
    }
    TrackedEntityInstanceAuditQueryParams params = new TrackedEntityInstanceAuditQueryParams();
    params.setTrackedEntityInstances(new HashSet<>(tei));
    params.setUsers(new HashSet<>(user));
    params.setAuditType(auditType);
    params.setStartDate(startDate);
    params.setEndDate(endDate);
    params.setSkipPaging(PagerUtils.isSkipPaging(skipPaging, paging));
    List<TrackedEntityInstanceAudit> teiAudits;
    Pager pager = null;
    if (!params.isSkipPaging()) {
        int total = trackedEntityInstanceAuditService.getTrackedEntityInstanceAuditsCount(params);
        pager = new Pager(page, total, pageSize);
        params.setFirst(pager.getOffset());
        params.setMax(pager.getPageSize());
    }
    teiAudits = trackedEntityInstanceAuditService.getTrackedEntityInstanceAudits(params);
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    CollectionNode trackedEntityInstanceAudits = rootNode.addChild(new CollectionNode("trackedEntityInstanceAudits", true));
    trackedEntityInstanceAudits.addChildren(fieldFilterService.toCollectionNode(TrackedEntityInstanceAudit.class, new FieldFilterParams(teiAudits, fields)).getChildren());
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) Pager(org.hisp.dhis.common.Pager) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) TrackedEntityInstanceAuditQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceAuditQueryParams) CollectionNode(org.hisp.dhis.node.types.CollectionNode) TrackedEntityInstanceAudit(org.hisp.dhis.audit.payloads.TrackedEntityInstanceAudit) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

TrackedEntityInstanceAudit (org.hisp.dhis.audit.payloads.TrackedEntityInstanceAudit)1 Pager (org.hisp.dhis.common.Pager)1 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)1 CollectionNode (org.hisp.dhis.node.types.CollectionNode)1 RootNode (org.hisp.dhis.node.types.RootNode)1 TrackedEntityInstanceAuditQueryParams (org.hisp.dhis.trackedentity.TrackedEntityInstanceAuditQueryParams)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1