Search in sources :

Example 46 with TrackerImportReport

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

the class ReportSummaryIntegrationTest method testStatsCountForOneUpdateEventAndOneNewEventAndOneInvalidEvent.

@Test
void testStatsCountForOneUpdateEventAndOneNewEventAndOneInvalidEvent() throws IOException {
    InputStream inputStream = new ClassPathResource("tracker/single_tei.json").getInputStream();
    TrackerImportParams params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    trackerImportService.importTracker(params);
    inputStream = new ClassPathResource("tracker/single_enrollment.json").getInputStream();
    params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    trackerImportService.importTracker(params);
    inputStream = new ClassPathResource("tracker/single_event.json").getInputStream();
    params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    trackerImportService.importTracker(params);
    inputStream = new ClassPathResource("tracker/one_update_and_one_new_and_one_invalid_event.json").getInputStream();
    params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    params.setAtomicMode(AtomicMode.OBJECT);
    params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
    TrackerImportReport trackerImportEventReport = trackerImportService.importTracker(params);
    assertNotNull(trackerImportEventReport);
    assertEquals(TrackerStatus.OK, trackerImportEventReport.getStatus());
    assertEquals(1, trackerImportEventReport.getValidationReport().getErrors().size());
    assertEquals(1, trackerImportEventReport.getStats().getCreated());
    assertEquals(1, trackerImportEventReport.getStats().getUpdated());
    assertEquals(1, trackerImportEventReport.getStats().getIgnored());
    assertEquals(0, trackerImportEventReport.getStats().getDeleted());
}
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 47 with TrackerImportReport

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

the class ReportSummaryIntegrationTest method testStatsCountForOneCreatedEnrollmentAndUpdateSameEnrollment.

@Test
void testStatsCountForOneCreatedEnrollmentAndUpdateSameEnrollment() throws IOException {
    InputStream inputStream = new ClassPathResource("tracker/single_tei.json").getInputStream();
    TrackerImportParams params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    trackerImportService.importTracker(params);
    inputStream = new ClassPathResource("tracker/single_enrollment.json").getInputStream();
    params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
    TrackerImportReport trackerImportEnrollmentReport = trackerImportService.importTracker(params);
    assertNotNull(trackerImportEnrollmentReport);
    assertEquals(TrackerStatus.OK, trackerImportEnrollmentReport.getStatus());
    assertTrue(trackerImportEnrollmentReport.getValidationReport().getErrors().isEmpty());
    assertEquals(1, trackerImportEnrollmentReport.getStats().getCreated());
    assertEquals(0, trackerImportEnrollmentReport.getStats().getUpdated());
    assertEquals(0, trackerImportEnrollmentReport.getStats().getIgnored());
    assertEquals(0, trackerImportEnrollmentReport.getStats().getDeleted());
    inputStream = new ClassPathResource("tracker/single_enrollment.json").getInputStream();
    params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
    trackerImportEnrollmentReport = trackerImportService.importTracker(params);
    assertNotNull(trackerImportEnrollmentReport);
    assertEquals(TrackerStatus.OK, trackerImportEnrollmentReport.getStatus());
    assertTrue(trackerImportEnrollmentReport.getValidationReport().getErrors().isEmpty());
    assertEquals(0, trackerImportEnrollmentReport.getStats().getCreated());
    assertEquals(1, trackerImportEnrollmentReport.getStats().getUpdated());
    assertEquals(0, trackerImportEnrollmentReport.getStats().getIgnored());
    assertEquals(0, trackerImportEnrollmentReport.getStats().getDeleted());
}
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 48 with TrackerImportReport

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

the class ReportSummaryIntegrationTest method testStatsCountForOneCreatedAndOneUpdatedTEI.

