}
@SuppressWarnings("unchecked")
@Override
protected void doExecute(StepExecution stepExecution) throws Exception {
ExecutionContext executionContext = stepExecution.getJobExecution().getExecutionContext();
List<javax.batch.runtime.StepExecution> stepExecutions = new ArrayList<javax.batch.runtime.StepExecution>();
if(executionContext.containsKey("batch.lastSteps")) {
List<String> stepNames = (List<String>) executionContext.get("batch.lastSteps");
for (String stepName : stepNames) {
StepExecution curStepExecution = getJobRepository().getLastStepExecution(stepExecution.getJobExecution().getJobInstance(), stepName);
stepExecutions.add(new JsrStepExecution(curStepExecution));
}
} else {
Collection<StepExecution> currentRunStepExecutions = stepExecution.getJobExecution().getStepExecutions();
StepExecution lastExecution = null;
if(stepExecutions != null) {
for (StepExecution curStepExecution : currentRunStepExecutions) {
if(lastExecution == null || (curStepExecution.getEndTime() != null && curStepExecution.getEndTime().after(lastExecution.getEndTime()))) {
lastExecution = curStepExecution;
}
}
stepExecutions.add(new JsrStepExecution(lastExecution));
}
}
try {
ExitStatus exitStatus = new ExitStatus(decider.decide(stepExecutions.toArray(new javax.batch.runtime.StepExecution[0])));
stepExecution.getJobExecution().setExitStatus(exitStatus);
stepExecution.setExitStatus(exitStatus);
if(executionContext.containsKey("batch.lastSteps")) {
executionContext.remove("batch.lastSteps");
}
} catch (Exception e) {
stepExecution.setTerminateOnly();
stepExecution.addFailureException(e);
throw e;