This is an automated email from the ASF dual-hosted git repository.

mweiler pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-kogito-apps.git


The following commit(s) were added to refs/heads/main by this push:
     new c3e9feae7 [incubator-kie-issues#2144] Data Index Addon: make 
ProcessInstances timers dataFetcher be a read only operation (#2273)
c3e9feae7 is described below

commit c3e9feae728b5b92ada519d261ea43c695448d4d
Author: Pere Fernández <[email protected]>
AuthorDate: Wed Oct 15 16:12:55 2025 +0200

    [incubator-kie-issues#2144] Data Index Addon: make ProcessInstances timers 
dataFetcher be a read only operation (#2273)
---
 .../index/addon/api/KogitoAddonRuntimeClient.java  | 22 +++++-
 .../api/KogitoAddonRuntimeClientImplTest.java      | 89 +++++++++++++++++++++-
 .../main/resources/META-INF/quarkus-extension.yaml |  4 +-
 3 files changed, 106 insertions(+), 9 deletions(-)

diff --git 
a/data-index/data-index-common-addons/src/main/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClient.java
 
b/data-index/data-index-common-addons/src/main/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClient.java
index 5d260236b..2d7146246 100644
--- 
a/data-index/data-index-common-addons/src/main/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClient.java
+++ 
b/data-index/data-index-common-addons/src/main/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClient.java
@@ -202,15 +202,29 @@ public class KogitoAddonRuntimeClient extends 
KogitoRuntimeCommonClient implemen
 
     @Override
     public CompletableFuture<List<Timer>> getProcessInstanceTimers(String 
serviceUrl, ProcessInstance processInstance) {
-        return 
CompletableFuture.completedFuture(executeOnProcessInstance(processInstance.getProcessId(),
 processInstance.getId(), pInstance -> {
+
+        Process<?> process = processes != null ? 
processes.processById(processInstance.getProcessId()) : null;
+
+        if (process == null) {
+            throw new DataIndexServiceException(
+                    String.format("Cannot get timers for process instance 
'%s': process with id '%s' cannot be found", processInstance.getId(), 
processInstance.getProcessId()));
+        }
+
+        Optional<? extends org.kie.kogito.process.ProcessInstance<?>> 
foundProcessInstanceOptional = 
process.instances().findById(processInstance.getId());
+        if (foundProcessInstanceOptional.isPresent()) {
+            org.kie.kogito.process.ProcessInstance<?> foundProcessInstance = 
foundProcessInstanceOptional.get();
             try {
-                return pInstance.timers().stream()
+                List<Timer> timers = foundProcessInstance.timers().stream()
                         .map(Timer::from)
                         .toList();
+                return CompletableFuture.completedFuture(timers);
             } catch (Exception ex) {
-                throw new DataIndexServiceException("Failure getting timers 
for process instance " + pInstance.id(), ex);
+                throw new DataIndexServiceException(String.format("Failure 
getting timers for process instance '%s'", processInstance.getId()), ex);
             }
-        }));
+        } else {
+            throw new DataIndexServiceException(
+                    String.format("Cannot get timers for process instance 
'%s': instance cannot be found in process '%s'", processInstance.getId(), 
processInstance.getProcessId()));
+        }
     }
 
     private static Map<String, String> 
mapMetadata(org.kie.api.definition.process.Node n) {
diff --git 
a/data-index/data-index-quarkus/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/test/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImplTest.java
 
b/data-index/data-index-quarkus/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/test/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImplTest.java
index 769c7c173..8a9fa8738 100644
--- 
a/data-index/data-index-quarkus/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/test/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImplTest.java
+++ 
b/data-index/data-index-quarkus/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/test/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImplTest.java
@@ -19,12 +19,11 @@
 package org.kie.kogito.index.addon.api;
 
 import java.nio.Buffer;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
 import java.util.concurrent.CompletableFuture;
 
 import org.eclipse.microprofile.context.ManagedExecutor;
+import org.jbpm.workflow.instance.WorkflowProcessInstance;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
@@ -32,11 +31,13 @@ import org.kie.kogito.Application;
 import org.kie.kogito.index.addon.api.models.TestModel;
 import org.kie.kogito.index.api.ExecuteArgs;
 import org.kie.kogito.index.model.*;
+import org.kie.kogito.index.model.Timer;
 import org.kie.kogito.index.service.DataIndexServiceException;
 import org.kie.kogito.index.service.KogitoRuntimeCommonClient;
 import org.kie.kogito.index.service.auth.DataIndexAuthTokenReader;
 import org.kie.kogito.index.test.TestUtils;
 import org.kie.kogito.jackson.utils.ObjectMapperFactory;
+import org.kie.kogito.jobs.TimerDescription;
 import org.kie.kogito.process.ProcessError;
 import org.kie.kogito.process.ProcessInstanceExecutionException;
 import org.kie.kogito.process.ProcessInstances;
@@ -166,6 +167,88 @@ public class KogitoAddonRuntimeClientImplTest {
         }).when(error);
     }
 
+    @Test
+    public void testGetProcessInstanceTimers() throws Exception {
+        ProcessInstance pI = createProcessInstance(PROCESS_INSTANCE_ID, 
ACTIVE);
+
+        WorkflowProcessInstance workflowProcessInstance = 
mock(WorkflowProcessInstance.class);
+        
when(workflowProcessInstance.getProcessId()).thenReturn(pI.getProcessId());
+        when(workflowProcessInstance.getId()).thenReturn(pI.getId());
+
+        List<TimerDescription> timers = new ArrayList<>();
+        timers.add(TimerDescription.Builder
+                .ofProcessInstance(workflowProcessInstance)
+                .timerId("timerId")
+                .timerDescription("SLA")
+                .build());
+
+        when(processInstance.timers()).thenReturn(timers);
+
+        CompletableFuture<List<Timer>> result = 
client.getProcessInstanceTimers(SERVICE_URL, pI);
+
+        verify(processes, times(1)).processById(anyString());
+        verify(instances, times(1)).findById(anyString());
+        verify(processInstance, times(1)).timers();
+
+        assertThat(result).isNotNull()
+                .isDone();
+
+        assertThat(result.get())
+                .hasSize(1)
+                .element(0)
+                .hasFieldOrPropertyWithValue("processId", pI.getProcessId())
+                .hasFieldOrPropertyWithValue("processInstanceId", pI.getId())
+                .hasFieldOrPropertyWithValue("timerId", "timerId")
+                .hasFieldOrPropertyWithValue("description", "SLA");
+    }
+
+    @Test
+    public void testGetProcessInstanceTimersErrorWithWrongProcessId() {
+        ProcessInstance pI = createProcessInstance(PROCESS_INSTANCE_ID, 
ACTIVE);
+
+        when(processes.processById(anyString())).thenReturn(null);
+
+        assertThatThrownBy(() -> client.getProcessInstanceTimers(SERVICE_URL, 
pI))
+                .isInstanceOf(DataIndexServiceException.class)
+                .hasMessage("Cannot get timers for process instance 'pId': 
process with id 'travels' cannot be found");
+
+        verify(processes, times(1)).processById(anyString());
+        verify(instances, never()).findById(anyString());
+        verify(processInstance, never()).timers();
+    }
+
+    @Test
+    public void testGetProcessInstanceTimersErrorWithWrongProcessInstanceId() {
+        ProcessInstance pI = createProcessInstance(PROCESS_INSTANCE_ID, 
ACTIVE);
+
+        when(instances.findById(anyString())).thenReturn(Optional.empty());
+
+        assertThatThrownBy(() -> client.getProcessInstanceTimers(SERVICE_URL, 
pI))
+                .isInstanceOf(DataIndexServiceException.class)
+                .hasMessage("Cannot get timers for process instance 'pId': 
instance cannot be found in process 'travels'");
+
+        verify(processes, times(1)).processById(anyString());
+        verify(instances, times(1)).findById(anyString());
+        verify(processInstance, never()).timers();
+    }
+
+    @Test
+    public void 
testGetProcessInstanceTimersErrorWithUnexpectedErrorGettingTimers() {
+        ProcessInstance pI = createProcessInstance(PROCESS_INSTANCE_ID, 
ACTIVE);
+
+        when(processInstance.timers()).thenThrow(new 
RuntimeException("Something went wrong"));
+
+        assertThatThrownBy(() -> client.getProcessInstanceTimers(SERVICE_URL, 
pI))
+                .isInstanceOf(DataIndexServiceException.class)
+                .hasMessage("Failure getting timers for process instance 
'pId'")
+                .hasRootCauseInstanceOf(RuntimeException.class)
+                .hasRootCauseMessage("Something went wrong");
+
+        verify(processes, times(1)).processById(anyString());
+        verify(instances, times(1)).findById(anyString());
+        verify(processInstance, times(1)).timers();
+    }
+
     @Test
     void testExecuteAfterSuccess() {
         ProcessDefinition definition = new ProcessDefinition();
diff --git 
a/data-index/data-index-quarkus/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-jpa/runtime/src/main/resources/META-INF/quarkus-extension.yaml
 
b/data-index/data-index-quarkus/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-jpa/runtime/src/main/resources/META-INF/quarkus-extension.yaml
index 4086152b7..21441f556 100644
--- 
a/data-index/data-index-quarkus/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-jpa/runtime/src/main/resources/META-INF/quarkus-extension.yaml
+++ 
b/data-index/data-index-quarkus/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-jpa/runtime/src/main/resources/META-INF/quarkus-extension.yaml
@@ -17,7 +17,7 @@
 # under the License.
 #
 
-name: Kogito Data Index PostgreSQL Quarkus Add-On
+name: Kogito Data Index JPA Quarkus Add-On
 description: Runs the Kogito Data Index embedded with JPA persistence
 metadata:
   keywords:
@@ -28,7 +28,7 @@ metadata:
     - tasks
     - jobs
     - BPMN
-    - postgresql
+    - JPA
   guide: https://quarkus.io/guides/kogito
   categories:
     - "business-automation"


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to