Skip to content

Commit

Permalink
fix trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
elguardian committed Jun 4, 2024
1 parent 30793c6 commit 6ba74e0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<NameExpr> identifiers = new HashSet<>(blockStmt.findAll(NameExpr.class));
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ default NodeInstance getByNodeDefinitionId(final String nodeDefinitionId, NodeCo

if (nodeDefinitionId.equals(node.getUniqueId())) {
if (nodeContainer instanceof Node) {
Collection<KogitoNodeInstance> nodeInstances = getKogitoNodeInstances(ni -> ni.getNode().getId() == (((Node) nodeContainer).getId()), true);
Collection<KogitoNodeInstance> nodeInstances = getKogitoNodeInstances(ni -> ni.getNode().getId().equals(((Node) nodeContainer).getId()), true);
if (nodeInstances.isEmpty()) {
return ((NodeInstanceContainer) getNodeInstance((Node) nodeContainer)).getNodeInstance(node);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<T>) process.instances()).update(pi.id(), pi));
}
Expand Down

0 comments on commit 6ba74e0

Please sign in to comment.