Search in sources :

Example 11 with IdSchemes

use of org.hisp.dhis.common.IdSchemes in project dhis2-core by dhis2.

the class DataValueSetServiceExportTest method testExportLastUpdated.

@Test
public void testExportLastUpdated() {
    Date lastUpdated = getDate(1970, 1, 1);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    dataValueSetService.writeDataValueSetJson(lastUpdated, out, new IdSchemes());
    DataValueSet dvs = JacksonUtils.fromJson(out.toByteArray(), DataValueSet.class);
    assertNotNull(dvs);
    assertEquals(12, dvs.getDataValues().size());
    for (org.hisp.dhis.dxf2.datavalue.DataValue dv : dvs.getDataValues()) {
        assertNotNull(dv);
    }
}
Also used : IdSchemes(org.hisp.dhis.common.IdSchemes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Date(java.util.Date) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 12 with IdSchemes

use of org.hisp.dhis.common.IdSchemes in project dhis2-core by dhis2.

the class DataValueSetServiceExportTest method testExportOutputIdSchemeAttribute.

@Test
public void testExportOutputIdSchemeAttribute() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    String attributeIdScheme = IdScheme.ATTR_ID_SCHEME_PREFIX + atA.getUid();
    IdSchemes idSchemes = new IdSchemes().setDataElementIdScheme(attributeIdScheme).setOrgUnitIdScheme(attributeIdScheme).setCategoryOptionComboIdScheme(attributeIdScheme);
    DataExportParams params = new DataExportParams().setDataSets(Sets.newHashSet(dsB)).setOrganisationUnits(Sets.newHashSet(ouA)).setPeriods(Sets.newHashSet(peB)).setOutputIdSchemes(idSchemes);
    dataValueSetService.writeDataValueSetJson(params, out);
    DataValueSet dvs = JacksonUtils.fromJson(out.toByteArray(), DataValueSet.class);
    assertNotNull(dvs);
    assertNotNull(dvs.getDataSet());
    assertEquals(dsB.getUid(), dvs.getDataSet());
    assertEquals(2, dvs.getDataValues().size());
    for (org.hisp.dhis.dxf2.datavalue.DataValue dv : dvs.getDataValues()) {
        assertNotNull(dv);
        assertEquals(avA.getValue(), dv.getDataElement());
        assertEquals(avB.getValue(), dv.getOrgUnit());
    }
}
Also used : IdSchemes(org.hisp.dhis.common.IdSchemes) DataExportParams(org.hisp.dhis.datavalue.DataExportParams) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 13 with IdSchemes

use of org.hisp.dhis.common.IdSchemes in project dhis2-core by dhis2.

the class DataValueSetServiceTest method testImportDataValuesXmlUpdatesOnly.

@Test
public void testImportDataValuesXmlUpdatesOnly() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetB.xml").getInputStream();
    ImportOptions importOptions = new ImportOptions().setImportStrategy(ImportStrategy.UPDATES);
    IdSchemes idSchemes = new IdSchemes();
    idSchemes.setIdScheme("UID");
    idSchemes.setDataElementIdScheme("UID");
    idSchemes.setOrgUnitIdScheme("UID");
    importOptions.setIdSchemes(idSchemes);
    ImportSummary summary = dataValueSetService.saveDataValueSet(in, importOptions);
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    assertEquals(0, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(12, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(0, dataValues.size());
}
Also used : IdSchemes(org.hisp.dhis.common.IdSchemes) 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)

Aggregations

IdSchemes (org.hisp.dhis.common.IdSchemes)13 DhisSpringTest (org.hisp.dhis.DhisSpringTest)5 Test (org.junit.Test)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 DataExportParams (org.hisp.dhis.datavalue.DataExportParams)3 DateUtils.getMediumDateString (org.hisp.dhis.system.util.DateUtils.getMediumDateString)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 DataValue (org.hisp.dhis.datavalue.DataValue)2 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)2 ProgramType (org.hisp.dhis.program.ProgramType)2 SqlRowSet (org.springframework.jdbc.support.rowset.SqlRowSet)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 List (java.util.List)1