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());
}
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());
}
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());
}
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"));
}
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);
}
Aggregations