use of javax.batch.operations.NoSuchJobException in project quickstart by wildfly.
the class BatchController method getJobsExecution.
public Set<JobData> getJobsExecution() {
Set<JobData> jobsData = new TreeSet<JobData>(new Comparator<JobData>() {
@Override
public int compare(JobData o1, JobData o2) {
return o2.getJobInstanceId().compareTo(o1.getJobInstanceId());
}
});
Map<Long, JobExecution> jobIntances = new HashMap<>();
JobOperator jobOperator = BatchRuntime.getJobOperator();
try {
List<JobInstance> instances = jobOperator.getJobInstances("import-file", 0, jobOperator.getJobInstanceCount("import-file"));
for (JobInstance ji : instances) {
List<JobExecution> executions = jobOperator.getJobExecutions(ji);
for (JobExecution jobExecution : executions) {
// initialize the map if null
if (jobIntances.get(ji.getInstanceId()) == null) {
jobIntances.put(ji.getInstanceId(), jobExecution);
}
// Update the jobExecution if is newer
JobExecution existing = jobIntances.get(ji.getInstanceId());
if (jobExecution.getExecutionId() > existing.getExecutionId()) {
jobIntances.put(ji.getInstanceId(), jobExecution);
}
}
}
for (Long instaceId : jobIntances.keySet()) {
JobExecution jobExecution = jobIntances.get(instaceId);
JobInstance ji = jobOperator.getJobInstance(jobExecution.getExecutionId());
Properties parameters = jobOperator.getParameters(jobExecution.getExecutionId());
jobsData.add(new JobData(ji.getInstanceId(), jobExecution.getExecutionId(), ji.getJobName(), jobExecution.getCreateTime(), jobExecution.getEndTime(), jobExecution.getBatchStatus(), parameters, jobExecution.getExitStatus()));
}
} catch (NoSuchJobException e) {
// It's ok if when doesn't have any jobs yet to show
}
return jobsData;
}
Aggregations