Search in sources :

Example 71 with TrackerImportReport

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

the class ReportSummaryIntegrationTest method testStatsCountForOneUpdateEventAndOneNewEvent.

@Test
void testStatsCountForOneUpdateEventAndOneNewEvent() 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_event_and_one_new_event.json").getInputStream();
    params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
    TrackerImportReport trackerImportEventReport = trackerImportService.importTracker(params);
    assertNotNull(trackerImportEventReport);
    assertEquals(TrackerStatus.OK, trackerImportEventReport.getStatus());
    assertTrue(trackerImportEventReport.getValidationReport().getErrors().isEmpty());
    assertEquals(1, trackerImportEventReport.getStats().getCreated());
    assertEquals(1, trackerImportEventReport.getStats().getUpdated());
    assertEquals(0, 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 72 with TrackerImportReport

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

the class ReportSummaryIntegrationTest method testStatsCountForOneCreatedAndOneUpdatedTEIAndOneInvalidTEI.

@Test
void testStatsCountForOneCreatedAndOneUpdatedTEIAndOneInvalidTEI() 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_and_one_invalid_tei.json").getInputStream();
    params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    params.setAtomicMode(AtomicMode.OBJECT);
    params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
    TrackerImportReport trackerImportTeiReport = trackerImportService.importTracker(params);
    assertNotNull(trackerImportTeiReport);
    assertEquals(TrackerStatus.OK, trackerImportTeiReport.getStatus());
    assertEquals(1, trackerImportTeiReport.getValidationReport().getErrors().size());
    assertEquals(1, trackerImportTeiReport.getStats().getCreated());
    assertEquals(1, trackerImportTeiReport.getStats().getUpdated());
    assertEquals(1, 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 73 with TrackerImportReport

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

the class ReportSummaryIntegrationTest method testStatsCountForOneUpdateEnrollmentAndOneCreatedEnrollmentAndOneInvalidEnrollment.

@Test
void testStatsCountForOneUpdateEnrollmentAndOneCreatedEnrollmentAndOneInvalidEnrollment() throws IOException {
    InputStream inputStream = new ClassPathResource("tracker/one_update_tei_and_one_new_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/one_update_and_one_new_and_one_invalid_enrollment.json").getInputStream();
    params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    params.setAtomicMode(AtomicMode.OBJECT);
    params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
    TrackerImportReport trackerImportEnrollmentReport = trackerImportService.importTracker(params);
    assertNotNull(trackerImportEnrollmentReport);
    assertEquals(TrackerStatus.OK, trackerImportEnrollmentReport.getStatus());
    assertEquals(1, trackerImportEnrollmentReport.getValidationReport().getErrors().size());
    assertEquals(1, trackerImportEnrollmentReport.getStats().getCreated());
    assertEquals(1, trackerImportEnrollmentReport.getStats().getUpdated());
    assertEquals(1, 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 74 with TrackerImportReport

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

the class TrackedEntityAttributeValueAuditTest method testTrackedEntityAttributeValueAuditCreate.

@Test
void testTrackedEntityAttributeValueAuditCreate() throws IOException {
    TrackerImportParams trackerImportParams = fromJson("tracker/te_program_with_tea_data.json");
    trackerImportParams.setUser(currentUserService.getCurrentUser());
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerImportParams);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    List<TrackedEntityInstance> trackedEntityInstances = manager.getAll(TrackedEntityInstance.class);
    assertEquals(1, trackedEntityInstances.size());
    TrackedEntityInstance trackedEntityInstance = trackedEntityInstances.get(0);
    List<TrackedEntityAttributeValue> attributeValues = trackedEntityAttributeValueService.getTrackedEntityAttributeValues(trackedEntityInstance);
    assertEquals(4, attributeValues.size());
    List<TrackedEntityAttribute> attributes = attributeValues.stream().map(TrackedEntityAttributeValue::getAttribute).collect(Collectors.toList());
    List<TrackedEntityAttributeValueAudit> attributeValueAudits = attributeValueAuditService.getTrackedEntityAttributeValueAudits(attributes, trackedEntityInstances, AuditType.CREATE);
    assertEquals(4, attributeValueAudits.size());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) TrackedEntityAttributeValueAudit(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAudit) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 75 with TrackerImportReport

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

the class TrackedEntityAttributeValueAuditTest method testTrackedEntityAttributeValueAuditDelete.

@Test
void testTrackedEntityAttributeValueAuditDelete() throws IOException {
    TrackerImportParams trackerImportParams = fromJson("tracker/te_program_with_tea_data.json");
    trackerImportParams.setUser(currentUserService.getCurrentUser());
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerImportParams);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    List<TrackedEntityAttributeValue> attributeValues1 = trackedEntityAttributeValueService.getTrackedEntityAttributeValues(manager.getAll(TrackedEntityInstance.class).get(0));
    List<TrackedEntityAttribute> attributes1 = attributeValues1.stream().map(TrackedEntityAttributeValue::getAttribute).collect(Collectors.toList());
    trackerImportParams = fromJson("tracker/te_program_with_tea_null_data.json");
    trackerImportParams.setUser(currentUserService.getCurrentUser());
    trackerImportParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
    trackerImportReport = trackerImportService.importTracker(trackerImportParams);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    List<TrackedEntityInstance> trackedEntityInstances = manager.getAll(TrackedEntityInstance.class);
    List<TrackedEntityAttributeValueAudit> attributeValueAudits = attributeValueAuditService.getTrackedEntityAttributeValueAudits(attributes1, trackedEntityInstances, AuditType.DELETE);
    assertEquals(1, attributeValueAudits.size());
    attributeValueAudits = attributeValueAuditService.getTrackedEntityAttributeValueAudits(attributes1, trackedEntityInstances, AuditType.UPDATE);
    assertEquals(1, attributeValueAudits.size());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) TrackedEntityAttributeValueAudit(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAudit) 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