BATCH-1507: double check the step names

This commit is contained in:
dsyer
2010-02-08 10:43:22 +00:00
parent 87c839d7f0
commit 69ed590c74
2 changed files with 28 additions and 6 deletions

View File

@@ -69,13 +69,19 @@ public class FlowJob extends AbstractJob {
public Step getStep(String stepName) {
State state = this.flow.getState(stepName);
if (state instanceof StepHolder) {
return ((StepHolder) state).getStep();
Step step = ((StepHolder) state).getStep();
if (stepName.equals(step.getName())) {
return step;
}
}
// The state names can be prefixed with the job name for
// uniqueness...
state = this.flow.getState(getName()+"."+stepName);
state = this.flow.getState(getName() + "." + stepName);
if (state instanceof StepHolder) {
return ((StepHolder) state).getStep();
Step step = ((StepHolder) state).getStep();
if (stepName.equals(step.getName())) {
return step;
}
}
return null;
}
@@ -88,7 +94,8 @@ public class FlowJob extends AbstractJob {
Collection<String> steps = new HashSet<String>();
for (State state : flow.getStates()) {
if (state instanceof StepHolder) {
steps.add(state.getName());
String name = ((StepHolder) state).getStep().getName();
steps.add(name);
}
}
return steps;
@@ -100,8 +107,8 @@ public class FlowJob extends AbstractJob {
@Override
protected void doExecute(final JobExecution execution) throws JobExecutionException {
try {
JobFlowExecutor executor = new JobFlowExecutor(getJobRepository(), new SimpleStepHandler(getJobRepository()),
execution);
JobFlowExecutor executor = new JobFlowExecutor(getJobRepository(),
new SimpleStepHandler(getJobRepository()), execution);
executor.updateJobExecutionStatus(flow.start(executor).getStatus());
}
catch (FlowExecutionException e) {

View File

@@ -535,6 +535,21 @@ public class FlowJobTests {
assertEquals("step", step.getName());
}
@Test
public void testGetStepNamesWithPrefix() throws Exception {
SimpleFlow flow = new SimpleFlow("job");
List<StateTransition> transitions = new ArrayList<StateTransition>();
transitions.add(StateTransition.createStateTransition(new StepState("job.step", new StubStep("step")), "end0"));
transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end0")));
flow.setStateTransitions(transitions);
flow.afterPropertiesSet();
job.setFlow(flow);
job.setName(flow.getName());
job.afterPropertiesSet();
assertEquals("[step]", job.getStepNames().toString());
}
@Test
public void testGetStepNotExists() throws Exception {
SimpleFlow flow = new SimpleFlow("job");