Search in sources :

Example 16 with DELETED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.

the class TrackedEntityInstanceServiceTest method testAddAlreadyDeletedTeiInBulk.

@Test
void testAddAlreadyDeletedTeiInBulk() {
    ImportOptions importOptions = new ImportOptions();
    trackedEntityInstanceService.addTrackedEntityInstance(teiMaleA, importOptions);
    trackedEntityInstanceService.deleteTrackedEntityInstance(teiMaleA.getTrackedEntityInstance());
    manager.flush();
    importOptions.setImportStrategy(ImportStrategy.CREATE);
    teiMaleA.setDeleted(true);
    teiMaleB.setTrackedEntityInstance("teiUid00002");
    teiFemaleA.setTrackedEntityInstance("teiUid00003");
    List<TrackedEntityInstance> teis = new ArrayList<>();
    teis.add(teiMaleA);
    teis.add(teiMaleB);
    teis.add(teiFemaleA);
    ImportSummaries importSummaries = trackedEntityInstanceService.addTrackedEntityInstances(teis, importOptions);
    assertEquals(ImportStatus.ERROR, importSummaries.getStatus());
    assertEquals(1, importSummaries.getIgnored());
    assertEquals(2, importSummaries.getImported());
    assertTrue(importSummaries.getImportSummaries().stream().anyMatch(is -> is.getDescription().contains("already exists or was deleted earlier")));
    manager.flush();
    List<String> uids = new ArrayList<>();
    uids.add(teiMaleA.getTrackedEntityInstance());
    uids.add(teiMaleB.getTrackedEntityInstance());
    uids.add(teiFemaleA.getTrackedEntityInstance());
    List<String> fetchedUids = teiDaoService.getTrackedEntityInstancesUidsIncludingDeleted(uids);
    assertTrue(Sets.difference(new HashSet<>(uids), new HashSet<>(fetchedUids)).isEmpty());
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) Arrays(java.util.Arrays) Date(java.util.Date) TrackedEntityAttributeValueService(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) TextPattern(org.hisp.dhis.textpattern.TextPattern) Autowired(org.springframework.beans.factory.annotation.Autowired) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) Disabled(org.junit.jupiter.api.Disabled) StringUtils(org.apache.commons.lang3.StringUtils) Collections.singletonList(java.util.Collections.singletonList) TrackedEntityAttributeService(org.hisp.dhis.trackedentity.TrackedEntityAttributeService) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) EnrollmentStatus(org.hisp.dhis.dxf2.events.enrollment.EnrollmentStatus) Locale(java.util.Locale) SessionFactory(org.hibernate.SessionFactory) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) EventStatus(org.hisp.dhis.event.EventStatus) Collectors(java.util.stream.Collectors) Attribute(org.hisp.dhis.dxf2.events.trackedentity.Attribute) TrackedEntityTypeAttribute(org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute) Event(org.hisp.dhis.dxf2.events.event.Event) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) TextPatternMethod(org.hisp.dhis.textpattern.TextPatternMethod) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ProgramType(org.hisp.dhis.program.ProgramType) ProgramInstanceService(org.hisp.dhis.program.ProgramInstanceService) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) TrackedEntityTypeService(org.hisp.dhis.trackedentity.TrackedEntityTypeService) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) LocalDateTime(java.time.LocalDateTime) Program(org.hisp.dhis.program.Program) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) Objects(org.hisp.dhis.common.Objects) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceService(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService) DateTime(org.joda.time.DateTime) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ProgramStage(org.hisp.dhis.program.ProgramStage) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DateTimeFormatter(java.time.format.DateTimeFormatter) CodeGenerator(org.hisp.dhis.common.CodeGenerator) TextPatternSegment(org.hisp.dhis.textpattern.TextPatternSegment) ArrayList(java.util.ArrayList) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 17 with DELETED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.

the class DataValueSetServiceIntegrationTest method testImportReverseDeletedValuesXml.

