diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/builtin/JavaConstraintEvaluatorBuilder.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/builtin/JavaConstraintEvaluatorBuilder.java index 621592cc278..a2831596274 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/builtin/JavaConstraintEvaluatorBuilder.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/builtin/JavaConstraintEvaluatorBuilder.java @@ -57,7 +57,7 @@ public Expression build(ContextResolver resolver, String expression, Class ty } if (blockStmt == null) { - blockStmt = StaticJavaParser.parseBlock(expression); + blockStmt = StaticJavaParser.parseBlock("{" + expression + "}"); } Set identifiers = new HashSet<>(blockStmt.findAll(NameExpr.class)); @@ -79,7 +79,7 @@ public Expression build(ContextResolver resolver, String expression, Class ty private BlockStmt parseStatement(String expression) { try { BlockStmt block = new BlockStmt(); - block.addStatement(StaticJavaParser.parseStatement("{" + expression + "}")); + block.addStatement(StaticJavaParser.parseStatement(expression)); return block; } catch (ParseProblemException e) { return null; diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/DynamicNode.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/DynamicNode.java index 5130acaddc2..d38584d943d 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/DynamicNode.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/DynamicNode.java @@ -25,7 +25,7 @@ import org.jbpm.process.instance.impl.ReturnValueEvaluator; import org.kie.api.definition.process.Node; import org.kie.api.definition.process.WorkflowElementIdentifier; -import org.kie.api.runtime.process.ProcessContext; +import org.kie.kogito.internal.process.runtime.KogitoProcessContext; import static org.jbpm.ruleflow.core.Metadata.CUSTOM_AUTO_START; @@ -99,12 +99,12 @@ public DynamicNode setCompletionExpression(ReturnValueEvaluator copmletionPredic return this; } - public boolean canActivate(ProcessContext context) { - return activationPredicate == null || (Boolean) activationPredicate.eval(context); + public boolean canActivate(KogitoProcessContext context) { + return activationPredicate == null || (Boolean) activationPredicate.evaluate(context); } - public boolean canComplete(ProcessContext context) { - return isAutoComplete() || (completionPredicate != null && (Boolean) completionPredicate.eval(context)); + public boolean canComplete(KogitoProcessContext context) { + return isAutoComplete() || (completionPredicate != null && (Boolean) completionPredicate.evaluate(context)); } public boolean hasCompletionCondition() { diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/NodeInstanceContainer.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/NodeInstanceContainer.java index 3fb400cc16d..388c134b173 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/NodeInstanceContainer.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/NodeInstanceContainer.java @@ -66,7 +66,7 @@ default NodeInstance getByNodeDefinitionId(final String nodeDefinitionId, NodeCo if (nodeDefinitionId.equals(node.getUniqueId())) { if (nodeContainer instanceof Node) { - Collection nodeInstances = getKogitoNodeInstances(ni -> ni.getNode().getId() == (((Node) nodeContainer).getId()), true); + Collection nodeInstances = getKogitoNodeInstances(ni -> ni.getNode().getId().equals(((Node) nodeContainer).getId()), true); if (nodeInstances.isEmpty()) { return ((NodeInstanceContainer) getNodeInstance((Node) nodeContainer)).getNodeInstance(node); } else { diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java index 969316760f1..f7015820700 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java @@ -946,7 +946,7 @@ public void nodeInstanceCompleted(NodeInstance nodeInstance, String outType) { } private boolean canComplete() { - if (nodeInstances.isEmpty() || nodeInstances.stream().anyMatch(Predicate.not(NodeInstance::isCancelled))) { + if (nodeInstances.isEmpty()) { return true; } else { int eventSubprocessCounter = 0; diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/DynamicNodeInstance.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/DynamicNodeInstance.java index b8899d34b4a..d155cc640cd 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/DynamicNodeInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/DynamicNodeInstance.java @@ -80,7 +80,8 @@ private boolean canActivate() { return getDynamicNode().canActivate(ContextFactory.fromNode(this)); } - public boolean canComplete() { + private boolean canComplete() { + return getNodeInstances(false).isEmpty() && getDynamicNode().canComplete(ContextFactory.fromNode(this)); } @@ -112,9 +113,9 @@ public void nodeInstanceCompleted(org.jbpm.workflow.instance.NodeInstance nodeIn return; } } - + // TODO what if we reach the end of one branch but others might still need to be created ? + // TODO are we sure there will always be node instances left if we are not done yet? if (isTerminated(nodeInstance) || canComplete()) { - this.cancelType = CancelType.OBSOLETE; triggerCompleted(CONNECTION_DEFAULT_TYPE); } if (!canComplete()) { diff --git a/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcessInstance.java b/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcessInstance.java index 9f49340e952..d2fcc15cc61 100644 --- a/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcessInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcessInstance.java @@ -40,7 +40,6 @@ import org.jbpm.workflow.core.Node; import org.jbpm.workflow.core.WorkflowProcess; import org.jbpm.workflow.instance.NodeInstance; -import org.jbpm.workflow.instance.NodeInstanceContainer; import org.jbpm.workflow.instance.WorkflowProcessInstance; import org.jbpm.workflow.instance.impl.NodeInstanceImpl; import org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl; @@ -441,17 +440,12 @@ public void triggerNode(String nodeId) { WorkflowProcessInstance wfpi = processInstance(); RuleFlowProcess rfp = ((RuleFlowProcess) wfpi.getProcess()); - org.kie.api.definition.process.Node node = rfp.getNodesRecursively() - .stream() - .filter(ni -> Objects.equals(nodeId, ni.getUniqueId()) || Objects.equals(nodeId, ni.getName()) || Objects.equals(nodeId, ni.getId().toExternalFormat())) - .findFirst() - .orElseThrow(() -> new NodeNotFoundException(this.id, nodeId)); - - org.kie.api.definition.process.Node parentNode = rfp.getParentNode(node.getId()); - - NodeInstanceContainer nodeInstanceContainerNode = parentNode == null ? wfpi : ((NodeInstanceContainer) wfpi.getNodeInstance(parentNode)); - - nodeInstanceContainerNode.getNodeInstance(node).trigger(null, Node.CONNECTION_DEFAULT_TYPE); + // we avoid create containers incorrectly + NodeInstance nodeInstance = wfpi.getByNodeDefinitionId(nodeId, rfp); + if (nodeInstance == null) { + throw new NodeNotFoundException(this.id, nodeId); + } + nodeInstance.trigger(null, Node.CONNECTION_DEFAULT_TYPE); addToUnitOfWork(pi -> ((MutableProcessInstances) process.instances()).update(pi.id(), pi)); }