use of org.hisp.dhis.dataapproval.DataApprovalWorkflow 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')")
@DeleteMapping(APPROVALS_PATH)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void removeApproval(@RequestParam(required = false) Set<String> ds, @RequestParam(required = false) Set<String> wf, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String aoc) throws WebMessageException {
Set<DataApprovalWorkflow> workflows = getAndValidateWorkflows(ds, wf);
Period period = getAndValidatePeriod(pe);
OrganisationUnit organisationUnit = getAndValidateOrgUnit(ou);
DataApprovalLevel dataApprovalLevel = getAndValidateApprovalLevel(organisationUnit);
CategoryOptionCombo optionCombo = getAndValidateAttributeOptionCombo(aoc);
User user = currentUserService.getCurrentUser();
List<DataApproval> dataApprovalList = new ArrayList<>();
for (DataApprovalWorkflow workflow : workflows) {
dataApprovalList.addAll(getApprovalsAsList(dataApprovalLevel, workflow, period, organisationUnit, optionCombo, false, new Date(), user));
}
dataApprovalService.unapproveData(dataApprovalList);
}
use of org.hisp.dhis.dataapproval.DataApprovalWorkflow 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;
}
use of org.hisp.dhis.dataapproval.DataApprovalWorkflow in project dhis2-core by dhis2.
the class DataApprovalController method getApprovalPermissions.
// -------------------------------------------------------------------------
// Get
// -------------------------------------------------------------------------
@GetMapping(value = APPROVALS_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public DataApprovalPermissions getApprovalPermissions(@RequestParam(required = false) String ds, @RequestParam(required = false) String wf, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String aoc) throws WebMessageException {
DataApprovalWorkflow workflow = getAndValidateWorkflow(ds, wf);
Period period = getAndValidatePeriod(pe);
OrganisationUnit organisationUnit = getAndValidateOrgUnit(ou);
CategoryOptionCombo optionCombo = getAndValidateAttributeOptionCombo(aoc);
DataApprovalStatus status = dataApprovalService.getDataApprovalStatus(workflow, period, organisationUnit, optionCombo);
DataApprovalPermissions permissions = status.getPermissions();
permissions.setState(status.getState().toString());
return status.getPermissions();
}
use of org.hisp.dhis.dataapproval.DataApprovalWorkflow in project dhis2-core by dhis2.
the class DataApprovalController method getApprovalByCategoryOptionCombos.
@GetMapping(value = APPROVALS_PATH + "/categoryOptionCombos", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public List<Map<String, Object>> getApprovalByCategoryOptionCombos(@RequestParam(required = false) Set<String> ds, @RequestParam(required = false) Set<String> wf, @RequestParam String pe, @RequestParam(required = false) String ou) throws WebMessageException {
Set<DataApprovalWorkflow> workflows = getAndValidateWorkflows(ds, wf);
Period period = getAndValidatePeriod(pe);
OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ou);
if (orgUnit != null && orgUnit.isRoot()) {
// Look for all org units.
orgUnit = null;
}
List<DataApprovalStatus> statusList = new ArrayList<>();
for (DataApprovalWorkflow workflow : workflows) {
Set<CategoryCombo> attributeCombos = new HashSet<>();
for (DataSet dataSet : workflow.getDataSets()) {
attributeCombos.add(dataSet.getCategoryCombo());
}
for (CategoryCombo attributeCombo : attributeCombos) {
statusList.addAll(dataApprovalService.getUserDataApprovalsAndPermissions(workflow, period, orgUnit, attributeCombo));
}
}
List<Map<String, Object>> list = new ArrayList<>();
for (DataApprovalStatus status : statusList) {
Map<String, Object> item = new HashMap<>();
Map<String, String> approvalLevel = new HashMap<>();
if (status.getApprovedLevel() != null) {
approvalLevel.put("id", status.getApprovedLevel().getUid());
approvalLevel.put("level", String.valueOf(status.getApprovedLevel().getLevel()));
}
item.put("id", status.getAttributeOptionComboUid());
item.put("level", approvalLevel);
item.put("ou", status.getOrganisationUnitUid());
item.put("ouName", status.getOrganisationUnitName());
item.put("accepted", status.isAccepted());
item.put("permissions", status.getPermissions());
list.add(item);
}
return list;
}
use of org.hisp.dhis.dataapproval.DataApprovalWorkflow in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testCheckDataValueNotAlreadyApproved.
@Test
void testCheckDataValueNotAlreadyApproved() {
DataValue dataValue = createRandomDataValue();
DataValueContext valueContext = createDataValueContext(dataValue).build();
DataSetContext dataSetContext = createMinimalDataSetContext(createEmptyDataValueSet()).build();
DataApprovalWorkflow workflow = new DataApprovalWorkflow();
workflow.setUid(CodeGenerator.generateUid());
dataSetContext.getDataSet().setWorkflow(workflow);
ImportContext context = createMinimalImportContext(valueContext).forceDataInput(false).build();
final String workflowPeriodAoc = workflow.getUid() + valueContext.getPeriod().getUid() + valueContext.getAttrOptionCombo().getUid();
String key = valueContext.getOrgUnit().getUid() + workflowPeriodAoc;
// already approved
context.getApprovalMap().put(key, true);
assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
assertConflict(ErrorCode.E7642, "Data is already approved for data set: `<object4>` period: `<object2>` organisation unit: `<object1>` attribute option combo: `<object3>`", context, dataValue.getOrgUnit(), dataValue.getPeriod(), dataValue.getAttributeOptionCombo(), dataSetContext.getDataSet().getUid());
}
Aggregations