Skip to content

Commit

Permalink
[JBPM-10230] Fix multiple ForEachNodeInstances (#2418) (#2420)
Browse files Browse the repository at this point in the history
Co-authored-by: Francisco Javier Tirado Sarti <[email protected]>
  • Loading branch information
github-actions[bot] and fjtirado authored Jul 4, 2024
1 parent 2f0ffb2 commit 4266f48
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -826,16 +826,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<CompositeContextNodeInstance> data = forEachNodeInstance.getNodeInstances().stream().filter(e -> e instanceof CompositeContextNodeInstance).map(e -> (CompositeContextNodeInstance) e).collect(Collectors.toList());
List<Object> 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();
Expand Down

0 comments on commit 4266f48

Please sign in to comment.