Example usage for org.springframework.batch.core JobInstance getVersion

List of usage examples for org.springframework.batch.core JobInstance getVersion

Introduction

In this page you can find the example usage for org.springframework.batch.core JobInstance getVersion.

Prototype

public Integer getVersion() 

Source Link

Usage

From source file:org.springframework.xd.dirt.rest.BatchJobsController.java

/**
 * Return a paged collection of job instances for a given job.
 * //from   ww  w.ja  va2s .  c om
 * @param jobName name of the batch job
 * @param startJobInstance start index for the job instance
 * @param pageSize page size for the list
 * @return collection of JobInstnaces by job name
 */
@RequestMapping(value = "/{jobName}/instances", method = RequestMethod.GET)
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public Collection<JobInstance> instancesForJob(@PathVariable String jobName,
        @RequestParam(defaultValue = "0") int startJobInstance,
        @RequestParam(defaultValue = "20") int pageSize) {
    String fullName = jobName + ".job";

    try {
        Collection<JobInstance> jobInstances = jobService.listJobInstances(fullName, startJobInstance,
                pageSize);
        // need to pass simple name back to the client
        List<JobInstance> result = new ArrayList<JobInstance>();
        for (JobInstance jobInstance : jobInstances) {
            JobInstance simpleInstance = new JobInstance(jobInstance.getId(), jobName);
            simpleInstance.setVersion(jobInstance.getVersion());
            result.add(simpleInstance);
        }
        // TODO: Need to add the jobExecutions for each jobInstance
        return result;
    } catch (NoSuchJobException e) {
        throw new NoSuchBatchJobException(jobName);
    }
}