From a0fcac344fb6dd4a18d59d987ca48eec4fcde7af Mon Sep 17 00:00:00 2001 From: Alberto Fanjul Date: Tue, 17 Oct 2023 10:07:19 +0200 Subject: [PATCH] [RHPAM-4822] Specific query to find node by unique id --- .../instance/node/EventNodeInstance.java | 19 +++++------ .../services/impl/RuntimeDataServiceImpl.java | 13 ++++++++ .../main/resources/META-INF/Servicesorm.xml | 32 ++++++++++++++++++- .../src/build/revapi-config.json | 9 ++++++ .../jbpm/services/api/RuntimeDataService.java | 11 +++++++ 5 files changed, 72 insertions(+), 12 deletions(-) diff --git a/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/EventNodeInstance.java b/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/EventNodeInstance.java index 8ac0079c3b..c33018a001 100644 --- a/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/EventNodeInstance.java +++ b/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/EventNodeInstance.java @@ -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 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 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; diff --git a/jbpm-services/jbpm-kie-services/src/main/java/org/jbpm/kie/services/impl/RuntimeDataServiceImpl.java b/jbpm-services/jbpm-kie-services/src/main/java/org/jbpm/kie/services/impl/RuntimeDataServiceImpl.java index 584ac48af2..e208591f8a 100644 --- a/jbpm-services/jbpm-kie-services/src/main/java/org/jbpm/kie/services/impl/RuntimeDataServiceImpl.java +++ b/jbpm-services/jbpm-kie-services/src/main/java/org/jbpm/kie/services/impl/RuntimeDataServiceImpl.java @@ -718,6 +718,19 @@ protected Collection getProcessInstanceHistory(long processId, return nodeInstances; } + @Override + public Collection getProcessInstanceNodeInstanceHistory(long processId, long nodeInstanceId, QueryContext queryContext) { + Map params = new HashMap(); + params.put("processId", processId); + params.put("nodeInstanceId", String.valueOf(nodeInstanceId)); + applyQueryContext(params, queryContext); + List nodeInstances = commandService.execute( + new QueryNameCommand>("getProcessInstanceNodeInstanceHistory", + params)); + + return nodeInstances; + } + @Override public Collection getProcessInstanceFullHistory(long processId, QueryContext queryContext) { Map params = new HashMap(); diff --git a/jbpm-services/jbpm-kie-services/src/main/resources/META-INF/Servicesorm.xml b/jbpm-services/jbpm-kie-services/src/main/resources/META-INF/Servicesorm.xml index 35f5d80d65..250706fdd9 100644 --- a/jbpm-services/jbpm-kie-services/src/main/resources/META-INF/Servicesorm.xml +++ b/jbpm-services/jbpm-kie-services/src/main/resources/META-INF/Servicesorm.xml @@ -471,7 +471,37 @@ and log.parentProcessInstanceId IN :parentsId - + + + + + 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 + + + diff --git a/jbpm-services/jbpm-services-api/src/build/revapi-config.json b/jbpm-services/jbpm-services-api/src/build/revapi-config.json index 411d76dd26..084d8bbf5d 100644 --- a/jbpm-services/jbpm-services-api/src/build/revapi-config.json +++ b/jbpm-services/jbpm-services-api/src/build/revapi-config.json @@ -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.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" } ] } diff --git a/jbpm-services/jbpm-services-api/src/main/java/org/jbpm/services/api/RuntimeDataService.java b/jbpm-services/jbpm-services-api/src/main/java/org/jbpm/services/api/RuntimeDataService.java index bc729aeb82..53eac77218 100644 --- a/jbpm-services/jbpm-services-api/src/main/java/org/jbpm/services/api/RuntimeDataService.java +++ b/jbpm-services/jbpm-services-api/src/main/java/org/jbpm/services/api/RuntimeDataService.java @@ -255,6 +255,17 @@ public int getValue() { */ Collection 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 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.