Search in sources :

Example 91 with TrackerImportParams

use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.

the class ReportSummaryDeleteIntegrationTest method testNonExistentEnrollment.

@Test
void testNonExistentEnrollment() throws IOException {
    TrackerImportParams params = fromJson("tracker/non_existent_enrollment_basic_data_for_deletion.json");
    params.setImportStrategy(TrackerImportStrategy.DELETE);
    TrackerImportReport importReport = trackerImportService.importTracker(params);
    assertEquals(TrackerStatus.ERROR, importReport.getStatus());
    assertTrue(importReport.getValidationReport().hasErrors());
    List<TrackerErrorReport> trackerErrorReports = importReport.getValidationReport().getErrors();
    assertEquals(TrackerErrorCode.E1081, trackerErrorReports.get(0).getErrorCode());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 92 with TrackerImportParams

use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.

the class ReportSummaryDeleteIntegrationTest method testEventDeletion.

@Test
void testEventDeletion() throws IOException {
    TrackerImportParams params = fromJson("tracker/event_basic_data_for_deletion.json");
    params.setImportStrategy(TrackerImportStrategy.DELETE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    assertDeletedObjects(trackerImportReport.getBundleReport(), 1, TrackerType.EVENT);
    // remaining
    assertEquals(1, manager.getAll(ProgramStageInstance.class).size());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 93 with TrackerImportParams

use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.

the class ReportSummaryDeleteIntegrationTest method initTest.

@Override
protected void initTest() throws IOException {
    setUpMetadata("tracker/tracker_basic_metadata.json");
    TrackerImportParams params = fromJson("tracker/tracker_basic_data_before_deletion.json");
    assertEquals(13, params.getTrackedEntities().size());
    assertEquals(2, params.getEnrollments().size());
    assertEquals(2, params.getEvents().size());
    TrackerBundleReport bundleReport = trackerImportService.importTracker(params).getBundleReport();
    assertEquals(bundleReport.getTypeReportMap().get(TrackerType.EVENT).getStats().getCreated(), manager.getAll(ProgramStageInstance.class).size());
    assertEquals(bundleReport.getTypeReportMap().get(TrackerType.EVENT).getStats().getCreated(), bundleReport.getTypeReportMap().get(TrackerType.EVENT).getObjectReportMap().size());
    assertEquals(bundleReport.getTypeReportMap().get(TrackerType.TRACKED_ENTITY).getStats().getCreated(), bundleReport.getTypeReportMap().get(TrackerType.TRACKED_ENTITY).getObjectReportMap().size());
    assertEquals(4, manager.getAll(ProgramInstance.class).size());
    assertEquals(2, bundleReport.getTypeReportMap().get(TrackerType.ENROLLMENT).getObjectReportMap().size());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerBundleReport(org.hisp.dhis.tracker.report.TrackerBundleReport)

Example 94 with TrackerImportParams

use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.

the class TrackerImportParamsSerdeTest method testJsonDeserialization.

@Test
void testJsonDeserialization() throws IOException {
    final String json = "" + "{\"importMode\":\"COMMIT\"," + "\"identifiers\":{\"dataElementIdScheme\":{\"idScheme\":\"UID\"}," + "\"orgUnitIdScheme\":{\"idScheme\":\"UID\"}," + "\"programIdScheme\":{\"idScheme\":\"ATTRIBUTE\",\"value\":\"aaaa\"}," + "\"programStageIdScheme\":{\"idScheme\":\"UID\"}," + "\"idScheme\":{\"idScheme\":\"CODE\"}," + "\"categoryOptionComboIdScheme\":{\"idScheme\":\"UID\"}," + "\"categoryOptionIdScheme\":{\"idScheme\":\"UID\"}}," + "\"importStrategy\":\"DELETE\"," + "\"atomicMode\":\"OBJECT\"," + "\"flushMode\":\"OBJECT\"," + "\"validationMode\":\"SKIP\"," + "\"skipPatternValidation\":true," + "\"skipSideEffects\":true," + "\"skipRuleEngine\":true," + "\"trackedEntities\":[]," + "\"enrollments\":[]," + "\"events\":[]," + "\"relationships\":[]," + "\"username\":\"system-process\"}";
    final TrackerImportParams trackerImportParams = renderService.fromJson(json, TrackerImportParams.class);
    assertThat(trackerImportParams.getImportMode(), is(TrackerBundleMode.COMMIT));
    assertThat(trackerImportParams.getImportStrategy(), is(TrackerImportStrategy.DELETE));
    assertThat(trackerImportParams.getAtomicMode(), is(AtomicMode.OBJECT));
    assertThat(trackerImportParams.getFlushMode(), is(FlushMode.OBJECT));
    assertThat(trackerImportParams.getValidationMode(), is(ValidationMode.SKIP));
    assertThat(trackerImportParams.isSkipPatternValidation(), is(true));
    assertThat(trackerImportParams.isSkipSideEffects(), is(true));
    assertThat(trackerImportParams.isSkipRuleEngine(), is(true));
    assertThat(trackerImportParams.getUser(), is(nullValue()));
    TrackerIdentifierParams identifiers = trackerImportParams.getIdentifiers();
    assertThat(identifiers.getIdScheme(), is(TrackerIdentifier.CODE));
    assertThat(identifiers.getProgramIdScheme().getIdScheme(), is(TrackerIdScheme.ATTRIBUTE));
    assertThat(identifiers.getProgramIdScheme().getValue(), is("aaaa"));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerIdentifierParams(org.hisp.dhis.tracker.TrackerIdentifierParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 95 with TrackerImportParams

use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.

the class TrackerImportParamsSerdeTest method testJsonSerialization.

@Test
void testJsonSerialization() throws JSONException {
    TrackerIdentifierParams identifierParams = TrackerIdentifierParams.builder().idScheme(TrackerIdentifier.CODE).programIdScheme(TrackerIdentifier.builder().idScheme(TrackerIdScheme.ATTRIBUTE).value("aaaa").build()).build();
    TrackerImportParams trackerImportParams = TrackerImportParams.builder().identifiers(identifierParams).atomicMode(AtomicMode.OBJECT).flushMode(FlushMode.OBJECT).skipRuleEngine(true).importStrategy(TrackerImportStrategy.DELETE).validationMode(ValidationMode.SKIP).build();
    String json = renderService.toJsonAsString(trackerImportParams);
    JSONAssert.assertEquals(json, "" + "{\"importMode\":\"COMMIT\"," + "\"identifiers\":{\"dataElementIdScheme\":{\"idScheme\":\"UID\"}," + "\"orgUnitIdScheme\":{\"idScheme\":\"UID\"}," + "\"programIdScheme\":{\"idScheme\":\"ATTRIBUTE\",\"value\":\"aaaa\"}," + "\"programStageIdScheme\":{\"idScheme\":\"UID\"}," + "\"idScheme\":{\"idScheme\":\"CODE\"}," + "\"categoryOptionComboIdScheme\":{\"idScheme\":\"UID\"}," + "\"categoryOptionIdScheme\":{\"idScheme\":\"UID\"}}," + "\"importStrategy\":\"DELETE\"," + "\"atomicMode\":\"OBJECT\"," + "\"flushMode\":\"OBJECT\"," + "\"validationMode\":\"SKIP\"," + "\"skipPatternValidation\":false," + "\"skipSideEffects\":false," + "\"skipRuleEngine\":true," + "\"trackedEntities\":[]," + "\"enrollments\":[]," + "\"events\":[]," + "\"relationships\":[]," + "\"username\":\"system-process\"}", JSONCompareMode.LENIENT);
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerIdentifierParams(org.hisp.dhis.tracker.TrackerIdentifierParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Aggregations

TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)163 Test (org.junit.jupiter.api.Test)142 TrackerImportReport (org.hisp.dhis.tracker.report.TrackerImportReport)105 TrackerTest (org.hisp.dhis.tracker.TrackerTest)46 User (org.hisp.dhis.user.User)26 ClassPathResource (org.springframework.core.io.ClassPathResource)23 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)21 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)17 InputStream (java.io.InputStream)16 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)11 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 List (java.util.List)9 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)9 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)8 Event (org.hisp.dhis.tracker.domain.Event)7 Pair (org.apache.commons.lang3.tuple.Pair)6 ProgramInstance (org.hisp.dhis.program.ProgramInstance)6 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)5 Program (org.hisp.dhis.program.Program)5