use of org.hisp.dhis.dataapproval.DataApprovalStateResponse in project dhis2-core by dhis2.
the class DataApprovalController method getApproval.
@GetMapping(value = STATUS_PATH, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getApproval(@RequestParam Set<String> ds, @RequestParam(required = false) String pe, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam Set<String> ou, @RequestParam(required = false) boolean children, HttpServletResponse response) throws WebMessageException, BadRequestException {
List<String> fields = new ArrayList<>(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
List<String> defaults = new ArrayList<>();
defaults.add("period[id,name,code],organisationUnit[id,name,created,lastUpdated],dataSet[code,name,created,lastUpdated,id]");
fields.addAll(defaults);
}
Set<DataSet> dataSets = parseDataSetsWithWorkflow(ds);
Set<Period> periods = parsePeriods(pe, startDate, endDate);
Set<OrganisationUnit> organisationUnits = new HashSet<>();
if (children) {
organisationUnits.addAll(organisationUnitService.getOrganisationUnitsWithChildren(ou));
} else {
organisationUnits.addAll(organisationUnitService.getOrganisationUnitsByUid(ou));
}
List<DataApprovalStateResponse> responses = new ArrayList<>();
for (DataSet dataSet : dataSets) {
for (OrganisationUnit organisationUnit : organisationUnits) {
for (Period period : periods) {
responses.add(getDataApprovalStateResponse(dataSet, organisationUnit, period));
}
}
}
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
RootNode rootNode = NodeUtils.createMetadata();
rootNode.addChild(fieldFilterService.toCollectionNode(DataApprovalStateResponse.class, new FieldFilterParams(responses, fields)));
return rootNode;
}
Aggregations