Search in sources :

Example 96 with ImportSummary

use of org.hisp.dhis.dxf2.importsummary.ImportSummary in project dhis2-core by dhis2.

the class DataValueSetServiceIntegrationTest method testImportAndDeleteValuesXml.

/**
     * Import 12 data values. Then import 12 values where 4 are marked as
     * deleted, 6 are updates and 2 are new.
     */
@Test
public void testImportAndDeleteValuesXml() throws Exception {
    assertEquals(0, dataValueService.getAllDataValues().size());
    in = new ClassPathResource("datavalueset/dataValueSetB.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(12, summary.getImportCount().getImported());
    assertEquals(12, dataValueService.getAllDataValues().size());
    // Delete 4 values, add 2 values
    in = new ClassPathResource("datavalueset/dataValueSetBNewDeleted.xml").getInputStream();
    summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(2, summary.getImportCount().getImported());
    assertEquals(6, summary.getImportCount().getUpdated());
    assertEquals(4, summary.getImportCount().getDeleted());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(10, dataValueService.getAllDataValues().size());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) DhisTest(org.hisp.dhis.DhisTest)

Example 97 with ImportSummary

use of org.hisp.dhis.dxf2.importsummary.ImportSummary in project dhis2-core by dhis2.

the class DataValueSetServiceTest method testImportDataValuesWithDataSetAllowsPeriods.

@Test
public void testImportDataValuesWithDataSetAllowsPeriods() throws Exception {
    Date thisMonth = DateUtils.truncate(new Date(), Calendar.MONTH);
    dsA.setExpiryDays(62);
    dsA.setOpenFuturePeriods(2);
    dataSetService.updateDataSet(dsA);
    Period tooEarly = createMonthlyPeriod(DateUtils.addMonths(thisMonth, 4));
    Period okBefore = createMonthlyPeriod(DateUtils.addMonths(thisMonth, 1));
    Period okAfter = createMonthlyPeriod(DateUtils.addMonths(thisMonth, -1));
    Period tooLate = createMonthlyPeriod(DateUtils.addMonths(thisMonth, -4));
    Period outOfRange = createMonthlyPeriod(DateUtils.addMonths(thisMonth, 6));
    periodService.addPeriod(tooEarly);
    periodService.addPeriod(okBefore);
    periodService.addPeriod(okAfter);
    periodService.addPeriod(tooLate);
    String importData = "<dataValueSet xmlns=\"http://dhis2.org/schema/dxf/2.0\" idScheme=\"code\" dataSet=\"DS_A\" orgUnit=\"OU_A\">\n" + "  <dataValue dataElement=\"DE_A\" period=\"" + tooEarly.getIsoDate() + "\" value=\"10001\" />\n" + "  <dataValue dataElement=\"DE_B\" period=\"" + okBefore.getIsoDate() + "\" value=\"10002\" />\n" + "  <dataValue dataElement=\"DE_C\" period=\"" + okAfter.getIsoDate() + "\" value=\"10003\" />\n" + "  <dataValue dataElement=\"DE_D\" period=\"" + tooLate.getIsoDate() + "\" value=\"10004\" />\n" + "  <dataValue dataElement=\"DE_D\" period=\"" + outOfRange.getIsoDate() + "\" value=\"10005\" />\n" + "</dataValueSet>\n";
    in = new ByteArrayInputStream(importData.getBytes(StandardCharsets.UTF_8));
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(summary.getConflicts().toString(), 3, summary.getConflicts().size());
    assertEquals(2, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(3, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.WARNING, summary.getStatus());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(2, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deB, okBefore, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deC, okAfter, ouA, ocDef, ocDef)));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Period(org.hisp.dhis.period.Period) Date(java.util.Date) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 98 with ImportSummary

use of org.hisp.dhis.dxf2.importsummary.ImportSummary in project dhis2-core by dhis2.

the class DataValueSetServiceTest method testImportDataValuesWithRequiredAttributeOptionCombo.

@Test
public void testImportDataValuesWithRequiredAttributeOptionCombo() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetNonStrict.xml").getInputStream();
    ImportOptions options = new ImportOptions().setRequireAttributeOptionCombo(true);
    ImportSummary summary = dataValueSetService.saveDataValueSet(in, options);
    assertEquals(summary.getConflicts().toString(), 2, summary.getConflicts().size());
    assertEquals(1, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(2, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.WARNING, summary.getStatus());
}
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 99 with ImportSummary

use of org.hisp.dhis.dxf2.importsummary.ImportSummary in project dhis2-core by dhis2.

the class DataValueSetServiceTest method testImportNullDataValues.

@Test
public void testImportNullDataValues() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetANull.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(ImportStatus.WARNING, summary.getStatus());
    assertEquals(2, summary.getImportCount().getIgnored());
    assertEquals(1, summary.getImportCount().getImported());
    assertEquals(summary.getConflicts().toString(), 2, summary.getConflicts().size());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(1, dataValues.size());
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 100 with ImportSummary

use of org.hisp.dhis.dxf2.importsummary.ImportSummary in project dhis2-core by dhis2.

the class DataValueSetServiceTest method testImportDataValuesXmlWithAttribute.

@Test
public void testImportDataValuesXmlWithAttribute() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetBAttribute.xml").getInputStream();
    ImportOptions importOptions = new ImportOptions().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)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)102 Test (org.junit.Test)58 DhisSpringTest (org.hisp.dhis.DhisSpringTest)49 ClassPathResource (org.springframework.core.io.ClassPathResource)39 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)25 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)22 DataValue (org.hisp.dhis.datavalue.DataValue)18 Event (org.hisp.dhis.dxf2.events.event.Event)17 InputStream (java.io.InputStream)14 Date (java.util.Date)11 ImportConflict (org.hisp.dhis.dxf2.importsummary.ImportConflict)11 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)11 IOException (java.io.IOException)10 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)10 DhisTest (org.hisp.dhis.DhisTest)9 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)7 DataElement (org.hisp.dhis.dataelement.DataElement)7 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)7 ApiVersion (org.hisp.dhis.webapi.mvc.annotation.ApiVersion)7