From 492f41a49eab99e59598c1a9c2aee94f6de7557d Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti <65240126+fjtirado@users.noreply.github.com> Date: Mon, 20 May 2024 10:49:42 +0200 Subject: [PATCH] [JBPM-10230] Fix multiple ForEachNodeInstances (#2418) --- .../impl/WorkflowProcessInstanceImpl.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java b/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java index 4ced5937be..d99a6d4672 100644 --- a/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java +++ b/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java @@ -823,16 +823,18 @@ public VariableResolver getVariableResolver(String varName) { return (varExpression) -> { try { // for each can have multiple outcomes 1 per item of the list so it should be computed like that - ForEachNodeInstance forEachNodeInstance = (ForEachNodeInstance) getNodeInstanceByNodeId(node.getId(), true); - if(forEachNodeInstance == null) { - return new Object[0]; - } - List data = forEachNodeInstance.getNodeInstances().stream().filter(e -> e instanceof CompositeContextNodeInstance).map(e -> (CompositeContextNodeInstance) e).collect(Collectors.toList()); List outcome = new ArrayList<>(); - for(CompositeContextNodeInstance nodeInstance : data) { - Object resolvedValue = resolveExpressionVariable(varExpression, new NodeInstanceResolverFactory(nodeInstance)).orElse(null); - if(resolvedValue != null) { - outcome.add(resolvedValue); + for (NodeInstance item : getNodeInstances(true)) { + if (item.getNodeId() == node.getId() && item instanceof ForEachNodeInstance) { + for (org.kie.api.runtime.process.NodeInstance nodeInstance : ((ForEachNodeInstance) item) + .getNodeInstances()) { + if (nodeInstance instanceof CompositeContextNodeInstance) { + resolveExpressionVariable(varExpression, + new NodeInstanceResolverFactory( + (CompositeContextNodeInstance) nodeInstance)) + .ifPresent(outcome::add); + } + } } } return outcome.toArray();