Search in sources :

Example 16 with TrackerImportReport

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

the class DefaultTrackerImportService method buildReportAndNotify.

private TrackerImportReport buildReportAndNotify(TrackerImportParams params, TrackerValidationReport validationReport, TrackerTimingsStats opsTimer, Map<TrackerType, Integer> bundleSize) {
    TrackerImportReport trackerImportReport = TrackerImportReport.withValidationErrors(validationReport, opsTimer.stopTimer(), bundleSize.values().stream().mapToInt(Integer::intValue).sum());
    endImport(params, trackerImportReport);
    return trackerImportReport;
}
Also used : TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport)

Example 17 with TrackerImportReport

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

the class DefaultTrackerImportService method buildImportReport.

/**
 * Clone the TrackerImportReport and filters out validation data based on
 * the provided {@link TrackerBundleReport}.
 *
 * @return a copy of the current TrackerImportReport
 */
@Override
public TrackerImportReport buildImportReport(TrackerImportReport originalImportReport, TrackerBundleReportMode reportMode) {
    TrackerImportReport.TrackerImportReportBuilder importReportBuilder = TrackerImportReport.builder().status(originalImportReport.getStatus()).stats(originalImportReport.getStats()).bundleReport(originalImportReport.getBundleReport()).message(originalImportReport.getMessage());
    TrackerValidationReport originalValidationReport = originalImportReport.getValidationReport();
    TrackerValidationReport validationReport = new TrackerValidationReport();
    if (originalValidationReport != null) {
        validationReport.addErrors(originalValidationReport.getErrors());
    }
    if (originalValidationReport != null && TrackerBundleReportMode.WARNINGS == reportMode) {
        validationReport.addWarnings(originalValidationReport.getWarnings());
    } else if (originalValidationReport != null && TrackerBundleReportMode.FULL == reportMode) {
        validationReport.addWarnings(originalValidationReport.getWarnings()).addTimings(originalValidationReport.getTimings());
        importReportBuilder.timingsStats(originalImportReport.getTimingsStats());
    }
    importReportBuilder.validationReport(validationReport);
    return importReportBuilder.build();
}
Also used : TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport)

Example 18 with TrackerImportReport

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

the class TrackerImportControllerTest method verifyShouldFindJobReport.

@Test
void verifyShouldFindJobReport() throws Exception {
    String uid = CodeGenerator.generateUid();
    TrackerImportReport trackerImportReport = TrackerImportReport.withImportCompleted(TrackerStatus.OK, TrackerBundleReport.builder().status(TrackerStatus.OK).build(), new TrackerValidationReport(), new TrackerTimingsStats(), new HashMap<>());
    // When
    when(notifier.getJobSummaryByJobId(JobType.TRACKER_IMPORT_JOB, uid)).thenReturn(trackerImportReport);
    when(trackerImportService.buildImportReport(any(), any())).thenReturn(trackerImportReport);
    // Then
    String contentAsString = mockMvc.perform(get(ENDPOINT + "/jobs/" + uid + "/report").content("{}").contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(jsonPath("$.message").doesNotExist()).andExpect(content().contentType("application/json")).andReturn().getResponse().getContentAsString();
    verify(notifier).getJobSummaryByJobId(JobType.TRACKER_IMPORT_JOB, uid);
    verify(trackerImportService).buildImportReport(any(), any());
    try {
        renderService.fromJson(contentAsString, TrackerImportReport.class);
    } catch (Exception e) {
        fail("response content : " + contentAsString + "\n" + " is not of TrackerImportReport type");
    }
}
Also used : TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport) TrackerTimingsStats(org.hisp.dhis.tracker.report.TrackerTimingsStats) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 19 with TrackerImportReport

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

the class EnrollmentImportValidationTest method testNoWriteAccessToOrg.

@Test
void testNoWriteAccessToOrg() throws IOException {
    TrackerImportParams params = createBundleFromJson("tracker/validations/enrollments_te_enrollments-data.json");
    User user = userService.getUser(USER_2);
    params.setUser(user);
    params.setImportStrategy(TrackerImportStrategy.CREATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertEquals(4, trackerImportReport.getValidationReport().getErrors().size());
    assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1000))));
}
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 20 with TrackerImportReport

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

the class EnrollmentImportValidationTest method testEnrollmentDeleteOk.

@Test
void testEnrollmentDeleteOk() throws IOException {
    TrackerImportParams paramsCreate = createBundleFromJson("tracker/validations/enrollments_te_enrollments-data.json");
    paramsCreate.setImportStrategy(TrackerImportStrategy.CREATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(paramsCreate);
    assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    manager.flush();
    manager.clear();
    TrackerImportParams paramsDelete = createBundleFromJson("tracker/validations/enrollments_te_enrollments-data-delete.json");
    paramsDelete.setImportStrategy(TrackerImportStrategy.DELETE);
    TrackerImportReport trackerImportReportDelete = trackerImportService.importTracker(paramsDelete);
    assertEquals(0, trackerImportReportDelete.getValidationReport().getErrors().size());
    assertEquals(TrackerStatus.OK, trackerImportReportDelete.getStatus());
    assertEquals(1, trackerImportReportDelete.getStats().getDeleted());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) 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