RESOLVED - issue BATCH-570: Job.getSteps() does not need to be exposed in the interface

Added getStepNames() to StepLocator.
This commit is contained in:
dsyer
2009-03-03 19:12:14 +00:00
parent 6cfc1ccc72
commit 9a3e55e58e
9 changed files with 96 additions and 16 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.batch.core.job;
import java.util.Collection;
import java.util.Date;
import org.apache.commons.logging.Log;
@@ -136,6 +137,13 @@ public abstract class AbstractJob implements Job, StepLocator, BeanNameAware, In
*/
public abstract Step getStep(String stepName);
/**
* Retrieve the step names.
*
* @return the step names
*/
public abstract Collection<String> getStepNames();
/**
* Boolean flag to prevent categorically a job from restarting, even if it
* has failed previously.

View File

@@ -17,7 +17,7 @@
package org.springframework.batch.core.job;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Collection;
import java.util.List;
import org.springframework.batch.core.BatchStatus;
@@ -69,10 +69,14 @@ public class SimpleJob extends AbstractJob {
/**
* Convenience method for clients to inspect the steps for this job.
*
* @return an unmodifiable copy of the steps for this job
* @return the step names for this job
*/
public List<Step> getSteps() {
return Collections.unmodifiableList(steps);
public Collection<String> getStepNames() {
List<String> names = new ArrayList<String>();
for (Step step : steps) {
names.add(step.getName());
}
return names;
}
/**

View File

@@ -15,10 +15,11 @@
*/
package org.springframework.batch.core.job.flow;
import java.util.Collection;
/**
* @author Dave Syer
*
*
*/
public interface Flow {
@@ -34,8 +35,8 @@ public interface Flow {
* @param stateName
* @return the State
*/
public State getState(String stateName);
State getState(String stateName);
/**
* @throws FlowExecutionException
*/
@@ -49,4 +50,11 @@ public interface Flow {
*/
FlowExecution resume(String stateName, FlowExecutor executor) throws FlowExecutionException;
/**
* Convenient accessor for clients needing to explore the states of this
* flow.
* @return the states
*/
Collection<State> getStates();
}

View File

@@ -15,6 +15,9 @@
*/
package org.springframework.batch.core.job.flow;
import java.util.Collection;
import java.util.HashSet;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
@@ -59,12 +62,10 @@ public class FlowJob extends AbstractJob {
this.flow = flow;
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.batch.core.job.AbstractJob#getStep(java.lang.String)
/**
* {@inheritDoc}
*/
@Override
public Step getStep(String stepName) {
State state = this.flow.getState(stepName);
if (state instanceof StepHolder) {
@@ -72,6 +73,20 @@ public class FlowJob extends AbstractJob {
}
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Collection<String> getStepNames() {
Collection<String> steps = new HashSet<String>();
for (State state: flow.getStates()) {
if (state instanceof StepHolder) {
steps.add(state.getName());
}
}
return steps;
}
/**
* @see AbstractJob#doExecute(JobExecution)

View File

@@ -16,7 +16,9 @@
package org.springframework.batch.core.job.flow.support;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -83,13 +85,19 @@ public class SimpleFlow implements Flow, InitializingBean {
this.stateTransitions = stateTransitions;
}
/*
* (non-Javadoc)
* @see org.springframework.batch.core.job.flow.Flow#getState(java.lang.String)
/**
* {@inheritDoc}
*/
public State getState(String stateName) {
return stateMap.get(stateName);
}
/**
* {@inheritDoc}
*/
public Collection<State> getStates() {
return new HashSet<State>(stateMap.values());
}
/**
* Locate start state and pre-populate data structures needed for execution.

View File

@@ -1,5 +1,7 @@
package org.springframework.batch.core.step;
import java.util.Collection;
import org.springframework.batch.core.Step;
/**
@@ -10,6 +12,8 @@ import org.springframework.batch.core.Step;
*/
public interface StepLocator {
Collection<String> getStepNames();
Step getStep(String stepName);
}

View File

@@ -15,8 +15,14 @@
*/
package org.springframework.batch.core.job;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import org.junit.Test;
@@ -174,6 +180,11 @@ public class AbstractJobTests {
public Step getStep(String stepName) {
return null;
}
@Override
public Collection<String> getStepNames() {
return Collections.<String> emptySet();
}
}

View File

@@ -147,6 +147,14 @@ public class SimpleJobTests {
assertEquals(1, jobExecution.getStepExecutions().size());
}
/**
* Test method for {@link SimpleJob#setSteps(java.util.List)}.
*/
@Test
public void testGetSteps() {
assertEquals(2, job.getStepNames().size());
}
/**
* Test method for
* {@link SimpleJob#addStep(org.springframework.batch.core.Step)}.

View File

@@ -67,6 +67,20 @@ public class FlowJobTests {
jobExecution = jobRepository.createJobExecution("job", new JobParameters());
}
@Test
public void testGetSteps() throws Exception {
SimpleFlow flow = new SimpleFlow("job");
List<StateTransition> transitions = new ArrayList<StateTransition>();
transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step1")), "step2"));
transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step2")), "end0"));
transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end0")));
flow.setStateTransitions(transitions);
flow.afterPropertiesSet();
job.setFlow(flow);
job.afterPropertiesSet();
assertEquals(2, job.getStepNames().size());
}
@Test
public void testTwoSteps() throws Exception {
SimpleFlow flow = new SimpleFlow("job");