Example usage for org.springframework.batch.core.step StepLocator getStep

List of usage examples for org.springframework.batch.core.step StepLocator getStep

Introduction

In this page you can find the example usage for org.springframework.batch.core.step StepLocator getStep.

Prototype

@Nullable
    Step getStep(String stepName);

Source Link

Usage

From source file:org.springframework.batch.core.configuration.support.DefaultJobLoader.java

/**
 * Returns all the {@link Step} instances defined by the specified {@link StepLocator}.
 * <br>/*  www  .j  a v a2 s.c  o  m*/
 * The specified <tt>jobApplicationContext</tt> is used to collect additional steps that
 * are not exposed by the step locator
 *
 * @param stepLocator the given step locator
 * @param jobApplicationContext the application context of the job
 * @return all the {@link Step} defined by the given step locator and context
 * @see StepLocator
 */
private Collection<Step> getSteps(final StepLocator stepLocator,
        final ApplicationContext jobApplicationContext) {
    final Collection<String> stepNames = stepLocator.getStepNames();
    final Collection<Step> result = new ArrayList<Step>();
    for (String stepName : stepNames) {
        result.add(stepLocator.getStep(stepName));
    }

    // Because some steps are referenced by name, we need to look in the context to see if there
    // are more Step instances defined. Right now they are registered as being available in the
    // context of the job but we have no idea if they are linked to that Job or not.
    final Map<String, Step> allSteps = jobApplicationContext.getBeansOfType(Step.class);
    for (Map.Entry<String, Step> entry : allSteps.entrySet()) {
        if (!stepNames.contains(entry.getKey())) {
            result.add(entry.getValue());
        }
    }
    return result;
}

From source file:org.springframework.batch.test.JobLauncherTestUtils.java

/**
 * Launch just the specified step in the job. An IllegalStateException is
 * thrown if there is no Step with the given name.
 * /*from   ww w .  j  a  va2  s . c o  m*/
 * @param stepName The name of the step to launch
 * @param jobParameters The JobParameters to use during the launch
 * @param jobExecutionContext An ExecutionContext whose values will be
 * loaded into the Job ExecutionContext prior to launching the step.
 * @return JobExecution
 */
public JobExecution launchStep(String stepName, JobParameters jobParameters,
        ExecutionContext jobExecutionContext) {
    if (!(job instanceof StepLocator)) {
        throw new UnsupportedOperationException("Cannot locate step from a Job that is not a StepLocator: job="
                + job.getName() + " does not implement StepLocator");
    }
    StepLocator locator = (StepLocator) this.job;
    Step step = locator.getStep(stepName);
    if (step == null) {
        step = locator.getStep(this.job.getName() + "." + stepName);
    }
    if (step == null) {
        throw new IllegalStateException("No Step found with name: [" + stepName + "]");
    }
    return getStepRunner().launchStep(step, jobParameters, jobExecutionContext);
}