Search in sources :

Example 1 with TrackerBundleParams

use of org.hisp.dhis.webapi.controller.tracker.TrackerBundleParams in project dhis2-core by dhis2.

the class TrackerImportController method asyncPostCsvTracker.

@PostMapping(value = "", consumes = { "application/csv", "text/csv" }, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage asyncPostCsvTracker(HttpServletRequest request, @CurrentUser User currentUser, @RequestParam(required = false, defaultValue = "true") boolean skipFirst) throws IOException, ParseException {
    String jobId = CodeGenerator.generateUid();
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    List<Event> events = csvEventService.readEvents(inputStream, skipFirst);
    TrackerBundleParams trackerBundleParams = new TrackerBundleParams();
    trackerBundleParams.setEvents(events);
    TrackerImportReportRequest trackerImportReportRequest = TrackerImportReportRequest.builder().trackerBundleParams(trackerBundleParams).contextService(contextService).userUid(currentUser.getUid()).isAsync(true).uid(jobId).authentication(SecurityContextHolder.getContext().getAuthentication()).build();
    trackerImportStrategy.importReport(trackerImportReportRequest);
    String location = ContextUtils.getRootPath(request) + "/tracker/jobs/" + jobId;
    return ok(TRACKER_JOB_ADDED).setLocation("/tracker/jobs/" + jobId).setResponse(TrackerJobWebMessageResponse.builder().id(jobId).location(location).build());
}
Also used : TrackerImportReportRequest(org.hisp.dhis.webapi.controller.tracker.TrackerImportReportRequest) TrackerBundleParams(org.hisp.dhis.webapi.controller.tracker.TrackerBundleParams) InputStream(java.io.InputStream) Event(org.hisp.dhis.tracker.domain.Event) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with TrackerBundleParams

use of org.hisp.dhis.webapi.controller.tracker.TrackerBundleParams in project dhis2-core by dhis2.

the class TrackerImportController method syncPostCsvTracker.

@PostMapping(value = "", consumes = { "application/csv", "text/csv" }, produces = APPLICATION_JSON_VALUE, params = { "async=false" })
public ResponseEntity<TrackerImportReport> syncPostCsvTracker(HttpServletRequest request, @RequestParam(required = false, defaultValue = "true") boolean skipFirst, @RequestParam(defaultValue = "errors", required = false) String reportMode, @CurrentUser User currentUser) throws IOException, ParseException {
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    List<Event> events = csvEventService.readEvents(inputStream, skipFirst);
    TrackerBundleParams trackerBundleParams = new TrackerBundleParams();
    trackerBundleParams.setEvents(events);
    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) TrackerBundleParams(org.hisp.dhis.webapi.controller.tracker.TrackerBundleParams) InputStream(java.io.InputStream) Event(org.hisp.dhis.tracker.domain.Event) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

InputStream (java.io.InputStream)2 Event (org.hisp.dhis.tracker.domain.Event)2 TrackerBundleParams (org.hisp.dhis.webapi.controller.tracker.TrackerBundleParams)2 TrackerImportReportRequest (org.hisp.dhis.webapi.controller.tracker.TrackerImportReportRequest)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 TrackerImportReport (org.hisp.dhis.tracker.report.TrackerImportReport)1 ResponseEntity (org.springframework.http.ResponseEntity)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1