Search in sources :

Example 1 with TrackerImportReportRequest

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

the class TrackerImportStrategyHandlerTest method shouldNotImportAsync.

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

Example 2 with TrackerImportReportRequest

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

the class TrackerImportStrategyHandlerImplTest method shouldSendMessageToQueueAsync.

@Test
void shouldSendMessageToQueueAsync() {
    ArgumentCaptor<String> queueNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<TrackerMessage> trackerMessageCaptor = ArgumentCaptor.forClass(TrackerMessage.class);
    doNothing().when(messageManager).sendQueue(queueNameCaptor.capture(), trackerMessageCaptor.capture());
    TrackerImportReportRequest trackerImportReportRequest = TrackerImportReportRequest.builder().trackerImportParams(TrackerImportParams.builder().jobConfiguration(new JobConfiguration("", JobType.TRACKER_IMPORT_JOB, "userId", true)).build()).build();
    importAsyncStrategy.importReport(trackerImportReportRequest);
    verify(trackerImportService, times(0)).importTracker(any());
    verify(messageManager).sendQueue(any(), any());
    assertEquals(Topics.TRACKER_IMPORT_JOB_TOPIC_NAME, queueNameCaptor.getValue());
    assertEquals(trackerImportReportRequest.getTrackerImportParams(), trackerMessageCaptor.getValue().getTrackerImportParams());
}
Also used : TrackerImportReportRequest(org.hisp.dhis.webapi.controller.tracker.TrackerImportReportRequest) TrackerMessage(org.hisp.dhis.tracker.job.TrackerMessage) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

Example 3 with TrackerImportReportRequest

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

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

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

the class TrackerImportController method asyncPostJsonTracker.

@PostMapping(value = "", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage asyncPostJsonTracker(HttpServletRequest request, HttpServletResponse response, @CurrentUser User currentUser, @RequestBody TrackerBundleParams trackerBundleParams) {
    String jobId = CodeGenerator.generateUid();
    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) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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