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