Search in sources :

Example 1 with Approval

use of org.hisp.dhis.webapi.webdomain.approval.Approval in project dhis2-core by dhis2.

the class DataApprovalController method getDataApprovalList.

private List<DataApproval> getDataApprovalList(Approvals approvals) throws WebMessageException {
    List<DataSet> dataSets = objectManager.getByUid(DataSet.class, approvals.getDs());
    List<Period> periods = PeriodType.getPeriodsFromIsoStrings(approvals.getPe());
    periods = periodService.reloadPeriods(periods);
    User user = currentUserService.getCurrentUser();
    DataElementCategoryOptionCombo defaultOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    Date date = new Date();
    // Avoid duplicates when different data sets have the same work flow
    Set<DataApproval> set = new HashSet<>();
    for (DataSet dataSet : dataSets) {
        if (dataSet.getWorkflow() == null) {
            throw new WebMessageException(WebMessageUtils.conflict("DataSet has no approval workflow: " + dataSet.getName()));
        }
        Set<DataElementCategoryOptionCombo> dataSetOptionCombos = dataSet.getCategoryCombo() != null ? dataSet.getCategoryCombo().getOptionCombos() : null;
        for (Approval approval : approvals.getApprovals()) {
            OrganisationUnit unit = organisationUnitService.getOrganisationUnit(approval.getOu());
            DataElementCategoryOptionCombo optionCombo = categoryService.getDataElementCategoryOptionCombo(approval.getAoc());
            optionCombo = ObjectUtils.firstNonNull(optionCombo, defaultOptionCombo);
            for (Period period : periods) {
                if (dataSetOptionCombos != null && dataSetOptionCombos.contains(optionCombo)) {
                    DataApproval dataApproval = new DataApproval(null, dataSet.getWorkflow(), period, unit, optionCombo, false, date, user);
                    set.add(dataApproval);
                }
            }
        }
    }
    return new ArrayList<>(set);
}
Also used : DataApproval(org.hisp.dhis.dataapproval.DataApproval) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) Date(java.util.Date) Approval(org.hisp.dhis.webapi.webdomain.approval.Approval) DataApproval(org.hisp.dhis.dataapproval.DataApproval) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) HashSet(java.util.HashSet)

Aggregations

Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 DataApproval (org.hisp.dhis.dataapproval.DataApproval)1 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)1 DataSet (org.hisp.dhis.dataset.DataSet)1 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Period (org.hisp.dhis.period.Period)1 User (org.hisp.dhis.user.User)1 Approval (org.hisp.dhis.webapi.webdomain.approval.Approval)1