Search in sources :

Example 76 with DataValueSet

use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.

the class DataValueSetImportValidatorTest method testValidateDataSetExists.

/*
     * Data Set validation (should the set be aborted)
     */
@Test
void testValidateDataSetExists() {
    DataValueSet dataValueSet = createEmptyDataValueSet();
    ImportContext context = createMinimalImportContext(null).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    assertTrue(validator.abortDataSetImport(dataValueSet, context, dataSetContext));
    assertConflict(ErrorCode.E7600, "Data set not found or not accessible: `<object1>`", context, dataValueSet.getDataSet());
}
Also used : DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) Test(org.junit.jupiter.api.Test)

Example 77 with DataValueSet

use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.

the class AnalyticsUtilsTest method testGetDataValueSetFromGrid.

@Test
void testGetDataValueSetFromGrid() {
    Grid grid = new ListGrid();
    grid.addHeader(new GridHeader(DimensionalObject.DATA_X_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ORGUNIT_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.PERIOD_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.CATEGORYOPTIONCOMBO_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ATTRIBUTEOPTIONCOMBO_DIM_ID));
    grid.addHeader(new GridHeader(VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, false, false));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouA", "peA", "coA", "aoA", 1d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouA", "peB", null, null, 2d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouB", "peA", null, null, 3d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouB", "peB", null, null, 4d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxB", "ouA", "peA", "coA", null, 5d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxB", "ouA", "peB", "coA", "aoB", 6d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxC", "ouA", "peA", null, "aoA", 7));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxC", "ouA", "peB", null, null, 8d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxD", "ouA", "peA", "coB", null, 9d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxE", "ouA", "peB", null, null, 10));
    DataValueSet dvs = AnalyticsUtils.getDataValueSetFromGrid(DataQueryParams.newBuilder().build(), grid);
    assertNotNull(dvs);
    assertNotNull(dvs.getDataValues());
    assertEquals(10, dvs.getDataValues().size());
    assertEquals("dxA", dvs.getDataValues().get(1).getDataElement());
    assertEquals("ouA", dvs.getDataValues().get(1).getOrgUnit());
    assertEquals("peB", dvs.getDataValues().get(1).getPeriod());
    assertNull(dvs.getDataValues().get(1).getCategoryOptionCombo());
    assertNull(dvs.getDataValues().get(1).getAttributeOptionCombo());
    assertEquals("2.0", dvs.getDataValues().get(1).getValue());
    assertEquals("dxB", dvs.getDataValues().get(4).getDataElement());
    assertEquals("ouA", dvs.getDataValues().get(4).getOrgUnit());
    assertEquals("peA", dvs.getDataValues().get(4).getPeriod());
    assertEquals("coA", dvs.getDataValues().get(4).getCategoryOptionCombo());
    assertNull(dvs.getDataValues().get(4).getAttributeOptionCombo());
    assertEquals("5.0", dvs.getDataValues().get(4).getValue());
    assertEquals("dxC", dvs.getDataValues().get(6).getDataElement());
    assertEquals("ouA", dvs.getDataValues().get(6).getOrgUnit());
    assertEquals("peA", dvs.getDataValues().get(6).getPeriod());
    assertNull(dvs.getDataValues().get(6).getCategoryOptionCombo());
    assertEquals("aoA", dvs.getDataValues().get(6).getAttributeOptionCombo());
    assertEquals("7", dvs.getDataValues().get(6).getValue());
    assertEquals("dxD", dvs.getDataValues().get(8).getDataElement());
    assertEquals("ouA", dvs.getDataValues().get(8).getOrgUnit());
    assertEquals("peA", dvs.getDataValues().get(8).getPeriod());
    assertEquals("coB", dvs.getDataValues().get(8).getCategoryOptionCombo());
    assertNull(dvs.getDataValues().get(8).getAttributeOptionCombo());
    assertEquals("9.0", dvs.getDataValues().get(8).getValue());
    assertEquals("dxE", dvs.getDataValues().get(9).getDataElement());
    assertEquals("ouA", dvs.getDataValues().get(9).getOrgUnit());
    assertEquals("peB", dvs.getDataValues().get(9).getPeriod());
    assertNull(dvs.getDataValues().get(9).getCategoryOptionCombo());
    assertNull(dvs.getDataValues().get(9).getAttributeOptionCombo());
    assertEquals("10", dvs.getDataValues().get(9).getValue());
}
Also used : DataValueSet(org.hisp.dhis.dxf2.datavalueset.DataValueSet) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 78 with DataValueSet