/**
 * Import 12 data values where 4 are marked as deleted. Then import 12 data
 * values which reverse deletion of the 4 values and update the other 8
 * values.
 */
@Test
void testImportReverseDeletedValuesXml() {
    assertDataValuesCount(0);
    in = readFile("datavalueset/dataValueSetBDeleted.xml");
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
    assertEquals(12, summary.getImportCount().getImported());
    assertDataValuesCount(8);
    // Reverse deletion and update
    in = readFile("datavalueset/dataValueSetB.xml");
    summary = dataValueSetService.importDataValueSetXml(in);
    assertSuccessWithImportedUpdatedDeleted(4, 8, 0, summary);
    assertDataValuesCount(12);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) DhisTest(org.hisp.dhis.DhisTest) Test(org.junit.jupiter.api.Test)

Example 18 with DELETED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.

the class DataValueSetServiceIntegrationTest method testDeleteValuesXml.

/**
 * Import 12 data values. Then import 12 values where 4 are marked as
 * deleted.
 */
@Test
void testDeleteValuesXml() {
    assertDataValuesCount(0);
    in = readFile("datavalueset/dataValueSetB.xml");
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
    assertEquals(12, summary.getImportCount().getImported());
    assertDataValuesCount(12);
    // Delete 4 values
    in = readFile("datavalueset/dataValueSetBDeleted.xml");
    summary = dataValueSetService.importDataValueSetXml(in);
    assertSuccessWithImportedUpdatedDeleted(0, 8, 4, summary);
    assertDataValuesCount(8);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) DhisTest(org.hisp.dhis.DhisTest) Test(org.junit.jupiter.api.Test)

Example 19 with DELETED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED 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
void testImportDeletedValuesXml() {
    assertDataValuesCount(0);
    in = readFile("datavalueset/dataValueSetBDeleted.xml");
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
    assertSuccessWithImportedUpdatedDeleted(12, 0, 0, summary);
    assertDataValuesCount(8);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) DhisTest(org.hisp.dhis.DhisTest) Test(org.junit.jupiter.api.Test)

Example 20 with DELETED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.

the class ProgramStageInstanceSupplierTest method verifySupplier.

@Test
void verifySupplier() throws SQLException {
    // mock resultset data
    when(mockResultSet.getLong("programstageinstanceid")).thenReturn(100L);
    when(mockResultSet.getString("uid")).thenReturn("abcded");
    when(mockResultSet.getString("status")).thenReturn("ACTIVE");
    when(mockResultSet.getBoolean("deleted")).thenReturn(false);
    // create event to import
    Event event = new Event();
    event.setUid(CodeGenerator.generateUid());
    event.setEnrollment("abcded");
    // mock resultset extraction
    mockResultSetExtractor(mockResultSet);
    Map<String, ProgramStageInstance> map = subject.get(ImportOptions.getDefaultImportOptions(), Collections.singletonList(event));
    ProgramStageInstance programStageInstance = map.get("abcded");
    assertThat(programStageInstance, is(notNullValue()));
    assertThat(programStageInstance.getId(), is(100L));
    assertThat(programStageInstance.getUid(), is("abcded"));
    assertThat(programStageInstance.getStatus(), is(EventStatus.ACTIVE));
    assertThat(programStageInstance.isDeleted(), is(false));
}
Also used : Event(org.hisp.dhis.dxf2.events.event.Event) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Test(org.junit.jupiter.api.Test)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)26 Test (org.junit.jupiter.api.Test)12 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)7 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)7 DataElement (org.hisp.dhis.dataelement.DataElement)6 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)6 IOException (java.io.IOException)5 DhisTest (org.hisp.dhis.DhisTest)5 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)5 Program (org.hisp.dhis.program.Program)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 IdScheme (org.hisp.dhis.common.IdScheme)4 ImportCount (org.hisp.dhis.dxf2.importsummary.ImportCount)4 ProgramStage (org.hisp.dhis.program.ProgramStage)4 Lists (com.google.common.collect.Lists)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 List (java.util.List)3