Skip to content

Commit

Permalink
RHPAM-4822 find EventNode by unique id
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Fanjul committed Oct 16, 2023
1 parent 175e6b9 commit 0b32cf4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
4 changes: 4 additions & 0 deletions jbpm-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-services-api</artifactId>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,14 @@ public void reconnect() {
super.reconnect();
for (NodeInstance nodeInstance : nodeInstances) {
if (nodeInstance instanceof EventBasedNodeInstanceInterface) {
((EventBasedNodeInstanceInterface) nodeInstance)
.addEventListeners();
}
try {
((EventBasedNodeInstanceInterface) nodeInstance)
.addEventListeners();
} catch (ClassCastException e) {
logger.debug("node definition changed for process instance "+getId()+"Looking for EventNode on"+nodeInstance.getId());
throw e;
}
}
}
registerExternalEventNodeListeners();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.Collection;

import org.jbpm.process.core.context.variable.VariableScope;
import org.jbpm.process.core.event.EventTransformer;
Expand All @@ -31,13 +32,22 @@
import org.jbpm.process.instance.context.variable.VariableScopeInstance;
import org.jbpm.process.instance.timer.TimerInstance;
import org.jbpm.process.instance.timer.TimerManager;
import org.jbpm.ruleflow.core.RuleFlowProcess;
import org.jbpm.services.api.RuntimeDataService;
import org.jbpm.services.api.model.NodeInstanceDesc;
import org.jbpm.services.api.service.ServiceRegistry;
import org.jbpm.util.PatternConstants;
import org.jbpm.workflow.core.NodeContainer;
import org.jbpm.workflow.core.node.EventNode;
import org.jbpm.workflow.instance.WorkflowProcessInstance;
import org.jbpm.workflow.instance.impl.ExtendedNodeInstanceImpl;
import org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl;
import org.kie.api.definition.process.Node;
import org.kie.api.runtime.process.EventListener;
import org.kie.api.runtime.process.NodeInstance;
import org.kie.api.runtime.process.NodeInstanceContainer;
import org.kie.api.runtime.query.QueryContext;
import org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode;
import org.mvel2.MVEL;

import static org.jbpm.workflow.instance.impl.DummyEventListener.EMPTY_EVENT_LISTENER;
Expand Down Expand Up @@ -141,7 +151,42 @@ public void removeTimerListeners() {
}

public EventNode getEventNode() {
return (EventNode) getNode();
EventNode node;
try {
node = (EventNode) getNode();
} catch (ClassCastException e) {
long id = getProcessInstance().getId();
long nodeInstanceId = getId();
node = (EventNode)getNodeByNodeInstanceId(id, nodeInstanceId);
if (node == null) {
throw e;
}
}
return node;
}

/**
* Search node by nodeinstanceid and uniqueId, cause node definition id might change
* @param id
* @param nodeInstanceId
* @return
*/
private Node getNodeByNodeInstanceId(long id, long nodeInstanceId) {
Node node = null;
RuntimeDataService service = (RuntimeDataService) ServiceRegistry.get().service(ServiceRegistry.RUNTIME_DATA_SERVICE);
Collection<NodeInstanceDesc> nodes = service.getProcessInstanceFullHistory(id, new QueryContext(0, 999));
for (NodeInstanceDesc nodeInstanceDesc : nodes) {
if (nodeInstanceId == nodeInstanceDesc.getId()) {
String uniqueId = nodeInstanceDesc.getNodeId();
org.jbpm.workflow.instance.NodeInstanceContainer nodeInstanceContainer = (org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer();
Node nodeByUniqueId = nodeInstanceContainer.getNodeContainer().getNodeByUniqueId(uniqueId);
if (nodeByUniqueId != null) {
node = nodeByUniqueId;
}
break;
}
}
return node;
}

public void triggerCompleted() {
Expand Down

0 comments on commit 0b32cf4

Please sign in to comment.