Search in sources :

Example 61 with TrackerImportReport

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

the class OwnershipTest method testCreateEnrollmentWithoutOwnership.

@Test
void testCreateEnrollmentWithoutOwnership() throws IOException {
    TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid());
    List<ProgramInstance> pis = manager.getAll(ProgramInstance.class);
    assertEquals(2, pis.size());
    enrollmentParams.setImportStrategy(TrackerImportStrategy.DELETE);
    TrackerImportReport updatedReport = trackerImportService.importTracker(enrollmentParams);
    assertNoImportErrors(updatedReport);
    assertEquals(1, updatedReport.getStats().getDeleted());
    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);
    enrollmentParams.setImportStrategy(TrackerImportStrategy.CREATE);
    enrollmentParams.getEnrollments().get(0).setEnrollment(CodeGenerator.generateUid());
    updatedReport = trackerImportService.importTracker(enrollmentParams);
    assertEquals(1, updatedReport.getStats().getIgnored());
    assertEquals(TrackerErrorCode.E1102, updatedReport.getValidationReport().getErrors().get(0).getErrorCode());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 62 with TrackerImportReport

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

the class ReportSummaryDeleteIntegrationTest method testEnrollmentDeletion.

@Test
void testEnrollmentDeletion() throws IOException {
    assertEquals(4, manager.getAll(ProgramInstance.class).size());
    assertEquals(2, manager.getAll(ProgramStageInstance.class).size());
    TrackerImportParams params = fromJson("tracker/enrollment_basic_data_for_deletion.json");
    params.setImportStrategy(TrackerImportStrategy.DELETE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    assertDeletedObjects(trackerImportReport.getBundleReport(), 1, TrackerType.ENROLLMENT);
    // remaining
    assertEquals(3, manager.getAll(ProgramInstance.class).size());
    // delete associated events as well
    assertEquals(1, manager.getAll(ProgramStageInstance.class).size());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 63 with TrackerImportReport

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

the class ReportSummaryDeleteIntegrationTest method testDeleteMultipleEntities.

@Test
void testDeleteMultipleEntities() throws IOException {
    TrackerImportParams params = fromJson("tracker/tracker_data_for_deletion.json");
    params.setImportStrategy(TrackerImportStrategy.DELETE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    assertDeletedObjects(trackerImportReport.getBundleReport(), 1, TrackerType.ENROLLMENT);
    assertDeletedObjects(trackerImportReport.getBundleReport(), 1, TrackerType.TRACKED_ENTITY);
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 64 with TrackerImportReport

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

Example 65 with TrackerImportReport

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