From ff3b8b6063b34082d0b07b119677002cad50246d Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti <65240126+fjtirado@users.noreply.github.com> Date: Tue, 4 Jun 2024 12:51:55 +0200 Subject: [PATCH] [Fix_#3451] Fixing start event state filtering (#3542) * [Fix_#3451] Fixing start event state filtering * [Fix_#3451] Add IT test --- .../parser/handlers/EventHandler.java | 3 +- .../parser/handlers/StateHandler.java | 12 +++++- .../src/main/resources/application.properties | 6 +++ .../src/main/resources/greetCustomer.sw.json | 41 +++++++++++++++++++ .../kogito/quarkus/workflows/EventFlowIT.java | 22 ++++++++++ 5 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/greetCustomer.sw.json 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 9ccecb22a79..6c95879a018 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 @@ -30,7 +30,6 @@ import org.jbpm.workflow.core.node.Join; import org.jbpm.workflow.core.node.Split; import org.kie.kogito.serverless.workflow.parser.ParserContext; -import org.kie.kogito.serverless.workflow.parser.ServerlessWorkflowParser; import io.serverlessworkflow.api.Workflow; import io.serverlessworkflow.api.events.OnEvents; @@ -65,7 +64,7 @@ public MakeNodeResult makeNode(RuleFlowNodeContainerFactory factory) { 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(), + onEvent.getEventRefs(), (fact, onEventRef) -> filterAndMergeNode(fact, onEvent.getEventDataFilter(), getVarName(), (f, inputVar, outputVar) -> buildEventNode(f, onEventRef, inputVar, outputVar))); CompositeContextNodeFactory embeddedSubProcess = handleActions(makeCompositeNode(factory), onEvent.getActions()); connect(result.getOutgoingNode(), embeddedSubProcess); diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/StateHandler.java b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/StateHandler.java index 63610ad6b71..5c9caf6f451 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/StateHandler.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/StateHandler.java @@ -50,6 +50,7 @@ import org.kie.kogito.serverless.workflow.SWFConstants; import org.kie.kogito.serverless.workflow.parser.ParserContext; import org.kie.kogito.serverless.workflow.parser.ServerlessWorkflowParser; +import org.kie.kogito.serverless.workflow.parser.VariableInfo; import org.kie.kogito.serverless.workflow.suppliers.CollectorActionSupplier; import org.kie.kogito.serverless.workflow.suppliers.CompensationActionSupplier; import org.kie.kogito.serverless.workflow.suppliers.ErrorExpressionActionSupplier; @@ -424,7 +425,8 @@ protected final MakeNodeResult filterAndMergeNode(RuleFlowNodeContainerFactory embeddedSubProcess, String actionVarName, String fromStateExpr, String resultExpr, String toStateExpr, boolean useData, boolean shouldMerge, FilterableNodeSupplier nodeSupplier) { + return filterAndMergeNode(embeddedSubProcess, new VariableInfo(actionVarName, actionVarName), fromStateExpr, resultExpr, toStateExpr, useData, shouldMerge, nodeSupplier); + } + protected final MakeNodeResult filterAndMergeNode(RuleFlowNodeContainerFactory embeddedSubProcess, VariableInfo variableInfo, String fromStateExpr, String resultExpr, String toStateExpr, + boolean useData, + boolean shouldMerge, FilterableNodeSupplier nodeSupplier) { + String actionVarName = variableInfo.getOutputVar(); if (isTempVariable(actionVarName)) { embeddedSubProcess.variable(actionVarName, new ObjectDataType(JsonNode.class.getCanonicalName()), Map.of(KogitoTags.VARIABLE_TAGS, KogitoTags.INTERNAL_TAG)); } @@ -451,7 +459,7 @@ protected final MakeNodeResult filterAndMergeNode(RuleFlowNodeContainerFactory