Search in sources :

Example 26 with ImportSummary

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

the class DataValueSetServiceIntegrationTest method testImportUpdateValuesXml.

/**
     * Import 12 data values. Then import 6 data values, where 4 are updates.
     */
@Test
public void testImportUpdateValuesXml() 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());
    // Update
    in = new ClassPathResource("datavalueset/dataValueSetBUpdate.xml").getInputStream();
    summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(2, summary.getImportCount().getImported());
    assertEquals(4, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(14, 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 27 with ImportSummary

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

the class DataValueSetServiceIntegrationTest method testImportDeletedValuesXml.

/**
     * Import 12 data values where 4 are marked as deleted. Deleted values should
     * count as imports when there are no existing non-deleted matching values.
     */
@Test
public void testImportDeletedValuesXml() throws Exception {
    assertEquals(0, dataValueService.getAllDataValues().size());
    in = new ClassPathResource("datavalueset/dataValueSetBDeleted.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(12, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(8, 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 28 with ImportSummary

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

the class RegistrationMultiEventsServiceTest method testSaveRepeatableStageWithoutEventIdShouldCreateNewEvent.

@Test
@Category(IntegrationTest.class)
public void testSaveRepeatableStageWithoutEventIdShouldCreateNewEvent() {
    Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
    ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA.getUid());
    importSummary = eventService.addEvent(event, null);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    event = createEvent(programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementB.getUid());
    importSummary = eventService.addEvent(event, null);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    sessionFactory.getCurrentSession().flush();
    EventSearchParams params = new EventSearchParams();
    params.setProgram(programA);
    params.setOrgUnit(organisationUnitA);
    params.setOrgUnitSelectionMode(OrganisationUnitSelectionMode.SELECTED);
    assertEquals(2, eventService.getEvents(params).getEvents().size());
    event = createEvent(programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementB.getUid());
    importSummary = eventService.addEvent(event, null);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(3, eventService.getEvents(params).getEvents().size());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) Category(org.junit.experimental.categories.Category) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 29 with ImportSummary

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

the class RegistrationMultiEventsServiceTest method testSaveRepeatableStageWithEventIdShouldNotCreateAdditionalEvents.

@Test
@Category(IntegrationTest.class)
public void testSaveRepeatableStageWithEventIdShouldNotCreateAdditionalEvents() {
    Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
    ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA.getUid());
    importSummary = eventService.addEvent(event, null);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    event = createEvent(programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementB.getUid());
    importSummary = eventService.addEvent(event, null);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    sessionFactory.getCurrentSession().flush();
    EventSearchParams params = new EventSearchParams();
    params.setProgram(programA);
    params.setOrgUnit(organisationUnitA);
    params.setOrgUnitSelectionMode(OrganisationUnitSelectionMode.SELECTED);
    assertEquals(2, eventService.getEvents(params).getEvents().size());
    event = createEvent(programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementB.getUid());
    event.setEvent(importSummary.getReference());
    importSummary = eventService.addEvent(event, null);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(2, eventService.getEvents(params).getEvents().size());
    event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA.getUid());
    importSummary = eventService.addEvent(event, null);
    assertEquals(ImportStatus.ERROR, importSummary.getStatus());
    assertEquals(2, eventService.getEvents(params).getEvents().size());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) Category(org.junit.experimental.categories.Category) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 30 with ImportSummary

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

the class RegistrationMultiEventsServiceTest method testSaveWithoutEnrollmentShouldFail.

@Test
@Category(IntegrationTest.class)
public void testSaveWithoutEnrollmentShouldFail() {
    Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA.getUid());
    ImportSummary importSummary = eventService.addEvent(event, null);
    assertEquals(ImportStatus.ERROR, importSummary.getStatus());
    assertThat(importSummary.getDescription(), CoreMatchers.containsString("is not enrolled in program"));
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) Category(org.junit.experimental.categories.Category) IntegrationTest(org.hisp.dhis.IntegrationTest) 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