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");
}
}
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;
}
}
Aggregations