Search in sources :

Example 1 with TrackerTimingsStats

use of org.hisp.dhis.tracker.report.TrackerTimingsStats 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 2 with TrackerTimingsStats

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

the class DefaultTrackerImportService method importTracker.

@Override
public TrackerImportReport importTracker(TrackerImportParams params) {
    User user = trackerUserService.getUser(params.getUserId());
    params.setUser(user);
    TrackerTimingsStats opsTimer = new TrackerTimingsStats();
    startImport(params);
    TrackerValidationReport validationReport = new TrackerValidationReport();
    TrackerBundleReport bundleReport;
    try {
        TrackerBundle trackerBundle = preHeat(params, opsTimer);
        Map<TrackerType, Integer> bundleSize = calculatePayloadSize(trackerBundle);
        preProcess(opsTimer, trackerBundle);
        if (addToValidationReport(params, opsTimer, validationReport, trackerBundle)) {
            return buildReportAndNotify(params, validationReport, opsTimer, bundleSize);
        }
        bundleReport = commit(params, opsTimer, trackerBundle);
        postCommit(trackerBundle);
        TrackerImportReport trackerImportReport = TrackerImportReport.withImportCompleted(TrackerStatus.OK, bundleReport, validationReport, opsTimer.stopTimer(), bundleSize);
        endImport(params, trackerImportReport);
        return trackerImportReport;
    } catch (Exception e) {
        log.error("Exception thrown during import.", e);
        TrackerImportReport report = TrackerImportReport.withError("Exception:" + e.getMessage(), validationReport, opsTimer.stopTimer());
        endImportWithError(params, report, e);
        return report;
    }
}
Also used : TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) User(org.hisp.dhis.user.User) TrackerTimingsStats(org.hisp.dhis.tracker.report.TrackerTimingsStats) TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerBundleReport(org.hisp.dhis.tracker.report.TrackerBundleReport)

Aggregations

TrackerImportReport (org.hisp.dhis.tracker.report.TrackerImportReport)2 TrackerTimingsStats (org.hisp.dhis.tracker.report.TrackerTimingsStats)2 TrackerValidationReport (org.hisp.dhis.tracker.report.TrackerValidationReport)2 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)1 TrackerBundleReport (org.hisp.dhis.tracker.report.TrackerBundleReport)1 User (org.hisp.dhis.user.User)1 NotFoundException (org.hisp.dhis.webapi.controller.exception.NotFoundException)1 Test (org.junit.jupiter.api.Test)1