Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHPAM-4822 find EventNode by unique id #2347

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not correct at all. the engine cannot depend on the services api at all.


</dependencies>

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,41 @@ 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();
logger.debug("node definition changed for process instance "+id+". EventNode not found on node id: "+getNodeId()+" searching with node instance id: "+nodeInstanceId);
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.getProcessInstanceNodeInstanceHistory(id, nodeInstanceId, new QueryContext(0, 1));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incorrect either. the engine should not access the runtime data service. this goes against the design.

if (!nodes.isEmpty ()) {
NodeInstanceDesc nodeInstanceDesc = nodes.iterator().next();
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;
}
}
return node;
}

public void triggerCompleted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,19 @@ protected Collection<NodeInstanceDesc> getProcessInstanceHistory(long processId,
return nodeInstances;
}

@Override
public Collection<NodeInstanceDesc> getProcessInstanceNodeInstanceHistory(long processId, long nodeInstanceId, QueryContext queryContext) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("processId", processId);
params.put("nodeInstanceId", String.valueOf(nodeInstanceId));
applyQueryContext(params, queryContext);
List<NodeInstanceDesc> nodeInstances = commandService.execute(
new QueryNameCommand<List<NodeInstanceDesc>>("getProcessInstanceNodeInstanceHistory",
params));

return nodeInstances;
}

@Override
public Collection<NodeInstanceDesc> getProcessInstanceFullHistory(long processId, QueryContext queryContext) {
Map<String, Object> params = new HashMap<String, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,37 @@
and log.parentProcessInstanceId IN :parentsId
</query>
<!-- hint name="org.hibernate.timeout" value="200"/ -->
</named-query>
</named-query>

<named-query name="getProcessInstanceNodeInstanceHistory">
<query>
select
new org.jbpm.kie.services.impl.model.NodeInstanceDesc(
log.nodeInstanceId,
log.nodeId,
log.nodeName,
log.nodeType,
log.externalId,
log.processInstanceId,
log.date,
log.connection,
log.type,
log.workItemId,
log.referenceId,
log.nodeContainerId,
log.slaDueDate,
log.slaCompliance
)
from
NodeInstanceLog log
where
log.processInstanceId=:processId
AND log.nodeInstanceId=:nodeInstanceId
ORDER BY
log.date DESC, log.id DESC
</query>
<!-- hint name="org.hibernate.timeout" value="200"/ -->
</named-query>

<!-- node instance queries -->

Expand Down
9 changes: 9 additions & 0 deletions jbpm-services/jbpm-services-api/src/build/revapi-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
"methodName": "getProcessInstanceHistoryFinished",
"elementKind": "method",
"justification": "[RHPAM-4653] IntermediateThrowingSignal node from subprocess and the subprocess is not getting marked as executed."
},
{
"code": "java.method.addedToInterface",
"new": "method java.util.Collection<org.jbpm.services.api.model.NodeInstanceDesc> org.jbpm.services.api.RuntimeDataService::getProcessInstanceNodeInstanceHistory(long, long, org.kie.api.runtime.query.QueryContext)",
"package": "org.jbpm.services.api",
"classSimpleName": "RuntimeDataService",
"methodName": "getProcessInstanceNodeInstanceHistory",
"elementKind": "method",
"justification": "[RHPAM-4822] Resolve ClassCastException when bpmn design didn't change"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,17 @@ public int getValue() {
*/
Collection<NodeInstanceDesc> getProcessInstanceHistoryFinished(long processInstanceId, QueryContext queryContext);

/**
* Returns complete trace of all executed (completed) and active nodes for given process instance id
* and node instance id
* @param processInstanceId The id of the process used to start the process instance.
* @param nodeInstanceId The id of the node instance to filter result.
* @param queryContext control parameters for the result e.g. sorting, paging
* @return The {@link NodeInstance} information, in the form of a list of {@link NodeInstanceDesc} instances,
* that comes from a process instance that matches the given criteria (deploymentId, processId).
*/
Collection<NodeInstanceDesc> getProcessInstanceNodeInstanceHistory(long processInstanceId, long nodeInstanceId, QueryContext queryContext);

/**
* Returns complete trace of all executed (completed) and active nodes for given process instance id
* @param processInstanceId The id of the process used to start the process instance.
Expand Down