BATCH-1011: tidy up FlowExecutionStatus name access
This commit is contained in:
@@ -171,7 +171,7 @@ public class FlowParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
|
||||
if (!transitionElementExists) {
|
||||
list.addAll(createTransition(FlowExecutionStatus.FAILED, FlowExecutionStatus.FAILED.toString(), null, null, stateDef, parserContext, false));
|
||||
list.addAll(createTransition(FlowExecutionStatus.FAILED, FlowExecutionStatus.FAILED.getName(), null, null, stateDef, parserContext, false));
|
||||
if (!hasNextAttribute) {
|
||||
list.addAll(createTransition(FlowExecutionStatus.COMPLETED, null, null, null, stateDef, parserContext,
|
||||
false));
|
||||
@@ -212,7 +212,7 @@ public class FlowParser extends AbstractSingleBeanDefinitionParser {
|
||||
private static Collection<BeanDefinition> parseTransitionElement(Element transitionElement, String stateId,
|
||||
BeanDefinition stateDef, ParserContext parserContext) {
|
||||
|
||||
FlowExecutionStatus batchStatus = getBatchStatusFromEndTransitionName(transitionElement.getNodeName());
|
||||
FlowExecutionStatus status = getBatchStatusFromEndTransitionName(transitionElement.getNodeName());
|
||||
String onAttribute = transitionElement.getAttribute("on");
|
||||
String nextAttribute = transitionElement.getAttribute("to");
|
||||
String restartAttribute = transitionElement.getAttribute("restart");
|
||||
@@ -223,12 +223,12 @@ public class FlowParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
String exitCodeAttribute = transitionElement.getAttribute("exit-code");
|
||||
|
||||
return createTransition(batchStatus, onAttribute, nextAttribute, exitCodeAttribute, stateDef, parserContext,
|
||||
return createTransition(status, onAttribute, nextAttribute, exitCodeAttribute, stateDef, parserContext,
|
||||
abandon);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param batchStatus The batch status that this transition will set. Use
|
||||
* @param status The batch status that this transition will set. Use
|
||||
* BatchStatus.UNKNOWN if not applicable.
|
||||
* @param on The pattern that this transition should match. Use null for
|
||||
* "no restriction" (same as "*").
|
||||
@@ -242,14 +242,14 @@ public class FlowParser extends AbstractSingleBeanDefinitionParser {
|
||||
* {@link org.springframework.batch.core.job.flow.support.StateTransition}
|
||||
* references
|
||||
*/
|
||||
private static Collection<BeanDefinition> createTransition(FlowExecutionStatus batchStatus, String on, String next,
|
||||
private static Collection<BeanDefinition> createTransition(FlowExecutionStatus status, String on, String next,
|
||||
String exitCode, BeanDefinition stateDef, ParserContext parserContext, boolean abandon) {
|
||||
|
||||
BeanDefinition endState = null;
|
||||
|
||||
// TODO: revise this for clarity
|
||||
if (batchStatus == FlowExecutionStatus.STOPPED || batchStatus == FlowExecutionStatus.COMPLETED
|
||||
|| batchStatus == FlowExecutionStatus.FAILED) {
|
||||
if (status == FlowExecutionStatus.STOPPED || status == FlowExecutionStatus.COMPLETED
|
||||
|| status == FlowExecutionStatus.FAILED) {
|
||||
|
||||
BeanDefinitionBuilder endBuilder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition("org.springframework.batch.core.job.flow.support.state.EndState");
|
||||
@@ -257,13 +257,13 @@ public class FlowParser extends AbstractSingleBeanDefinitionParser {
|
||||
boolean exitCodeExists = StringUtils.hasText(exitCode);
|
||||
// Make sure exit code is consistent with status for aggregation
|
||||
// purposes
|
||||
if (exitCodeExists && !exitCode.startsWith(batchStatus.toString())) {
|
||||
exitCode = batchStatus.toString() + (exitCode.contains(" ") ? " " : "_") + exitCode;
|
||||
if (exitCodeExists && !exitCode.startsWith(status.getName())) {
|
||||
exitCode = status.getName() + (exitCode.contains(" ") ? " " : "_") + exitCode;
|
||||
}
|
||||
endBuilder.addConstructorArgValue(exitCodeExists ? new FlowExecutionStatus(exitCode) : batchStatus);
|
||||
endBuilder.addConstructorArgValue(exitCodeExists ? new FlowExecutionStatus(exitCode) : status);
|
||||
|
||||
String endName = (batchStatus == FlowExecutionStatus.STOPPED ? STOP
|
||||
: batchStatus == FlowExecutionStatus.FAILED ? FAIL : END)
|
||||
String endName = (status == FlowExecutionStatus.STOPPED ? STOP
|
||||
: status == FlowExecutionStatus.FAILED ? FAIL : END)
|
||||
+ (endCounter++);
|
||||
endBuilder.addConstructorArgValue(endName);
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public class FlowExecutionStatus implements Comparable<FlowExecutionStatus> {
|
||||
*/
|
||||
public static final FlowExecutionStatus UNKNOWN = new FlowExecutionStatus(Status.UNKNOWN.toString());
|
||||
|
||||
private final String status;
|
||||
private final String name;
|
||||
|
||||
private enum Status {
|
||||
|
||||
@@ -68,21 +68,21 @@ public class FlowExecutionStatus implements Comparable<FlowExecutionStatus> {
|
||||
* @param status
|
||||
*/
|
||||
public FlowExecutionStatus(String status) {
|
||||
this.status = status;
|
||||
this.name = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the status starts with "STOPPED"
|
||||
*/
|
||||
public boolean isStop() {
|
||||
return status.startsWith(STOPPED.getStatus());
|
||||
return name.startsWith(STOPPED.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the status starts with "FAILED"
|
||||
*/
|
||||
public boolean isFail() {
|
||||
return status.startsWith(FAILED.toString());
|
||||
return name.startsWith(FAILED.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,11 +95,11 @@ public class FlowExecutionStatus implements Comparable<FlowExecutionStatus> {
|
||||
* @return negative, zero or positive as per the contract
|
||||
*/
|
||||
public int compareTo(FlowExecutionStatus other) {
|
||||
Status one = Status.match(this.status);
|
||||
Status two = Status.match(other.status);
|
||||
Status one = Status.match(this.name);
|
||||
Status two = Status.match(other.name);
|
||||
int comparison = one.compareTo(two);
|
||||
if (comparison == 0) {
|
||||
return this.status.compareTo(other.status);
|
||||
return this.name.compareTo(other.name);
|
||||
}
|
||||
return comparison;
|
||||
}
|
||||
@@ -109,6 +109,7 @@ public class FlowExecutionStatus implements Comparable<FlowExecutionStatus> {
|
||||
*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object == this) {
|
||||
return true;
|
||||
@@ -117,15 +118,27 @@ public class FlowExecutionStatus implements Comparable<FlowExecutionStatus> {
|
||||
return false;
|
||||
}
|
||||
FlowExecutionStatus other = (FlowExecutionStatus) object;
|
||||
return status.equals(other.status);
|
||||
return name.equals(other.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return status;
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
/**
|
||||
* @return the name of this status
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public class FlowJob extends AbstractJob {
|
||||
|
||||
public void updateJobExecutionStatus(FlowExecutionStatus status) {
|
||||
execution.setStatus(findBatchStatus(status));
|
||||
execution.setExitStatus(new ExitStatus(status.getStatus()));
|
||||
execution.setExitStatus(new ExitStatus(status.getName()));
|
||||
}
|
||||
|
||||
public JobExecution getJobExecution() {
|
||||
@@ -150,7 +150,7 @@ public class FlowJob extends AbstractJob {
|
||||
*/
|
||||
private BatchStatus findBatchStatus(FlowExecutionStatus status) {
|
||||
for (BatchStatus batchStatus : BatchStatus.values()) {
|
||||
if (status.getStatus().startsWith(batchStatus.toString())) {
|
||||
if (status.getName().startsWith(batchStatus.toString())) {
|
||||
return batchStatus;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ public class SimpleFlow implements Flow, InitializingBean {
|
||||
}
|
||||
|
||||
String next = null;
|
||||
String exitCode = status.getStatus();
|
||||
String exitCode = status.getName();
|
||||
for (StateTransition stateTransition : set) {
|
||||
if (stateTransition.matches(exitCode)) {
|
||||
if (stateTransition.isEnd()) {
|
||||
@@ -172,7 +172,7 @@ public class SimpleFlow implements Flow, InitializingBean {
|
||||
|
||||
if (next == null) {
|
||||
throw new FlowExecutionException(String.format(
|
||||
"Next state not found in flow=%s for state=%s with exit status=%s", getName(), stateName, status));
|
||||
"Next state not found in flow=%s for state=%s with exit status=%s", getName(), stateName, status.getName()));
|
||||
}
|
||||
|
||||
if (!stateMap.containsKey(next)) {
|
||||
|
||||
@@ -31,7 +31,7 @@ public class FlowExecutionTests {
|
||||
public void testBasicProperties() throws Exception {
|
||||
FlowExecution execution = new FlowExecution("foo", new FlowExecutionStatus("BAR"));
|
||||
assertEquals("foo",execution.getName());
|
||||
assertEquals("BAR",execution.getStatus().getStatus());
|
||||
assertEquals("BAR",execution.getStatus().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user