Search in sources :

Example 21 with DataValueSet

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);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 22 with DataValueSet

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);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 23 with DataValueSet

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());
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 24 with DataValueSet

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;
}
Also used : DataValueSet(org.hisp.dhis.dxf2.datavalueset.DataValueSet) DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DimensionalObject(org.hisp.dhis.common.DimensionalObject) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString)

Example 25 with DataValueSet

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"));
}
Also used : DataValueSet(org.hisp.dhis.dxf2.datavalueset.DataValueSet) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisTest(org.hisp.dhis.DhisTest)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)45 Test (org.junit.Test)43 ClassPathResource (org.springframework.core.io.ClassPathResource)39 DhisSpringTest (org.hisp.dhis.DhisSpringTest)31 DataValue (org.hisp.dhis.datavalue.DataValue)18 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)17 DhisTest (org.hisp.dhis.DhisTest)10 DataValueAudit (org.hisp.dhis.datavalue.DataValueAudit)5 DataValueSet (org.hisp.dhis.dxf2.datavalueset.DataValueSet)5 Period (org.hisp.dhis.period.Period)4 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)3 DataSet (org.hisp.dhis.dataset.DataSet)3 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)2 IdScheme (org.hisp.dhis.common.IdScheme)2 IdSchemes (org.hisp.dhis.common.IdSchemes)2 CachingMap (org.hisp.dhis.commons.collection.CachingMap)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 DataValue (org.hisp.dhis.dxf2.datavalue.DataValue)2 ImportConflict (org.hisp.dhis.dxf2.importsummary.ImportConflict)2 ImportCount (org.hisp.dhis.dxf2.importsummary.ImportCount)2