spring-projects / spring-statemachine

Spring Statemachine is a framework for application developers to use state machine concepts with Spring.
1.52k stars 598 forks source link

Dynamic transition with action via StateMachineModelFactory and TransitionsData #1083

Open kishor-sharma-maersk opened 1 year ago

kishor-sharma-maersk commented 1 year ago

How to add actions dynamically from input data in transition via TransitionsData and StateMachineModelFactory ?

chakradhar4 commented 1 year ago

Use stateContext it works in StateMachineModelFactory also i have used below guard implementation in customstatemachine model factory i think Action have the same implementation

private Function<StateContext<String, String>, Mono> choiceExtvariableGaurd(String varName, String decision) {         return new Function<StateContext<String, String>, Mono>(){             @Override             public Mono apply(StateContext<String, String> t) {                 if (decision.equals(t.getExtendedState().getVariables().get(varName)))                     return Mono.just(true);                 return Mono.just(false);             }         };     }