@Override
public long restart(final long executionId, final Properties restartParameters) throws JobExecutionAlreadyCompleteException,
NoSuchJobExecutionException, JobExecutionNotMostRecentException, JobRestartException, JobSecurityException {
long newExecutionId = 0;
final JobExecutionImpl originalToRestart = (JobExecutionImpl) getJobExecution(executionId);
if (originalToRestart == null) {
throw MESSAGES.noSuchJobExecution(executionId);
}
final BatchStatus previousStatus = originalToRestart.getBatchStatus();
if (previousStatus == BatchStatus.COMPLETED) {
throw MESSAGES.jobExecutionAlreadyCompleteException(executionId);
}
if (previousStatus == BatchStatus.ABANDONED ||
previousStatus == BatchStatus.STARTED ||
previousStatus == BatchStatus.STARTING ||
previousStatus == BatchStatus.STOPPING) {
throw MESSAGES.jobRestartException(executionId, previousStatus);
}
if (previousStatus == BatchStatus.FAILED || previousStatus == BatchStatus.STOPPED) {
final JobInstanceImpl jobInstance = (JobInstanceImpl) getJobInstance(executionId);
final List<JobExecution> executions = getJobExecutions(jobInstance);
final JobExecution mostRecentExecution = executions.get(executions.size() - 1);
if (executionId != mostRecentExecution.getExecutionId()) {
throw MESSAGES.jobExecutionNotMostRecentException(executionId, jobInstance.getInstanceId());
}
// the job may not have been loaded, e.g., when the restart is performed in a new JVM
final String jobName = originalToRestart.getJobName();
if (repository.getJob(jobName) == null) {
final Job jobDefined = ArchiveXmlLoader.loadJobXml(jobName, Job.class, batchEnvironment.getClassLoader());
repository.addJob(jobDefined);
}
if (jobInstance.getUnsubstitutedJob() == null) {