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;
}
Aggregations