Search in sources :

Example 6 with TrackerImportReportRequest

use of org.hisp.dhis.webapi.controller.tracker.TrackerImportReportRequest 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)

Example 7 with TrackerImportReportRequest

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

the class TrackerImportStrategyHandlerTest method shouldImportAsync.

@Test
void shouldImportAsync() {
    TrackerImportReportRequest trackerImportReportRequest = TrackerImportReportRequest.builder().contextService(contextService).userUid("userUid").uid("uid").trackerBundleParams(TrackerBundleParams.builder().build()).isAsync(true).build();
    importStrategy.importReport(trackerImportReportRequest);
    verify(importAsyncStrategy).importReport(any());
    verify(importAsyncFalseStrategy, times(0)).importReport(any());
}
Also used : TrackerImportReportRequest(org.hisp.dhis.webapi.controller.tracker.TrackerImportReportRequest) Test(org.junit.jupiter.api.Test)

Example 8 with TrackerImportReportRequest

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

the class TrackerImportStrategyHandlerImplTest method shouldCreateReportAsyncFalse.

@Test
void shouldCreateReportAsyncFalse() {
    TrackerImportReportRequest trackerImportReportRequest = TrackerImportReportRequest.builder().trackerImportParams(TrackerImportParams.builder().jobConfiguration(new JobConfiguration("", JobType.TRACKER_IMPORT_JOB, "userId", false)).build()).trackerBundleReportMode(TrackerBundleReportMode.FULL).build();
    importAsyncFalseStrategy.importReport(trackerImportReportRequest);
    verify(trackerImportService).importTracker(trackerImportReportRequest.getTrackerImportParams());
    verify(trackerImportService).buildImportReport(any(), any());
}
Also used : TrackerImportReportRequest(org.hisp.dhis.webapi.controller.tracker.TrackerImportReportRequest) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

TrackerImportReportRequest (org.hisp.dhis.webapi.controller.tracker.TrackerImportReportRequest)8 Test (org.junit.jupiter.api.Test)4 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 InputStream (java.io.InputStream)2 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)2 Event (org.hisp.dhis.tracker.domain.Event)2 TrackerImportReport (org.hisp.dhis.tracker.report.TrackerImportReport)2 TrackerBundleParams (org.hisp.dhis.webapi.controller.tracker.TrackerBundleParams)2 ResponseEntity (org.springframework.http.ResponseEntity)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 TrackerMessage (org.hisp.dhis.tracker.job.TrackerMessage)1