Skip to content

Commit

Permalink
[Fix_#3451] Fixing start event state filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed May 31, 2024
1 parent 47e5732 commit c20cf27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -424,7 +425,8 @@ protected final MakeNodeResult filterAndMergeNode(RuleFlowNodeContainerFactory<?
toExpr = eventFilter.getToStateData();
useData = eventFilter.isUseData();
}
return filterAndMergeNode(embeddedSubProcess, varName, null, dataExpr, toExpr, useData, true, nodeSupplier);
return filterAndMergeNode(embeddedSubProcess, isStartState ? new VariableInfo(DEFAULT_WORKFLOW_VAR, varName) : new VariableInfo(varName, varName), null, dataExpr, toExpr, useData, true,
nodeSupplier);
}

protected boolean isTempVariable(String varName) {
Expand All @@ -434,7 +436,13 @@ protected boolean isTempVariable(String varName) {
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));
}
Expand All @@ -451,7 +459,7 @@ protected final MakeNodeResult filterAndMergeNode(RuleFlowNodeContainerFactory<?

if (useData && resultExpr != null) {
currentNode = connect(currentNode, embeddedSubProcess.actionNode(parserContext.newId()).action(ExpressionActionSupplier.of(workflow, resultExpr)
.withVarNames(actionVarName, actionVarName).build()));
.withVarNames(variableInfo.getInputVar(), actionVarName).build()));
}

if (useData) {
Expand Down

0 comments on commit c20cf27

Please sign in to comment.