@Test
void testStatsCountForOneCreatedAndOneUpdatedTEI() throws IOException {
    InputStream inputStream = new ClassPathResource("tracker/single_tei.json").getInputStream();
    TrackerImportParams params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    trackerImportService.importTracker(params);
    inputStream = new ClassPathResource("tracker/one_update_tei_and_one_new_tei.json").getInputStream();
    params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
    TrackerImportReport trackerImportTeiReport = trackerImportService.importTracker(params);
    assertNotNull(trackerImportTeiReport);
    assertEquals(TrackerStatus.OK, trackerImportTeiReport.getStatus());
    assertTrue(trackerImportTeiReport.getValidationReport().getErrors().isEmpty());
    assertEquals(1, trackerImportTeiReport.getStats().getCreated());
    assertEquals(1, trackerImportTeiReport.getStats().getUpdated());
    assertEquals(0, trackerImportTeiReport.getStats().getIgnored());
    assertEquals(0, trackerImportTeiReport.getStats().getDeleted());
}
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 49 with TrackerImportReport

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

the class OwnershipTest method testClientDatesForTeiEnrollmentEvent.

@Test
void testClientDatesForTeiEnrollmentEvent() throws IOException {
    TrackerImportParams trackerImportParams = fromJson("tracker/ownership_event.json", nonSuperUser.getUid());
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerImportParams);
    manager.flush();
    TrackerImportParams teiParams = fromJson("tracker/ownership_tei.json", nonSuperUser.getUid());
    TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid());
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    List<TrackedEntityInstance> teis = manager.getAll(TrackedEntityInstance.class);
    assertEquals(1, teis.size());
    TrackedEntityInstance tei = teis.get(0);
    assertNotNull(tei.getCreatedAtClient());
    assertNotNull(tei.getLastUpdatedAtClient());
    assertEquals(DateUtils.fromInstant(teiParams.getTrackedEntities().get(0).getCreatedAtClient()), tei.getCreatedAtClient());
    assertEquals(DateUtils.fromInstant(teiParams.getTrackedEntities().get(0).getUpdatedAtClient()), tei.getLastUpdatedAtClient());
    Set<ProgramInstance> pis = tei.getProgramInstances();
    assertEquals(1, pis.size());
    ProgramInstance pi = pis.iterator().next();
    assertNotNull(pi.getCreatedAtClient());
    assertNotNull(pi.getLastUpdatedAtClient());
    assertEquals(DateUtils.fromInstant(enrollmentParams.getEnrollments().get(0).getCreatedAtClient()), pi.getCreatedAtClient());
    assertEquals(DateUtils.fromInstant(enrollmentParams.getEnrollments().get(0).getUpdatedAtClient()), pi.getLastUpdatedAtClient());
    Set<ProgramStageInstance> psis = pi.getProgramStageInstances();
    assertEquals(1, psis.size());
    ProgramStageInstance psi = psis.iterator().next();
    assertNotNull(psi.getCreatedAtClient());
    assertNotNull(psi.getLastUpdatedAtClient());
    assertEquals(DateUtils.fromInstant(trackerImportParams.getEvents().get(0).getCreatedAtClient()), psi.getCreatedAtClient());
    assertEquals(DateUtils.fromInstant(trackerImportParams.getEvents().get(0).getUpdatedAtClient()), psi.getLastUpdatedAtClient());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 50 with TrackerImportReport

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

the class OwnershipTest method testUpdateEnrollmentWithoutOwnership.

@Test
void testUpdateEnrollmentWithoutOwnership() throws IOException {
    // Change ownership
    TrackedEntityInstance tei = manager.get(TrackedEntityInstance.class, "IOR1AXXl24H");
    OrganisationUnit ou = manager.get(OrganisationUnit.class, "B1nCbRV3qtP");
    Program pgm = manager.get(Program.class, "BFcipDERJnf");
    trackerOwnershipManager.transferOwnership(tei, pgm, ou, true, false);
    TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid());
    enrollmentParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
    TrackerImportReport updatedReport = trackerImportService.importTracker(enrollmentParams);
    assertEquals(1, updatedReport.getStats().getIgnored());
    assertEquals(TrackerErrorCode.E1102, updatedReport.getValidationReport().getErrors().get(0).getErrorCode());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Program(org.hisp.dhis.program.Program) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

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