Search in sources :

Example 21 with DataApprovalWorkflow

use of org.hisp.dhis.dataapproval.DataApprovalWorkflow in project dhis2-core by dhis2.

the class DataApprovalController method getApprovalPermissions.

// -------------------------------------------------------------------------
// Get
// -------------------------------------------------------------------------
@RequestMapping(value = APPROVALS_PATH, method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
public void getApprovalPermissions(@RequestParam(required = false) String ds, @RequestParam(required = false) String wf, @RequestParam String pe, @RequestParam String ou, HttpServletResponse response) throws IOException, WebMessageException {
    DataApprovalWorkflow workflow = getAndValidateWorkflow(ds, wf);
    Period period = getAndValidatePeriod(pe);
    OrganisationUnit organisationUnit = getAndValidateOrgUnit(ou);
    DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    DataApprovalStatus status = dataApprovalService.getDataApprovalStatusAndPermissions(workflow, period, organisationUnit, optionCombo);
    DataApprovalPermissions permissions = status.getPermissions();
    permissions.setState(status.getState().toString());
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    renderService.toJson(response.getOutputStream(), 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) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with DataApprovalWorkflow

use of org.hisp.dhis.dataapproval.DataApprovalWorkflow in project dhis2-core by dhis2.

the class DataApprovalController method saveApprovalMultiple.

@PreAuthorize("hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')")
@RequestMapping(value = MULTIPLE_SAVE_RESOURCE_PATH, method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void saveApprovalMultiple(@RequestBody DataApprovalStateRequests dataApprovalStateRequests, HttpServletResponse response) throws WebMessageException {
    List<DataApproval> dataApprovalList = new ArrayList<>();
    for (DataApprovalStateRequest approvalStateRequest : dataApprovalStateRequests) {
        DataApprovalWorkflow workflow = getAndValidateWorkflow(approvalStateRequest.getDs(), null);
        Period period = getAndValidatePeriod(approvalStateRequest.getPe());
        OrganisationUnit organisationUnit = getAndValidateOrgUnit(approvalStateRequest.getOu());
        DataApprovalLevel dataApprovalLevel = getAndValidateApprovalLevel(organisationUnit);
        User user = approvalStateRequest.getAb() == null ? currentUserService.getCurrentUser() : userService.getUserCredentialsByUsername(approvalStateRequest.getAb()).getUserInfo();
        Date approvalDate = approvalStateRequest.getAd() == null ? new Date() : approvalStateRequest.getAd();
        dataApprovalList.addAll(getApprovalsAsList(dataApprovalLevel, workflow, period, organisationUnit, false, approvalDate, user));
    }
    dataApprovalService.approveData(dataApprovalList);
}
Also used : DataApproval(org.hisp.dhis.dataapproval.DataApproval) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) User(org.hisp.dhis.user.User) DataApprovalStateRequest(org.hisp.dhis.dataapproval.DataApprovalStateRequest) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) 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 23 with DataApprovalWorkflow

use of org.hisp.dhis.dataapproval.DataApprovalWorkflow in project dhis2-core by dhis2.

the class DataSetApprovalFrequencyComparatorTest method testD.

@Test
void testD() {
    DataSet dsA = new DataSet("EA: Expenditures Site Level", new QuarterlyPeriodType());
    DataSet dsB = new DataSet("MER Results: Facility Based", new QuarterlyPeriodType());
    DataSet dsC = new DataSet("MER Results: Facility Based - DoD ONLY", new QuarterlyPeriodType());
    DataApprovalWorkflow workflow = new DataApprovalWorkflow("Workflow A", new QuarterlyPeriodType(), null);
    dsB.assignWorkflow(workflow);
    DataElement deA = new DataElement();
    dsA.addDataSetElement(deA);
    dsB.addDataSetElement(deA);
    dsC.addDataSetElement(deA);
    assertEquals(dsB, deA.getApprovalDataSet());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataSet(org.hisp.dhis.dataset.DataSet) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) Test(org.junit.jupiter.api.Test)

Example 24 with DataApprovalWorkflow

use of org.hisp.dhis.dataapproval.DataApprovalWorkflow in project dhis2-core by dhis2.

the class DataSetApprovalFrequencyComparatorTest method testA.

@Test
void testA() {
    DataSet dsA = new DataSet("DataSetA", new YearlyPeriodType());
    DataSet dsB = new DataSet("DataSetB", new YearlyPeriodType());
    DataSet dsC = new DataSet("DataSetC", new MonthlyPeriodType());
    DataSet dsD = new DataSet("DataSetD", new QuarterlyPeriodType());
    DataApprovalWorkflow workflow = new DataApprovalWorkflow("Workflow A", new QuarterlyPeriodType(), null);
    dsA.assignWorkflow(workflow);
    dsD.assignWorkflow(workflow);
    List<DataSet> list = Lists.newArrayList(dsA, dsC, dsB, dsD);
    Collections.sort(list, DataSetApprovalFrequencyComparator.INSTANCE);
    assertEquals(dsD, list.get(0));
    assertEquals(dsA, list.get(1));
    assertEquals(dsC, list.get(2));
    assertEquals(dsB, list.get(3));
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) Test(org.junit.jupiter.api.Test)

Example 25 with DataApprovalWorkflow

use of org.hisp.dhis.dataapproval.DataApprovalWorkflow in project dhis2-core by dhis2.

the class DataOrgUnitSplitHandlerTest method setUpTest.

@Override
public void setUpTest() {
    cocA = categoryService.getDefaultCategoryOptionCombo();
    deA = createDataElement('A');
    deB = createDataElement('B');
    idObjectManager.save(deA);
    idObjectManager.save(deB);
    PeriodType monthly = periodService.getPeriodTypeByClass(MonthlyPeriodType.class);
    peA = monthly.createPeriod("202101");
    peB = monthly.createPeriod("202102");
    periodService.addPeriod(peA);
    periodService.addPeriod(peB);
    ouA = createOrganisationUnit('A');
    ouB = createOrganisationUnit('B');
    ouC = createOrganisationUnit('C');
    idObjectManager.save(ouA);
    idObjectManager.save(ouB);
    idObjectManager.save(ouC);
    usA = createUser('A');
    userService.addUser(usA);
    dlA = new DataApprovalLevel("DataApprovalLevelA", 1);
    idObjectManager.save(dlA);
    dwA = new DataApprovalWorkflow("DataApprovalWorkflowA", monthly, Sets.newHashSet(dlA));
    idObjectManager.save(dwA);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow)

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