|
| 1 | +package ca.uhn.fhir.jpa.starter.web; |
| 2 | + |
| 3 | +import ca.uhn.fhir.batch2.api.IJobCoordinator; |
| 4 | +import ca.uhn.fhir.batch2.api.JobOperationResultJson; |
| 5 | +import ca.uhn.fhir.batch2.model.JobInstance; |
| 6 | +import ca.uhn.fhir.batch2.model.StatusEnum; |
| 7 | +import ca.uhn.fhir.batch2.models.JobInstanceFetchRequest; |
| 8 | +import jakarta.validation.constraints.Min; |
| 9 | +import org.springframework.data.domain.Sort; |
| 10 | +import org.springframework.http.MediaType; |
| 11 | +import org.springframework.web.bind.annotation.*; |
| 12 | + |
| 13 | +import java.util.List; |
| 14 | + |
| 15 | +@RestController |
| 16 | +@RequestMapping("control") |
| 17 | +public class JobController { |
| 18 | + private final IJobCoordinator theJobCoordinator; |
| 19 | + |
| 20 | + public JobController(IJobCoordinator theJobCoordinator) { |
| 21 | + this.theJobCoordinator = theJobCoordinator; |
| 22 | + } |
| 23 | + |
| 24 | + @RequestMapping(value = JobController.JOBS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) |
| 25 | + public List<JobInstance> getAllJobs(@RequestParam(name = "pageStart") @Min(0) int pageStart, @RequestParam(name = "batchSize") int batchSize, @RequestParam(name = "jobStatus", required = false) StatusEnum jobStatus) { |
| 26 | + JobInstanceFetchRequest jobInstanceFetchRequest = new JobInstanceFetchRequest(); |
| 27 | + jobInstanceFetchRequest.setPageStart(pageStart); |
| 28 | + jobInstanceFetchRequest.setBatchSize(batchSize); |
| 29 | + jobInstanceFetchRequest.setJobStatus(jobStatus != null ? jobStatus.toString() : ""); |
| 30 | + jobInstanceFetchRequest.setSort(Sort.by(Sort.Direction.DESC, JobController.MY_CREATE_TIME)); |
| 31 | + |
| 32 | + return theJobCoordinator.fetchAllJobInstances(jobInstanceFetchRequest).getContent(); |
| 33 | + } |
| 34 | + |
| 35 | + @RequestMapping(value = JobController.JOBS, method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) |
| 36 | + public JobOperationResultJson cancelInstance(@RequestParam(name = "instanceId") String instanceId) { |
| 37 | + return theJobCoordinator.cancelInstance(instanceId); |
| 38 | + } |
| 39 | + |
| 40 | + public static final String JOBS = "jobs"; |
| 41 | + public static final String MY_CREATE_TIME = "myCreateTime"; |
| 42 | +} |
0 commit comments