Search in sources :

Example 1 with DataApproval

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);
}
Also used : DataApproval(org.hisp.dhis.dataapproval.DataApproval) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) Date(java.util.Date) Approval(org.hisp.dhis.webapi.webdomain.approval.Approval) DataApproval(org.hisp.dhis.dataapproval.DataApproval) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) HashSet(java.util.HashSet)

Example 2 with DataApproval

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);
}
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) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Period(org.hisp.dhis.period.Period) Date(java.util.Date) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with DataApproval

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);
}
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) Period(org.hisp.dhis.period.Period) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) Date(java.util.Date) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with DataApproval

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);
}
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) Period(org.hisp.dhis.period.Period) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) Date(java.util.Date) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with DataApproval

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));
}
Also used : DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) DataApproval(org.hisp.dhis.dataapproval.DataApproval) User(org.hisp.dhis.user.User) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) Date(java.util.Date)

Aggregations

DataApproval (org.hisp.dhis.dataapproval.DataApproval)11 Period (org.hisp.dhis.period.Period)9 Date (java.util.Date)8 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 User (org.hisp.dhis.user.User)8 DataApprovalLevel (org.hisp.dhis.dataapproval.DataApprovalLevel)7 DataApprovalWorkflow (org.hisp.dhis.dataapproval.DataApprovalWorkflow)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)6 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)4 ArrayList (java.util.ArrayList)4 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)3 DataSet (org.hisp.dhis.dataset.DataSet)3 DataApprovalStateRequest (org.hisp.dhis.dataapproval.DataApprovalStateRequest)2 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)2 HashSet (java.util.HashSet)1 Criteria (org.hibernate.Criteria)1 CachingMap (org.hisp.dhis.commons.collection.CachingMap)1 DataElement (org.hisp.dhis.dataelement.DataElement)1