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());
}
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());
}
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());
}
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);
}
Aggregations