Search in sources :

Example 11 with TrackerImportReport

use of org.hisp.dhis.tracker.report.TrackerImportReport 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))));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) User(org.hisp.dhis.user.User) Test(org.junit.jupiter.api.Test)

Example 12 with TrackerImportReport

use of org.hisp.dhis.tracker.report.TrackerImportReport 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))));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) User(org.hisp.dhis.user.User) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Test(org.junit.jupiter.api.Test)

Example 13 with TrackerImportReport

use of org.hisp.dhis.tracker.report.TrackerImportReport 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());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 14 with TrackerImportReport

use of org.hisp.dhis.tracker.report.TrackerImportReport 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());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) InputStream(java.io.InputStream) TrackerWarningReport(org.hisp.dhis.tracker.report.TrackerWarningReport) ClassPathResource(org.springframework.core.io.ClassPathResource) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 15 with TrackerImportReport

use of org.hisp.dhis.tracker.report.TrackerImportReport 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"));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

TrackerImportReport (org.hisp.dhis.tracker.report.TrackerImportReport)114 TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)105 Test (org.junit.jupiter.api.Test)99 User (org.hisp.dhis.user.User)23 TrackerTest (org.hisp.dhis.tracker.TrackerTest)21 ClassPathResource (org.springframework.core.io.ClassPathResource)20 InputStream (java.io.InputStream)17 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)15 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)9 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)8 ProgramInstance (org.hisp.dhis.program.ProgramInstance)5 Date (java.util.Date)4 List (java.util.List)4 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 Program (org.hisp.dhis.program.Program)4 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)3 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)3 TrackerValidationReport (org.hisp.dhis.tracker.report.TrackerValidationReport)3 TrackerImportReportRequest (org.hisp.dhis.webapi.controller.tracker.TrackerImportReportRequest)3 ResponseEntity (org.springframework.http.ResponseEntity)3