aboutsummaryrefslogtreecommitdiffstats
path: root/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'appc-lifecycle-management/state-machine-lib/src/main/java/org/onap')
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/StateMachineImpl.java14
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/State.java3
2 files changed, 11 insertions, 6 deletions
diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/StateMachineImpl.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/StateMachineImpl.java
index b56250708..75864a9ba 100644
--- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/StateMachineImpl.java
+++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/StateMachineImpl.java
@@ -25,6 +25,7 @@
package org.onap.appc.statemachine.impl;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import org.onap.appc.exceptions.InvalidInputException;
@@ -40,8 +41,8 @@ import org.onap.appc.statemachine.objects.Transition;
* Implementation of StateMachine
*/
public class StateMachineImpl implements StateMachine {
- private static final String invalidInputFormat = "VNF State or incoming event is invalid. State = %s event = %s";
- static final String toStringFormat = "StateMachineImpl{states=%s, events=%s}";
+ private static final String INVALID_INPUT_FORMAT = "VNF State or incoming event is invalid. State = %s event = %s";
+ static final String TO_STRING_FORMAT = "StateMachineImpl{states=%s, events=%s}";
private final Set<State> states;
private final Set<Event> events;
@@ -57,25 +58,28 @@ public class StateMachineImpl implements StateMachine {
public StateMachineResponse handleEvent(State inputState, Event event) throws InvalidInputException{
if(!validateInputs(inputState,event)){
- throw new InvalidInputException(String.format(invalidInputFormat, inputState, event));
+ throw new InvalidInputException(String.format(INVALID_INPUT_FORMAT, inputState, event));
}
StateMachineResponse response = new StateMachineResponse();
State currentState = null;
State nextState = null;
- for(State stateInSet:states){
+ for(State stateInSet : states){
if(stateInSet.equals(inputState)){
currentState = stateInSet;
break;
}
}
if (currentState != null) {
+ List<Transition> transitions = currentState.getTransitions();
+ if (transitions != null) {
for (Transition transition : currentState.getTransitions()) {
if (event.equals(transition.getEvent())) {
nextState = transition.getNextState();
}
}
}
+ }
if(nextState == null){
response.setResponse(Response.NO_TRANSITION_DEFINED);
}
@@ -98,6 +102,6 @@ public class StateMachineImpl implements StateMachine {
@Override
public String toString() {
- return String.format(toStringFormat, states, events);
+ return String.format(TO_STRING_FORMAT, states, events);
}
}
diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/State.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/State.java
index 117cd76c0..8f099b616 100644
--- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/State.java
+++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/State.java
@@ -67,9 +67,10 @@ public class State {
}
void addTransition(Transition transition) {
+ if (transition != null) {
this.transitions.add(transition);
}
-
+ }
public List<Transition> getTransitions() {
return transitions;
}