Skip to content

Commit

Permalink
[RHPAM-4822] Specific query to find node by unique id
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Fanjul committed Oct 17, 2023
1 parent 969e10e commit a0fcac3
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,14 @@ public EventNode getEventNode() {
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();
logger.debug("found UniqueId: " + uniqueId + " for process instance: " + id + " and node instance id: " + nodeInstanceId);
org.jbpm.workflow.instance.NodeInstanceContainer nodeInstanceContainer = (org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer();
Node nodeByUniqueId = nodeInstanceContainer.getNodeContainer().getNodeByUniqueId(uniqueId);
if (nodeByUniqueId != null) {
node = nodeByUniqueId;
}
break;
Collection<NodeInstanceDesc> nodes = service.getProcessInstanceNodeInstanceHistory(id, nodeInstanceId, new QueryContext(0, 1));
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;
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

0 comments on commit a0fcac3

Please sign in to comment.