Search in sources :

Example 51 with TrackerImportReport

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());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 52 with TrackerImportReport

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());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Program(org.hisp.dhis.program.Program) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 53 with TrackerImportReport

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());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 54 with TrackerImportReport

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);
}
Also used : TrackerImportReportRequest(org.hisp.dhis.webapi.controller.tracker.TrackerImportReportRequest) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) ResponseEntity(org.springframework.http.ResponseEntity) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 55 with 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;
    }
}
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)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