use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValuesXmlWithAttributePreheatCacheTrue.
@Test
public void testImportDataValuesXmlWithAttributePreheatCacheTrue() throws Exception {
in = new ClassPathResource("datavalueset/dataValueSetBAttribute.xml").getInputStream();
ImportOptions importOptions = new ImportOptions().setPreheatCache(true).setIdScheme(IdScheme.ATTR_ID_SCHEME_PREFIX + ATTRIBUTE_UID).setDataElementIdScheme(IdScheme.ATTR_ID_SCHEME_PREFIX + ATTRIBUTE_UID).setOrgUnitIdScheme(IdScheme.ATTR_ID_SCHEME_PREFIX + ATTRIBUTE_UID);
ImportSummary summary = dataValueSetService.saveDataValueSet(in, importOptions);
assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
assertEquals(12, summary.getImportCount().getImported());
assertEquals(0, summary.getImportCount().getUpdated());
assertEquals(0, summary.getImportCount().getDeleted());
assertEquals(0, summary.getImportCount().getIgnored());
assertEquals(ImportStatus.SUCCESS, summary.getStatus());
assertImportDataValues(summary);
}
use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValuesXmlWithCodePreheatCacheTrue.
@Test
public void testImportDataValuesXmlWithCodePreheatCacheTrue() throws Exception {
in = new ClassPathResource("datavalueset/dataValueSetBCode.xml").getInputStream();
ImportOptions importOptions = new ImportOptions().setPreheatCache(true).setIdScheme("CODE").setDataElementIdScheme("CODE").setOrgUnitIdScheme("CODE");
ImportSummary summary = dataValueSetService.saveDataValueSet(in, importOptions);
assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
assertEquals(12, summary.getImportCount().getImported());
assertEquals(0, summary.getImportCount().getUpdated());
assertEquals(0, summary.getImportCount().getDeleted());
assertEquals(0, summary.getImportCount().getIgnored());
assertEquals(ImportStatus.SUCCESS, summary.getStatus());
assertImportDataValues(summary);
}
use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValuesXmlDryRun.
@Test
public void testImportDataValuesXmlDryRun() throws Exception {
in = new ClassPathResource("datavalueset/dataValueSetB.xml").getInputStream();
ImportOptions importOptions = new ImportOptions().setDryRun(true).setIdScheme("UID").setDataElementIdScheme("UID").setOrgUnitIdScheme("UID");
ImportSummary summary = dataValueSetService.saveDataValueSet(in, importOptions);
assertEquals(ImportStatus.SUCCESS, summary.getStatus());
assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
assertNotNull(dataValues);
assertEquals(0, dataValues.size());
}
use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.
the class AnalyticsUtils method getDataValueSetFromGrid.
/**
* Generates a data value set based on the given grid with aggregated data.
* Sets the created and last updated fields to the current date.
*
* @param params the data query parameters.
* @param grid the grid.
* @return a data value set.
*/
public static DataValueSet getDataValueSetFromGrid(DataQueryParams params, Grid grid) {
int dxInx = grid.getIndexOfHeader(DATA_X_DIM_ID);
int peInx = grid.getIndexOfHeader(PERIOD_DIM_ID);
int ouInx = grid.getIndexOfHeader(ORGUNIT_DIM_ID);
int coInx = grid.getIndexOfHeader(CATEGORYOPTIONCOMBO_DIM_ID);
int aoInx = grid.getIndexOfHeader(ATTRIBUTEOPTIONCOMBO_DIM_ID);
int vlInx = grid.getWidth() - 1;
Assert.isTrue(dxInx >= 0, "Data dimension index must be greater than or equal to zero");
Assert.isTrue(peInx >= 0, "Period dimension index must be greater than or equal to zero");
Assert.isTrue(ouInx >= 0, "Org unit dimension index must be greater than or equal to zero");
Assert.isTrue(coInx >= 0, "Category option combo dimension index must be greater than or equal to zero");
Assert.isTrue(aoInx >= 0, "Attribute option combo dimension index must be greater than or equal to zero");
Assert.isTrue(vlInx >= 0, "Value index must be greater than or equal to zero");
String created = DateUtils.getMediumDateString();
DataValueSet dvs = new DataValueSet();
Set<String> primaryKeys = Sets.newHashSet();
for (List<Object> row : grid.getRows()) {
DataValue dv = new DataValue();
Object coc = row.get(coInx);
Object aoc = row.get(aoInx);
dv.setDataElement(String.valueOf(row.get(dxInx)));
dv.setPeriod(String.valueOf(row.get(peInx)));
dv.setOrgUnit(String.valueOf(row.get(ouInx)));
dv.setCategoryOptionCombo(coc != null ? String.valueOf(coc) : null);
dv.setAttributeOptionCombo(aoc != null ? String.valueOf(aoc) : null);
dv.setValue(String.valueOf(row.get(vlInx)));
dv.setComment(KEY_AGG_VALUE);
dv.setStoredBy(KEY_AGG_VALUE);
dv.setCreated(created);
dv.setLastUpdated(created);
if (!params.isDuplicatesOnly() || !primaryKeys.add(dv.getPrimaryKey())) {
dvs.getDataValues().add(dv);
}
}
return dvs;
}
use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.
the class AnalyticsServiceTest method testSetAggregation.
@Test
public void testSetAggregation() {
// Params: Sum for all org units for 2017
DataValueSet aggregatedDataValueSet = analyticsService.getAggregatedDataValueSet(dataQueryParams.get("deC_ouB_2017_03"));
AnalyticsTestUtils.assertResultSet(aggregatedDataValueSet, results.get("deC_ouB_2017_03"));
// Params: Sum for all org unit A, in data element a in Q1 2017
aggregatedDataValueSet = analyticsService.getAggregatedDataValueSet(dataQueryParams.get("deA_ouA_2017_Q01"));
AnalyticsTestUtils.assertResultSet(aggregatedDataValueSet, results.get("deA_ouA_2017_Q01"));
}
Aggregations