Search in sources :

Example 1 with DataApprovalStateResponses

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

the class DataApprovalController method getApproval.

@RequestMapping(value = STATUS_PATH, method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getApproval(@RequestParam Set<String> ds, @RequestParam(required = false) String pe, @RequestParam Date startDate, @RequestParam Date endDate, @RequestParam Set<String> ou, @RequestParam(required = false) boolean children, HttpServletResponse response) throws IOException, WebMessageException {
    List<String> fields = Lists.newArrayList(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 = new HashSet<>();
    PeriodType periodType = periodService.getPeriodTypeByName(pe);
    if (periodType != null) {
        periods.addAll(periodService.getPeriodsBetweenDates(periodType, startDate, endDate));
    } else {
        periods.addAll(periodService.getPeriodsBetweenDates(startDate, endDate));
    }
    Set<OrganisationUnit> organisationUnits = new HashSet<>();
    if (children) {
        organisationUnits.addAll(organisationUnitService.getOrganisationUnitsWithChildren(ou));
    } else {
        organisationUnits.addAll(organisationUnitService.getOrganisationUnitsByUid(ou));
    }
    DataApprovalStateResponses dataApprovalStateResponses = new DataApprovalStateResponses();
    for (DataSet dataSet : dataSets) {
        for (OrganisationUnit organisationUnit : organisationUnits) {
            for (Period period : periods) {
                dataApprovalStateResponses.add(getDataApprovalStateResponse(dataSet, organisationUnit, period));
            }
        }
    }
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.filter(DataApprovalStateResponse.class, dataApprovalStateResponses.getDataApprovalStateResponses(), fields));
    return rootNode;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) RootNode(org.hisp.dhis.node.types.RootNode) DataSet(org.hisp.dhis.dataset.DataSet) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) DataApprovalStateResponses(org.hisp.dhis.dataapproval.DataApprovalStateResponses) Period(org.hisp.dhis.period.Period) DataApprovalStateResponse(org.hisp.dhis.dataapproval.DataApprovalStateResponse) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 DataApprovalStateResponse (org.hisp.dhis.dataapproval.DataApprovalStateResponse)1 DataApprovalStateResponses (org.hisp.dhis.dataapproval.DataApprovalStateResponses)1 DataSet (org.hisp.dhis.dataset.DataSet)1 RootNode (org.hisp.dhis.node.types.RootNode)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Period (org.hisp.dhis.period.Period)1 PeriodType (org.hisp.dhis.period.PeriodType)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1