Search in sources :

Example 11 with TrackerImportParams

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))));
}
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 TrackerImportParams

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))));
}
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 TrackerImportParams

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

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

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

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