use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class EventSecurityImportValidationTest method testNoWriteAccessToProgramStage.
@Test
void testNoWriteAccessToProgramStage() throws IOException {
setupMetadata();
TrackerImportParams trackerBundleParams = createBundleFromJson("tracker/validations/events_error-no-programStage-access.json");
User user = userService.getUser(USER_3);
trackerBundleParams.setUser(user);
user.addOrganisationUnit(organisationUnitA);
manager.update(user);
TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerBundleParams);
assertEquals(2, trackerImportReport.getValidationReport().getErrors().size());
assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1095))));
assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1096))));
}
use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class EventSecurityImportValidationTest method testNoUncompleteEventAuth.
@Test
void testNoUncompleteEventAuth() throws IOException {
setupMetadata();
TrackerImportParams params = createBundleFromJson("tracker/validations/events_error-no-uncomplete.json");
params.setImportStrategy(TrackerImportStrategy.CREATE);
TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
// Change just inserted Event to status COMPLETED...
ProgramStageInstance zwwuwNp6gVd = programStageServiceInstance.getProgramStageInstance("ZwwuwNp6gVd");
zwwuwNp6gVd.setStatus(EventStatus.COMPLETED);
manager.update(zwwuwNp6gVd);
TrackerImportParams trackerBundleParams = createBundleFromJson("tracker/validations/events_error-no-uncomplete.json");
programA.setPublicAccess(AccessStringHelper.FULL);
manager.update(programA);
programStageA.setPublicAccess(AccessStringHelper.FULL);
manager.update(programStageA);
maleA.setPublicAccess(AccessStringHelper.FULL);
manager.update(maleA);
User user = userService.getUser(USER_4);
user.addOrganisationUnit(organisationUnitA);
manager.update(user);
manager.flush();
manager.clear();
trackerBundleParams.setUserId(user.getUid());
trackerBundleParams.setImportStrategy(TrackerImportStrategy.UPDATE);
trackerImportReport = trackerImportService.importTracker(trackerBundleParams);
assertEquals(1, trackerImportReport.getValidationReport().getErrors().size());
assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1083))));
}
use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class ProgramRuleIntegrationTest method testImportProgramEventSuccessWithWarningRaised.
@Test
void testImportProgramEventSuccessWithWarningRaised() throws IOException {
InputStream inputStream = new ClassPathResource("tracker/program_event.json").getInputStream();
TrackerImportParams params = renderService.fromJson(inputStream, TrackerImportParams.class);
params.setUserId(userA.getUid());
TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
assertNotNull(trackerImportReport);
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
assertEquals(1, trackerImportReport.getValidationReport().getWarnings().size());
}
use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class ProgramRuleIntegrationTest method testImportEventInProgramStageSuccessWithWarningRaised.
@Test
void testImportEventInProgramStageSuccessWithWarningRaised() throws IOException {
InputStream inputStream = new ClassPathResource("tracker/tei_enrollment_event.json").getInputStream();
TrackerImportParams params = renderService.fromJson(inputStream, TrackerImportParams.class);
params.setUserId(userA.getUid());
TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
assertNotNull(trackerImportReport);
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
List<TrackerWarningReport> warningReports = trackerImportReport.getValidationReport().getWarnings();
assertEquals(4, warningReports.size());
assertEquals(3, warningReports.stream().filter(w -> w.getTrackerType().equals(TrackerType.EVENT)).count());
assertEquals(1, warningReports.stream().filter(w -> w.getTrackerType().equals(TrackerType.ENROLLMENT)).count());
inputStream = new ClassPathResource("tracker/event_update_no_datavalue.json").getInputStream();
params = renderService.fromJson(inputStream, TrackerImportParams.class);
params.setUserId(userA.getUid());
params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
trackerImportReport = trackerImportService.importTracker(params);
assertNotNull(trackerImportReport);
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
warningReports = trackerImportReport.getValidationReport().getWarnings();
assertEquals(3, warningReports.size());
assertEquals(TrackerErrorCode.E1308, warningReports.get(0).getWarningCode());
assertEquals("Generated by program rule (`ProgramRule`) - DataElement `DATAEL00001` is being replaced in event `EVENT123456`", warningReports.get(0).getWarningMessage());
inputStream = new ClassPathResource("tracker/event_update_datavalue.json").getInputStream();
params = renderService.fromJson(inputStream, TrackerImportParams.class);
params.setUserId(userA.getUid());
params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
trackerImportReport = trackerImportService.importTracker(params);
assertNotNull(trackerImportReport);
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
warningReports = trackerImportReport.getValidationReport().getWarnings();
assertEquals(3, warningReports.size());
assertEquals(TrackerErrorCode.E1308, warningReports.get(0).getWarningCode());
assertEquals("Generated by program rule (`ProgramRule`) - DataElement `DATAEL00001` is being replaced in event `EVENT123456`", warningReports.get(0).getWarningMessage());
}
use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class AtomicModeIntegrationTest method testImportFailWithAtomicModeAllIfThereIsAnErrorInOneTEI.
@Test
void testImportFailWithAtomicModeAllIfThereIsAnErrorInOneTEI() throws IOException {
InputStream inputStream = new ClassPathResource("tracker/one_valid_tei_and_one_invalid.json").getInputStream();
TrackerImportParams params = renderService.fromJson(inputStream, TrackerImportParams.class);
params.setUserId(userA.getUid());
params.setAtomicMode(AtomicMode.ALL);
TrackerImportReport trackerImportTeiReport = trackerImportService.importTracker(params);
assertNotNull(trackerImportTeiReport);
assertEquals(TrackerStatus.ERROR, trackerImportTeiReport.getStatus());
assertEquals(1, trackerImportTeiReport.getValidationReport().getErrors().size());
assertNull(trackedEntityInstanceService.getTrackedEntityInstance("VALIDTEIAAA"));
assertNull(trackedEntityInstanceService.getTrackedEntityInstance("INVALIDTEIA"));
}
Aggregations