Example usage for org.springframework.batch.core BatchStatus isUnsuccessful

List of usage examples for org.springframework.batch.core BatchStatus isUnsuccessful

Introduction

In this page you can find the example usage for org.springframework.batch.core BatchStatus isUnsuccessful.

Prototype

public boolean isUnsuccessful() 

Source Link

Document

Convenience method to decide if a status indicates execution was unsuccessful.

Usage

From source file:de.codecentric.batch.web.JobOperationsController.java

private JobParameters createJobParametersWithIncrementerIfAvailable(String parameters, Job job)
        throws JobParametersNotFoundException {
    JobParameters jobParameters = jobParametersConverter
            .getJobParameters(PropertiesConverter.stringToProperties(parameters));
    // use JobParametersIncrementer to create JobParameters if incrementer is set and only if the job is no restart
    if (job.getJobParametersIncrementer() != null) {
        JobExecution lastJobExecution = jobRepository.getLastJobExecution(job.getName(), jobParameters);
        boolean restart = false;
        // check if job failed before
        if (lastJobExecution != null) {
            BatchStatus status = lastJobExecution.getStatus();
            if (status.isUnsuccessful() && status != BatchStatus.ABANDONED) {
                restart = true;/*from  ww  w.  j a  v  a 2  s  . c  o  m*/
            }
        }
        // if it's not a restart, create new JobParameters with the incrementer
        if (!restart) {
            JobParameters nextParameters = getNextJobParameters(job);
            Map<String, JobParameter> map = new HashMap<String, JobParameter>(nextParameters.getParameters());
            map.putAll(jobParameters.getParameters());
            jobParameters = new JobParameters(map);
        }
    }
    return jobParameters;
}

From source file:com.xchanging.support.batch.admin.service.SimpleJobService.java

public JobExecution launch(String jobName, JobParameters jobParameters)
        throws NoSuchJobException, JobExecutionAlreadyRunningException, JobRestartException,
        JobInstanceAlreadyCompleteException, JobParametersInvalidException {

    Job job = jobLocator.getJob(jobName);

    JobExecution lastJobExecution = jobRepository.getLastJobExecution(jobName, jobParameters);
    boolean restart = false;
    if (lastJobExecution != null) {
        BatchStatus status = lastJobExecution.getStatus();
        if (status.isUnsuccessful() && status != BatchStatus.ABANDONED) {
            restart = true;//  w w  w.  j  a v  a 2s.  co  m
        }
    }

    if (job.getJobParametersIncrementer() != null && !restart) {
        jobParameters = job.getJobParametersIncrementer().getNext(jobParameters);
    }

    JobExecution jobExecution = jobLauncher.run(job, jobParameters);

    if (jobExecution.isRunning()) {
        activeExecutions.add(jobExecution);
    }
    return jobExecution;

}

From source file:admin.service.SimpleJobService.java

@Override
public JobExecution launch(String jobName, JobParameters jobParameters)
        throws NoSuchJobException, JobExecutionAlreadyRunningException, JobRestartException,
        JobInstanceAlreadyCompleteException, JobParametersInvalidException {

    Job job = jobLocator.getJob(jobName);

    JobExecution lastJobExecution = jobRepository.getLastJobExecution(jobName, jobParameters);
    boolean restart = false;
    if (lastJobExecution != null) {
        BatchStatus status = lastJobExecution.getStatus();
        if (status.isUnsuccessful() && status != BatchStatus.ABANDONED) {
            restart = true;/*from   ww  w.  j  ava 2 s.  c o  m*/
        }
    }

    if (job.getJobParametersIncrementer() != null && !restart) {
        jobParameters = job.getJobParametersIncrementer().getNext(jobParameters);
    }

    JobExecution jobExecution = jobLauncher.run(job, jobParameters);

    if (jobExecution.isRunning()) {
        activeExecutions.add(jobExecution);
    }
    return jobExecution;

}

From source file:org.trpr.platform.batch.impl.spring.admin.SimpleJobService.java

/**
 * Interface method implementation/*from w ww  .j a  va 2 s .com*/
 * @see org.springframework.batch.admin.service.JobService#launch(java.lang.String, org.springframework.batch.core.JobParameters)
 */
public JobExecution launch(String jobName, JobParameters jobParameters)
        throws NoSuchJobException, JobExecutionAlreadyRunningException, JobRestartException,
        JobInstanceAlreadyCompleteException, JobParametersInvalidException {

    Job job = this.jobRegistry.getJob(jobName);
    JobExecution lastJobExecution = this.jobRepository.getLastJobExecution(jobName, jobParameters);
    boolean restart = false;
    if (lastJobExecution != null) {
        BatchStatus status = lastJobExecution.getStatus();
        if (status.isUnsuccessful() && status != BatchStatus.ABANDONED) {
            restart = true;
        }
    }
    if (job.getJobParametersIncrementer() != null && !restart) {
        jobParameters = job.getJobParametersIncrementer().getNext(jobParameters);
    }
    JobExecution jobExecution = this.jobLauncher.run(job, jobParameters);
    if (jobExecution.isRunning()) {
        this.activeExecutions.add(jobExecution);
    }
    return jobExecution;
}

From source file:org.springframework.cloud.dataflow.server.batch.SimpleJobService.java

@Override
public JobExecution launch(String jobName, JobParameters jobParameters)
        throws NoSuchJobException, JobExecutionAlreadyRunningException, JobRestartException,
        JobInstanceAlreadyCompleteException, JobParametersInvalidException {

    JobExecution jobExecution = null;/*from  w w  w  . j  a  v a2s  .c om*/

    if (jobLocator.getJobNames().contains(jobName)) {
        Job job = jobLocator.getJob(jobName);

        JobExecution lastJobExecution = jobRepository.getLastJobExecution(jobName, jobParameters);
        boolean restart = false;
        if (lastJobExecution != null) {
            BatchStatus status = lastJobExecution.getStatus();
            if (status.isUnsuccessful() && status != BatchStatus.ABANDONED) {
                restart = true;
            }
        }

        if (job.getJobParametersIncrementer() != null && !restart) {
            jobParameters = job.getJobParametersIncrementer().getNext(jobParameters);
        }

        jobExecution = jobLauncher.run(job, jobParameters);

        if (jobExecution.isRunning()) {
            activeExecutions.add(jobExecution);
        }
    } else {
        if (jsrJobOperator != null) {
            jobExecution = new JobExecution(jsrJobOperator.start(jobName, jobParameters.toProperties()));
        } else {
            throw new NoSuchJobException(
                    String.format("Unable to find job %s to launch", String.valueOf(jobName)));
        }
    }

    return jobExecution;
}