summaryrefslogtreecommitdiffstats
path: root/appc-lifecycle-management/state-machine-lib/src/main
diff options
context:
space:
mode:
authorDilip kumar Pampana <dp583p@att.com>2018-01-10 10:26:15 -0500
committerSkip Wonnell <skip@att.com>2018-01-10 16:47:56 +0000
commit14ee9cc1ceb81bd6fe963e4d3580595830885714 (patch)
treed3d12b05bffd535bb0c98a1bf1d1309478d49529 /appc-lifecycle-management/state-machine-lib/src/main
parent40bae6d46b1fc0d91da8b16d07b145c86ecf7c0c (diff)
Life Cycle Managment Updates
Issue-ID: APPC-349 Change-Id: Ifdb7bf973c08374bea43c298005d88f2a9d15dd0 Signed-off-by: Dilip kumar Pampana <dp583p@att.com>
Diffstat (limited to 'appc-lifecycle-management/state-machine-lib/src/main')
-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;
}