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