[Minor] Allow to set Action to ERROR, if already in ERROR

This commit is contained in:
Robert von Burg 2017-08-09 11:31:10 +02:00
parent 27b6beff03
commit cfe8664ddc
2 changed files with 32 additions and 32 deletions

View File

@ -73,7 +73,7 @@ public enum State {
* @return true if the state is {@link #ERROR} or {@link #STOPPED} * @return true if the state is {@link #ERROR} or {@link #STOPPED}
*/ */
public boolean inErrorPhase() { public boolean inErrorPhase() {
return this == State.ERROR || this == State.STOPPED; return this == ERROR || this == STOPPED;
} }
/** /**
@ -94,42 +94,42 @@ public enum State {
* @return true if the state is {@link #CREATED} * @return true if the state is {@link #CREATED}
*/ */
public boolean isCreated() { public boolean isCreated() {
return this == State.CREATED; return this == CREATED;
} }
/** /**
* @return true if the state is {@link #PLANNING} * @return true if the state is {@link #PLANNING}
*/ */
public boolean isInPlanning() { public boolean isInPlanning() {
return this == State.PLANNING; return this == PLANNING;
} }
/** /**
* @return true if the state is {@link #PLANNED} * @return true if the state is {@link #PLANNED}
*/ */
public boolean isInPlanned() { public boolean isInPlanned() {
return this == State.PLANNED; return this == PLANNED;
} }
/** /**
* @return true if the state is {@link #EXECUTION} * @return true if the state is {@link #EXECUTION}
*/ */
public boolean isInExecution() { public boolean isInExecution() {
return this == State.EXECUTION; return this == EXECUTION;
} }
/** /**
* @return true if the state is {@link #WARNING} * @return true if the state is {@link #WARNING}
*/ */
public boolean isInWarning() { public boolean isInWarning() {
return this == State.WARNING; return this == WARNING;
} }
/** /**
* @return true if the state is {@link #ERROR} * @return true if the state is {@link #ERROR}
*/ */
public boolean isInError() { public boolean isInError() {
return this == State.ERROR; return this == ERROR;
} }
/** /**
@ -157,21 +157,21 @@ public enum State {
* @return true if {@link #ERROR} * @return true if {@link #ERROR}
*/ */
public boolean canSetToStopped() { public boolean canSetToStopped() {
return this == State.ERROR; return this == ERROR;
} }
/** /**
* @return true if {@link #STARTING} or {@link #EXECUTION} or {@link #WARNING} * @return true if {@link #STARTING} or {@link #EXECUTION} or {@link #WARNING}
*/ */
public boolean canSetToError() { public boolean canSetToError() {
return this == State.EXECUTION || this == State.WARNING; return this == EXECUTION || this == WARNING || this == ERROR;
} }
/** /**
* @return true if {@link #EXECUTION} or {@link #WARNING} or {@link #STOPPED} * @return true if {@link #EXECUTION} or {@link #WARNING} or {@link #STOPPED}
*/ */
public boolean canSetToExecuted() { public boolean canSetToExecuted() {
return this == State.EXECUTION || this == State.WARNING || this == State.STOPPED; return this == EXECUTION || this == WARNING || this == STOPPED;
} }
public static State parse(String s) { public static State parse(String s) {
@ -193,40 +193,40 @@ public enum State {
return states.iterator().next(); return states.iterator().next();
// error // error
if (states.contains(State.ERROR)) if (states.contains(ERROR))
return State.ERROR; return ERROR;
// stopped // stopped
if (states.contains(State.STOPPED)) if (states.contains(STOPPED))
return State.STOPPED; return STOPPED;
// warning // warning
if (states.contains(State.WARNING)) if (states.contains(WARNING))
return State.WARNING; return WARNING;
// execution // execution
if (states.contains(State.EXECUTION)) if (states.contains(EXECUTION))
return State.EXECUTION; return EXECUTION;
if (states.contains(State.EXECUTED) && (states.contains(State.CREATED) || states.contains(State.PLANNING) if (states.contains(EXECUTED)
|| states.contains(State.PLANNED))) && (states.contains(CREATED) || states.contains(PLANNING) || states.contains(PLANNED)))
return State.EXECUTION; return EXECUTION;
// executed // executed
if (states.contains(State.EXECUTED) && (states.contains(State.CLOSED))) if (states.contains(EXECUTED) && (states.contains(CLOSED)))
return State.EXECUTED; return EXECUTED;
// planning // planning
if (states.contains(State.PLANNING)) if (states.contains(PLANNING))
return State.PLANNING; return PLANNING;
if (states.contains(State.PLANNED) && (states.contains(State.CREATED) || states.contains(State.PLANNING))) if (states.contains(PLANNED) && (states.contains(CREATED) || states.contains(PLANNING)))
return State.PLANNING; return PLANNING;
// planned // planned
if (states.contains(State.PLANNED) && (states.contains(State.CLOSED))) if (states.contains(PLANNED) && (states.contains(CLOSED)))
return State.PLANNED; return PLANNED;
if (states.contains(State.CREATED) && (states.contains(State.CLOSED))) if (states.contains(CREATED) && (states.contains(CLOSED)))
return State.CREATED; return CREATED;
// should never happen, unless new state is introduced // should never happen, unless new state is introduced
throw new IllegalStateException("Unhandled situation with states: " throw new IllegalStateException("Unhandled situation with states: "

View File

@ -27,7 +27,7 @@ public class SetActionToErrorCommand extends ExecutionCommand {
DBC.PRE.assertNotNull("action can not be null", this.action); DBC.PRE.assertNotNull("action can not be null", this.action);
if (!this.action.getState().canSetToError()) { if (!this.action.getState().canSetToError()) {
String msg = "State {0} and canot be changed to {1} for action {2}"; String msg = "Current state is {0} and canot be changed to {1} for action {2}";
msg = MessageFormat.format(msg, this.action.getState(), State.ERROR, this.action.getLocator()); msg = MessageFormat.format(msg, this.action.getState(), State.ERROR, this.action.getLocator());
throw new StrolchException(msg); throw new StrolchException(msg);
} }