Search in sources :

Example 11 with DataApprovalWorkflow

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) DataApproval(org.hisp.dhis.dataapproval.DataApproval) User(org.hisp.dhis.user.User) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Date(java.util.Date) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 12 with DataApprovalWorkflow

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;
}
Also used : CategoryService(org.hisp.dhis.category.CategoryService) RequestParam(org.springframework.web.bind.annotation.RequestParam) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) DataApprovalService(org.hisp.dhis.dataapproval.DataApprovalService) Date(java.util.Date) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) PeriodService(org.hisp.dhis.period.PeriodService) Autowired(org.springframework.beans.factory.annotation.Autowired) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) NodeUtils(org.hisp.dhis.node.NodeUtils) Collections.singleton(java.util.Collections.singleton) Map(java.util.Map) Preset(org.hisp.dhis.node.Preset) ApprovalDto(org.hisp.dhis.webapi.webdomain.approval.ApprovalDto) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) Period(org.hisp.dhis.period.Period) PostMapping(org.springframework.web.bind.annotation.PostMapping) ContextService(org.hisp.dhis.webapi.service.ContextService) Collection(java.util.Collection) FieldFilterService(org.hisp.dhis.fieldfilter.FieldFilterService) MediaType(org.springframework.http.MediaType) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) WebMessageUtils.conflict(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict) DataApprovalStateResponse(org.hisp.dhis.dataapproval.DataApprovalStateResponse) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DataApproval(org.hisp.dhis.dataapproval.DataApproval) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) RootNode(org.hisp.dhis.node.types.RootNode) ApprovalsDto(org.hisp.dhis.webapi.webdomain.approval.ApprovalsDto) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) DataApprovalStatus(org.hisp.dhis.dataapproval.DataApprovalStatus) DataSet(org.hisp.dhis.dataset.DataSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) ApprovalStatusDto(org.hisp.dhis.webapi.webdomain.approval.ApprovalStatusDto) Controller(org.springframework.stereotype.Controller) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RequestBody(org.springframework.web.bind.annotation.RequestBody) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) User(org.hisp.dhis.user.User) GetMapping(org.springframework.web.bind.annotation.GetMapping) BadRequestException(org.hisp.dhis.webapi.controller.exception.BadRequestException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) DataApprovalLevelService(org.hisp.dhis.dataapproval.DataApprovalLevelService) ContextUtils(org.hisp.dhis.webapi.utils.ContextUtils) DataApprovalPermissions(org.hisp.dhis.dataapproval.DataApprovalPermissions) HttpServletResponse(javax.servlet.http.HttpServletResponse) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ObjectUtils(org.hisp.dhis.util.ObjectUtils) HttpStatus(org.springframework.http.HttpStatus) Collectors.toList(java.util.stream.Collectors.toList) CurrentUserService(org.hisp.dhis.user.CurrentUserService) PeriodType(org.hisp.dhis.period.PeriodType) DataSetService(org.hisp.dhis.dataset.DataSetService) DataApproval(org.hisp.dhis.dataapproval.DataApproval) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) Date(java.util.Date) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) ApprovalDto(org.hisp.dhis.webapi.webdomain.approval.ApprovalDto)

Example 13 with DataApprovalWorkflow

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();
}
Also used : DataApprovalPermissions(org.hisp.dhis.dataapproval.DataApprovalPermissions) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Period(org.hisp.dhis.period.Period) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) DataApprovalStatus(org.hisp.dhis.dataapproval.DataApprovalStatus) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 14 with DataApprovalWorkflow

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) DataApprovalStatus(org.hisp.dhis.dataapproval.DataApprovalStatus) CategoryCombo(org.hisp.dhis.category.CategoryCombo) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 15 with DataApprovalWorkflow

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());
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Aggregations

DataApprovalWorkflow (org.hisp.dhis.dataapproval.DataApprovalWorkflow)32 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)20 Period (org.hisp.dhis.period.Period)19 DataApprovalLevel (org.hisp.dhis.dataapproval.DataApprovalLevel)18 DataApproval (org.hisp.dhis.dataapproval.DataApproval)16 User (org.hisp.dhis.user.User)15 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)13 Date (java.util.Date)11 ArrayList (java.util.ArrayList)10 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 DataSet (org.hisp.dhis.dataset.DataSet)9 DataApprovalStatus (org.hisp.dhis.dataapproval.DataApprovalStatus)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Map (java.util.Map)6 Set (java.util.Set)5 CategoryCombo (org.hisp.dhis.category.CategoryCombo)5 Test (org.junit.jupiter.api.Test)5 Collection (java.util.Collection)4 List (java.util.List)4