use of io.serverlessworkflow.api.transitions.Transition in project kogito-runtimes by kiegroup.
the class SwitchValidatorTest method validateDefaultConditionWithEventConditionsTransitionButTimeoutNotSetError.
@Test
void validateDefaultConditionWithEventConditionsTransitionButTimeoutNotSetError() {
switchState.getEventConditions().add(mock(EventCondition.class));
DefaultConditionDefinition defaultCondition = mockDefaultConditionWithTransition();
Transition transition = defaultCondition.getTransition();
doReturn(NEXT_STATE).when(transition).getNextState();
StateHandler<?> stateHandler = mock(StateHandler.class);
doReturn(stateHandler).when(parserContext).getStateHandler(NEXT_STATE);
Assertions.assertThatThrownBy(() -> SwitchValidator.validateDefaultCondition(defaultCondition, switchState, workflow, parserContext)).isInstanceOf(IllegalArgumentException.class).hasMessage(String.format(EVENT_TIMEOUT_REQUIRED_ERROR, SWITCH_STATE_NAME, WORKFLOW_NAME));
}
use of io.serverlessworkflow.api.transitions.Transition in project kogito-runtimes by kiegroup.
the class SwitchHandler method finalizeEventBasedSwitchState.
private void finalizeEventBasedSwitchState(RuleFlowNodeContainerFactory<?, ?> factory) {
NodeFactory<?, ?> splitNode = getNode();
List<EventCondition> conditions = state.getEventConditions();
DefaultConditionDefinition defaultCondition = state.getDefaultCondition();
if (defaultCondition != null) {
validateDefaultCondition(defaultCondition, state, workflow, parserContext);
String eventTimeout = resolveEventTimeout(state, workflow);
// Create the timer for controlling the eventTimeout and connect it with the exclusive split.
TimerNodeFactory<?> eventTimeoutTimerNode = timerNode(factory.timerNode(parserContext.newId()), eventTimeout);
connect(splitNode, eventTimeoutTimerNode);
Transition transition = defaultCondition.getTransition();
if (transition != null) {
StateHandler<?> targetState = parserContext.getStateHandler(transition);
// Connect the timer with the target state.
targetState.connect(factory, eventTimeoutTimerNode.getNode().getId());
} else {
// Connect the timer with a process finalization sequence that might produce events.
endIt(eventTimeoutTimerNode.getNode().getId(), factory, defaultCondition.getEnd().getProduceEvents());
}
}
// Process the event conditions.
for (EventCondition eventCondition : conditions) {
StateHandler<?> targetState = parserContext.getStateHandler(eventCondition.getTransition());
// Create the event reception and later processing sequence.
MakeNodeResult eventNode = filterAndMergeNode(factory, eventCondition.getEventDataFilter(), (f, inputVar, outputVar) -> consumeEventNode(f, eventCondition.getEventRef(), inputVar, outputVar));
// Connect it with the split node
factory.connection(splitNode.getNode().getId(), eventNode.getIncomingNode().getNode().getId());
// Connect the last node of the sequence with the target state.
targetState.connect(factory, eventNode.getOutgoingNode().getNode().getId());
}
}
use of io.serverlessworkflow.api.transitions.Transition in project kogito-runtimes by kiegroup.
the class StateHandler method handleCompensation.
private long handleCompensation(RuleFlowNodeContainerFactory<?, ?> embeddedSubProcess, StateHandler<?> compensation) {
if (compensation.getState().getCompensatedBy() != null) {
throw new IllegalArgumentException("Serverless workflow specification forbids nested compensations, hence state " + compensation.getState().getName() + " is not valid");
}
compensation.handleState(embeddedSubProcess);
Transition transition = compensation.getState().getTransition();
long lastNodeId = compensation.getNode().getNode().getId();
compensation.handleTransitions(embeddedSubProcess, transition, lastNodeId);
compensation.handleErrors(embeddedSubProcess);
compensation.handleConnections(embeddedSubProcess);
return lastNodeId;
}
use of io.serverlessworkflow.api.transitions.Transition in project kogito-runtimes by kiegroup.
the class SwitchHandler method finalizeDataBasedSwitchState.
private void finalizeDataBasedSwitchState(RuleFlowNodeContainerFactory<?, ?> factory) {
final NodeFactory<?, ?> startNode = getNode();
final long splitId = startNode.getNode().getId();
DefaultConditionDefinition defaultCondition = state.getDefaultCondition();
// set default connection
if (defaultCondition != null) {
validateDefaultCondition(defaultCondition, state, workflow, parserContext);
Transition transition = defaultCondition.getTransition();
if (transition != null) {
StateHandler<?> stateHandler = parserContext.getStateHandler(transition);
startNode.metaData(XORSPLITDEFAULT, concatId(splitId, stateHandler.getNode().getNode().getId()));
} else {
EndNodeFactory<?> endNodeFactory = endIt(splitId, factory, defaultCondition.getEnd().getProduceEvents());
startNode.metaData(XORSPLITDEFAULT, concatId(splitId, endNodeFactory.getNode().getId()));
}
}
List<DataCondition> conditions = state.getDataConditions();
for (DataCondition condition : conditions) {
handleTransition(factory, condition.getTransition(), splitId, Optional.of(new StateHandler.HandleTransitionCallBack() {
@Override
public void onStateTarget(StateHandler<?> targetState) {
targetHandlers.add(() -> addConstraint(factory, startNode, targetState, condition));
}
@Override
public void onIdTarget(long targetId) {
addConstraint(startNode, targetId, condition);
}
@Override
public void onEmptyTarget() {
if (condition.getEnd() != null) {
EndNodeFactory<?> endNodeFactory = endIt(splitId, factory, condition.getEnd().getProduceEvents());
addConstraint(startNode, endNodeFactory.getNode().getId(), condition);
} else {
throw new IllegalArgumentException("Invalid condition, not transition not end");
}
}
}));
}
}
use of io.serverlessworkflow.api.transitions.Transition in project kogito-runtimes by kiegroup.
the class SwitchValidatorTest method validateDefaultConditionTransitionNextStateNotFoundError.
@Test
void validateDefaultConditionTransitionNextStateNotFoundError() {
DefaultConditionDefinition defaultCondition = mockDefaultConditionWithTransition();
Transition transition = defaultCondition.getTransition();
doReturn(NEXT_STATE).when(transition).getNextState();
Assertions.assertThatThrownBy(() -> SwitchValidator.validateDefaultCondition(defaultCondition, switchState, workflow, parserContext)).isInstanceOf(IllegalArgumentException.class).hasMessage(String.format(NEXT_STATE_NOT_FOUND_FOR_DEFAULT_CONDITION_ERROR, NEXT_STATE, SWITCH_STATE_NAME, WORKFLOW_NAME));
}
Aggregations