use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.

the class AnalyticsUtilsTest method testGetDataValueSetFromGridEmpty.

@Test
void testGetDataValueSetFromGridEmpty() {
    Grid grid = new ListGrid();
    grid.addHeader(new GridHeader(DimensionalObject.DATA_X_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ORGUNIT_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.PERIOD_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.CATEGORYOPTIONCOMBO_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ATTRIBUTEOPTIONCOMBO_DIM_ID));
    grid.addHeader(new GridHeader(VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, false, false));
    DataValueSet dvs = AnalyticsUtils.getDataValueSetFromGrid(DataQueryParams.newBuilder().build(), grid);
    assertNotNull(dvs);
    assertNotNull(dvs.getDataValues());
    assertEquals(0, dvs.getDataValues().size());
}
Also used : DataValueSet(org.hisp.dhis.dxf2.datavalueset.DataValueSet) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 79 with DataValueSet

use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.

the class DataSetController method getDvs.

@GetMapping("/{uid}/dataValueSet")
@ResponseBody
public RootNode getDvs(@PathVariable("uid") String uid, @RequestParam(value = "orgUnitIdScheme", defaultValue = "ID", required = false) String orgUnitIdScheme, @RequestParam(value = "dataElementIdScheme", defaultValue = "ID", required = false) String dataElementIdScheme, @RequestParam(value = "period", defaultValue = "", required = false) String period, @RequestParam(value = "orgUnit", defaultValue = "", required = false) List<String> orgUnits, @RequestParam(value = "comment", defaultValue = "true", required = false) boolean comment, TranslateParams translateParams, HttpServletResponse response) throws IOException, WebMessageException {
    setUserContext(translateParams);
    List<DataSet> dataSets = getEntity(uid, NO_WEB_OPTIONS);
    if (dataSets.isEmpty()) {
        throw new WebMessageException(notFound("DataSet not found for uid: " + uid));
    }
    Period pe = periodService.getPeriod(period);
    return dataValueSetService.getDataValueSetTemplate(dataSets.get(0), pe, orgUnits, comment, orgUnitIdScheme, dataElementIdScheme);
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Period(org.hisp.dhis.period.Period) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Test (org.junit.jupiter.api.Test)63 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)56 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)41 ClassPathResource (org.springframework.core.io.ClassPathResource)39 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)24 DataValue (org.hisp.dhis.datavalue.DataValue)21 DhisTest (org.hisp.dhis.DhisTest)12 DataValueSet (org.hisp.dhis.dxf2.datavalueset.DataValueSet)9 DataValueAudit (org.hisp.dhis.datavalue.DataValueAudit)8 DataSetContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext)8 DataSet (org.hisp.dhis.dataset.DataSet)6 Period (org.hisp.dhis.period.Period)6 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)5 ImportCount (org.hisp.dhis.dxf2.importsummary.ImportCount)5 ListGrid (org.hisp.dhis.system.grid.ListGrid)5 IdScheme (org.hisp.dhis.common.IdScheme)4 DataElement (org.hisp.dhis.dataelement.DataElement)4 IdentifiableObjectCallable (org.hisp.dhis.system.callable.IdentifiableObjectCallable)4 Date (java.util.Date)3 List (java.util.List)3