use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.
the class OwnershipTest method testDeleteEnrollment.
@Test
void testDeleteEnrollment() throws IOException {
TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid());
List<ProgramInstance> pis = manager.getAll(ProgramInstance.class);
assertEquals(2, pis.size());
ProgramInstance pi = pis.stream().filter(e -> e.getUid().equals("TvctPPhpD8u")).findAny().get();
enrollmentParams.setImportStrategy(TrackerImportStrategy.DELETE);
TrackerImportReport updatedReport = trackerImportService.importTracker(enrollmentParams);
assertNoImportErrors(updatedReport);
assertEquals(1, updatedReport.getStats().getDeleted());
pis = manager.getAll(ProgramInstance.class);
assertEquals(1, pis.size());
}
use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.
the class OwnershipTest method testDeleteEnrollmentWithoutOwnership.
@Test
void testDeleteEnrollmentWithoutOwnership() throws IOException {
// Change ownership
TrackedEntityInstance tei = manager.get(TrackedEntityInstance.class, "IOR1AXXl24H");
OrganisationUnit ou = manager.get(OrganisationUnit.class, "B1nCbRV3qtP");
Program pgm = manager.get(Program.class, "BFcipDERJnf");
TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid());
trackerOwnershipManager.transferOwnership(tei, pgm, ou, true, false);
enrollmentParams.setImportStrategy(TrackerImportStrategy.DELETE);
TrackerImportReport updatedReport = trackerImportService.importTracker(enrollmentParams);
assertEquals(1, updatedReport.getStats().getIgnored());
assertEquals(TrackerErrorCode.E1102, updatedReport.getValidationReport().getErrors().get(0).getErrorCode());
}
use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.
the class ReportSummaryDeleteIntegrationTest method testTrackedEntityInstanceDeletion.
@Test
void testTrackedEntityInstanceDeletion() throws IOException {
TrackerImportParams params = fromJson("tracker/tracked_entity_basic_data_for_deletion.json");
params.setImportStrategy(TrackerImportStrategy.DELETE);
assertEquals(9, params.getTrackedEntities().size());
TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
assertDeletedObjects(trackerImportReport.getBundleReport(), 9, TrackerType.TRACKED_ENTITY);
// remaining
assertEquals(4, manager.getAll(TrackedEntityInstance.class).size());
assertEquals(2, manager.getAll(ProgramInstance.class).size());
}
use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.
the class TrackerImportController method syncPostJsonTracker.
@PostMapping(value = "", consumes = APPLICATION_JSON_VALUE, params = { "async=false" })
public ResponseEntity<TrackerImportReport> syncPostJsonTracker(@RequestParam(defaultValue = "errors", required = false) String reportMode, @CurrentUser User currentUser, @RequestBody TrackerBundleParams trackerBundleParams) {
TrackerImportReportRequest trackerImportReportRequest = TrackerImportReportRequest.builder().trackerBundleParams(trackerBundleParams).contextService(contextService).userUid(currentUser.getUid()).trackerBundleReportMode(TrackerBundleReportMode.getTrackerBundleReportMode(reportMode)).uid(CodeGenerator.generateUid()).build();
TrackerImportReport trackerImportReport = trackerImportStrategy.importReport(trackerImportReportRequest);
ResponseEntity.BodyBuilder builder = trackerImportReport.getStatus() == TrackerStatus.ERROR ? ResponseEntity.status(HttpStatus.CONFLICT) : ResponseEntity.ok();
return builder.body(trackerImportReport);
}
use of org.hisp.dhis.tracker.report.TrackerImportReport 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