use of org.hisp.dhis.webapi.webdomain.approval.ApprovalDto in project dhis2-core by dhis2.
the class DataApprovalController method getDataApprovalList.
private List<DataApproval> getDataApprovalList(ApprovalsDto approvals) throws WebMessageException {
Set<DataApprovalWorkflow> workflows = getAndValidateWorkflows(approvals.getDs(), approvals.getWf());
List<Period> periods = PeriodType.getPeriodsFromIsoStrings(approvals.getPe());
periods = periodService.reloadPeriods(periods);
if (periods.isEmpty()) {
throw new WebMessageException(conflict("Approvals must have periods"));
}
User user = currentUserService.getCurrentUser();
CategoryOptionCombo defaultOptionCombo = categoryService.getDefaultCategoryOptionCombo();
Date date = new Date();
List<DataApproval> dataApprovals = new ArrayList<>();
List<CategoryOptionCombo> optionCombos = categoryService.getAllCategoryOptionCombos();
Map<String, CategoryOptionCombo> comboMap = optionCombos.stream().collect(Collectors.toMap(CategoryOptionCombo::getUid, c -> c));
Map<String, OrganisationUnit> ouCache = new HashMap<>();
for (ApprovalDto approval : approvals.getApprovals()) {
CategoryOptionCombo atributeOptionCombo = comboMap.get(approval.getAoc());
atributeOptionCombo = ObjectUtils.firstNonNull(atributeOptionCombo, defaultOptionCombo);
OrganisationUnit unit = ouCache.get(approval.getOu());
if (unit == null) {
unit = getAndValidateOrgUnit(approval.getOu());
ouCache.put(approval.getOu(), unit);
}
for (DataApprovalWorkflow workflow : workflows) {
for (Period period : periods) {
dataApprovals.add(new DataApproval(null, workflow, period, unit, atributeOptionCombo, false, date, user));
}
}
}
return dataApprovals;
}
Aggregations