use of org.hisp.dhis.dataapproval.DataApproval 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);
}
use of org.hisp.dhis.dataapproval.DataApproval in project dhis2-core by dhis2.
the class DataApprovalController method removeApproval.
// -------------------------------------------------------------------------
// Delete
// -------------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')")
@RequestMapping(value = APPROVALS_PATH, method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void removeApproval(@RequestParam Set<String> ds, @RequestParam String pe, @RequestParam String ou, HttpServletResponse response) throws WebMessageException {
Set<DataSet> dataSets = parseDataSetsWithWorkflow(ds);
if (dataSets.size() != ds.size()) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal data set identifier in this list: " + ds));
}
Period period = getAndValidatePeriod(pe);
OrganisationUnit organisationUnit = getAndValidateOrgUnit(ou);
DataApprovalLevel dataApprovalLevel = getAndValidateApprovalLevel(organisationUnit);
User user = currentUserService.getCurrentUser();
List<DataApproval> dataApprovalList = newArrayList();
for (DataSet dataSet : dataSets) {
dataApprovalList.addAll(getApprovalsAsList(dataApprovalLevel, dataSet.getWorkflow(), period, organisationUnit, false, new Date(), user));
}
dataApprovalService.unapproveData(dataApprovalList);
}
use of org.hisp.dhis.dataapproval.DataApproval in project dhis2-core by dhis2.
the class DataApprovalController method acceptApproval.
// -------------------------------------------------------------------------
// Post, acceptance
// -------------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_ACCEPT_DATA_LOWER_LEVELS')")
@RequestMapping(value = ACCEPTANCES_PATH, method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void acceptApproval(@RequestParam(required = false) String ds, @RequestParam(required = false) String wf, @RequestParam String pe, @RequestParam String ou, HttpServletResponse response) throws WebMessageException {
DataApprovalWorkflow workflow = getAndValidateWorkflow(ds, wf);
Period period = getAndValidatePeriod(pe);
OrganisationUnit organisationUnit = getAndValidateOrgUnit(ou);
DataApprovalLevel dataApprovalLevel = getAndValidateApprovalLevel(organisationUnit);
User user = currentUserService.getCurrentUser();
List<DataApproval> dataApprovalList = getApprovalsAsList(dataApprovalLevel, workflow, period, organisationUnit, false, new Date(), user);
dataApprovalService.acceptData(dataApprovalList);
}
use of org.hisp.dhis.dataapproval.DataApproval in project dhis2-core by dhis2.
the class DataApprovalController method unacceptApproval.
@PreAuthorize("hasRole('ALL') or hasRole('F_ACCEPT_DATA_LOWER_LEVELS')")
@RequestMapping(value = ACCEPTANCES_PATH, method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void unacceptApproval(@RequestParam(required = false) String ds, @RequestParam(required = false) String wf, @RequestParam String pe, @RequestParam String ou, HttpServletResponse response) throws WebMessageException {
DataApprovalWorkflow workflow = getAndValidateWorkflow(ds, wf);
Period period = getAndValidatePeriod(pe);
OrganisationUnit organisationUnit = getAndValidateOrgUnit(ou);
DataApprovalLevel dataApprovalLevel = getAndValidateApprovalLevel(organisationUnit);
User user = currentUserService.getCurrentUser();
List<DataApproval> dataApprovalList = getApprovalsAsList(dataApprovalLevel, workflow, period, organisationUnit, false, new Date(), user);
dataApprovalService.unacceptData(dataApprovalList);
}
use of org.hisp.dhis.dataapproval.DataApproval in project dhis2-core by dhis2.
the class DataSetServiceTest method approveData.
private void approveData(DataSet dataSet, Period period, OrganisationUnit unit) {
DataApprovalLevel level = new DataApprovalLevel("Level A", unit.getLevel(), null);
levelService.addDataApprovalLevel(level);
DataApprovalWorkflow workflow = new DataApprovalWorkflow("Workflow A", period.getPeriodType(), newHashSet(level));
dataApprovalService.addWorkflow(workflow);
dataSet.setWorkflow(workflow);
dataSetService.updateDataSet(dataSet);
User user = mockCurrentUserService.getCurrentUser();
DataApproval approval = new DataApproval(level, workflow, period, unit, attributeOptionCombo, false, new Date(), user);
approvalService.approveData(newArrayList(approval));
}
Aggregations