From b5fec230cc7fa77d17ef4edec1b6c0b7eb98d93a Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Wed, 22 May 2024 20:22:27 +0200 Subject: [PATCH] [Fix #3524] Use timeout per Event state, not per Event type --- .../parser/handlers/EventHandler.java | 58 ++++++------------- 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/EventHandler.java b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/EventHandler.java index 0a9c385b331..9ccecb22a79 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/EventHandler.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/EventHandler.java @@ -33,14 +33,10 @@ import org.kie.kogito.serverless.workflow.parser.ServerlessWorkflowParser; import io.serverlessworkflow.api.Workflow; -import io.serverlessworkflow.api.actions.Action; import io.serverlessworkflow.api.events.OnEvents; import io.serverlessworkflow.api.states.EventState; -import static org.kie.kogito.serverless.workflow.parser.handlers.NodeFactoryUtils.eventBasedSplitNode; -import static org.kie.kogito.serverless.workflow.parser.handlers.NodeFactoryUtils.joinExclusiveNode; import static org.kie.kogito.serverless.workflow.parser.handlers.NodeFactoryUtils.startMessageNode; -import static org.kie.kogito.serverless.workflow.utils.TimeoutsConfigResolver.resolveEventTimeout; public class EventHandler extends CompositeContextNodeHandler { @@ -53,47 +49,27 @@ public void handleStart() { // disable standard procedure } - @Override public MakeNodeResult makeNode(RuleFlowNodeContainerFactory factory) { - return joinNodes(factory, state.getOnEvents(), this::processOnEvent); - } - - private MakeNodeResult processOnEvent(RuleFlowNodeContainerFactory factory, OnEvents onEvent) { if (isStartState) { - MakeNodeResult result = joinNodes(factory, - onEvent.getEventRefs(), (fact, onEventRef) -> filterAndMergeNode(fact, onEvent.getEventDataFilter(), ServerlessWorkflowParser.DEFAULT_WORKFLOW_VAR, - (f, inputVar, outputVar) -> buildEventNode(f, onEventRef, inputVar, outputVar))); - CompositeContextNodeFactory embeddedSubProcess = handleActions(makeCompositeNode(factory), onEvent.getActions()); - connect(result.getOutgoingNode(), embeddedSubProcess); - return new MakeNodeResult(result.getIncomingNode(), embeddedSubProcess); + return joinNodes(factory, state.getOnEvents(), this::processOnEvent); } else { - String varName = getVarName(); - CompositeContextNodeFactory embeddedSubProcess = makeCompositeNode(factory); - NodeFactory startNode = embeddedSubProcess.startNode(parserContext.newId()).name("EmbeddedStart"); - JoinFactory joinNode = null; - String eventTimeout = resolveEventTimeout(state, workflow); - if (eventTimeout != null) { - // creating a split-join branch for the timer - SplitFactory splitNode = eventBasedSplitNode(embeddedSubProcess.splitNode(parserContext.newId()), Split.TYPE_XAND); - joinNode = joinExclusiveNode(embeddedSubProcess.joinNode(parserContext.newId())); - startNode = connect(startNode, splitNode); - createTimerNode(embeddedSubProcess, splitNode, joinNode, eventTimeout); - } - MakeNodeResult result = joinNodes(embeddedSubProcess, - onEvent.getEventRefs(), (fact, onEventRef) -> filterAndMergeNode(fact, onEvent.getEventDataFilter(), varName, - (f, inputVar, outputVar) -> buildEventNode(f, onEventRef, inputVar, outputVar))); - connect(startNode, result.getIncomingNode()); - NodeFactory currentNode = result.getOutgoingNode(); - for (Action action : onEvent.getActions()) { - currentNode = connect(currentNode, getActionNode(embeddedSubProcess, action, varName, true)); - } - if (joinNode != null) { - currentNode = connect(currentNode, joinNode); - } - connect(currentNode, embeddedSubProcess.endNode(parserContext.newId()).name("EmbeddedEnd").terminate(true)).done(); - handleErrors(parserContext.factory(), embeddedSubProcess); - return new MakeNodeResult(embeddedSubProcess); + CompositeContextNodeFactory embeddedContainer = makeCompositeNode(factory); + connect(connect(embeddedContainer.startNode(parserContext.newId()).name("EmbeddedStart"), + makeTimeoutNode(embeddedContainer, joinNodes(embeddedContainer, state.getOnEvents(), this::processOnEvent))), + embeddedContainer.endNode(parserContext.newId()).name("EmbeddedEnd").terminate(true)).done(); + handleErrors(factory, embeddedContainer); + return new MakeNodeResult(embeddedContainer); } + + } + + private MakeNodeResult processOnEvent(RuleFlowNodeContainerFactory factory, OnEvents onEvent) { + MakeNodeResult result = joinNodes(factory, + onEvent.getEventRefs(), (fact, onEventRef) -> filterAndMergeNode(fact, onEvent.getEventDataFilter(), isStartState ? ServerlessWorkflowParser.DEFAULT_WORKFLOW_VAR : getVarName(), + (f, inputVar, outputVar) -> buildEventNode(f, onEventRef, inputVar, outputVar))); + CompositeContextNodeFactory embeddedSubProcess = handleActions(makeCompositeNode(factory), onEvent.getActions()); + connect(result.getOutgoingNode(), embeddedSubProcess); + return new MakeNodeResult(result.getIncomingNode(), embeddedSubProcess); } private MakeNodeResult joinNodes(RuleFlowNodeContainerFactory factory, List events, BiFunction, T, MakeNodeResult> function) {