Skip to content
Snippets Groups Projects

F fsm

Merged Timm Fitschen requested to merge f-fsm into dev
3 files
+ 144
56
Compare changes
  • Side-by-side
  • Inline

Files

@@ -35,17 +35,17 @@ public class CheckStateTransition extends EntityStateJob {
@Override
protected void run() {
try {
State nextState = getState();
if (nextState != null) {
checkStateValid(nextState);
State newState = getState();
if (newState != null) {
checkStateValid(newState);
}
if (getEntity() instanceof UpdateEntity) {
State fromState = getState(((UpdateEntity) getEntity()).getOriginal());
checkStateTransition(fromState, nextState);
State oldState = getState(((UpdateEntity) getEntity()).getOriginal());
checkStateTransition(oldState, newState);
} else if (getEntity() instanceof DeleteEntity) {
if (nextState != null) checkFinalState(nextState);
if (newState != null) checkFinalState(newState);
} else {
if (nextState != null) checkInitialState(nextState);
if (newState != null) checkInitialState(newState);
}
} catch (Message m) {
getEntity().addError(m);
@@ -68,31 +68,31 @@ public class CheckStateTransition extends EntityStateJob {
/**
* Check if state is valid and transition is allowed.
*
* @param fromState
* @param toState
* @param oldState
* @param newState
* @throws Message if not
*/
private void checkStateTransition(State fromState, State toState) throws Message {
if (fromState == null && toState == null) {
private void checkStateTransition(State oldState, State newState) throws Message {
if (oldState == null && newState == null) {
return;
} else if (fromState == null && toState != null) {
checkInitialState(toState);
} else if (oldState == null && newState != null) {
checkInitialState(newState);
return;
} else if (toState == null && fromState != null) {
checkFinalState(fromState);
} else if (newState == null && oldState != null) {
checkFinalState(oldState);
return;
}
StateModel stateModel = findMatchingStateModel(fromState, toState);
StateModel stateModel = findMatchingStateModel(oldState, newState);
if (stateModel == null) {
// change from one stateModel to another
checkInitialState(toState);
checkFinalState(fromState);
checkInitialState(newState);
checkFinalState(oldState);
return;
}
for (Transition t : stateModel.getTransitions()) {
if (t.fromStatesInclude(fromState) && t.toStatesInclude(toState)) {
if (t.isFromState(oldState) && t.isToState(newState)) {
// TODO permissions
return;
}
@@ -101,14 +101,14 @@ public class CheckStateTransition extends EntityStateJob {
}
/**
* @param fromState
* @param toState
* @param oldState
* @param newState
* @return the state model which contains both of the states.
* @throws Message if the state model of one of the states cannot be constructed.
*/
private StateModel findMatchingStateModel(State fromState, State toState) throws Message {
if (fromState.getStateModel().equals(toState.getStateModel())) {
return fromState.getStateModel();
private StateModel findMatchingStateModel(State oldState, State newState) throws Message {
if (oldState.getStateModel().equals(newState.getStateModel())) {
return oldState.getStateModel();
}
return null;
}
@@ -116,11 +116,11 @@ public class CheckStateTransition extends EntityStateJob {
/**
* Check if the old state is final or if the {@link FORCE_FINAL_STATE} flag is true.
*
* @param fromState
* @param oldState
* @throws Message if the state is not final.
*/
private void checkFinalState(State fromState) throws Message {
if (!fromState.isFinal()) {
private void checkFinalState(State oldState) throws Message {
if (!oldState.isFinal()) {
if ("true".equalsIgnoreCase(getTransaction().getContainer().getFlags().get(FORCE_FINAL_STATE))
|| "true".equalsIgnoreCase(getEntity().getFlag(FORCE_FINAL_STATE))) {
// TODO permissions
@@ -134,11 +134,11 @@ public class CheckStateTransition extends EntityStateJob {
/**
* Check if the new state is an initial state.
*
* @param toState
* @param newState
* @throws Message if not
*/
private void checkInitialState(State toState) throws Message {
if (!toState.isInitial()) {
private void checkInitialState(State newState) throws Message {
if (!newState.isInitial()) {
throw INITIAL_STATE_NOT_ALLOWED;
}
// TODO permissions
Loading