This is an automated email from the ASF dual-hosted git repository.
tiagobento pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools.git
The following commit(s) were added to refs/heads/main by this push:
new c5049de2f8b [incubator-kie-issues#1970] Make jBPM Quarkus Dev UI
counters not rely on a specific Quarkus profile (#3146)
c5049de2f8b is described below
commit c5049de2f8baf7b1d3241dd3cf3427966478c651
Author: Pere Fernández <[email protected]>
AuthorDate: Mon May 19 23:16:18 2025 +0200
[incubator-kie-issues#1970] Make jBPM Quarkus Dev UI counters not rely on a
specific Quarkus profile (#3146)
---
.../devui/deployment/DevConsoleProcessor.java | 20 +++++-
.../devui/runtime/rpc/JBPMDevUIEventPublisher.java | 79 ---------------------
...PCService.java => JBPMDevUIJsonRPCService.java} | 48 +++++++------
.../rpc/events/JBPMDevUIEventPublisher.java | 56 +++++++++++++++
.../rpc/events/JBPMDevUIEventPublisherTest.java | 81 ++++++++++++++++++++++
5 files changed, 181 insertions(+), 103 deletions(-)
diff --git
a/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-deployment/src/main/java/org/jbpm/quarkus/devui/deployment/DevConsoleProcessor.java
b/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-deployment/src/main/java/org/jbpm/quarkus/devui/deployment/DevConsoleProcessor.java
index 23972b4b73b..056d7439f75 100644
---
a/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-deployment/src/main/java/org/jbpm/quarkus/devui/deployment/DevConsoleProcessor.java
+++
b/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-deployment/src/main/java/org/jbpm/quarkus/devui/deployment/DevConsoleProcessor.java
@@ -27,12 +27,16 @@ import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
+import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
+import jakarta.enterprise.context.ApplicationScoped;
import org.eclipse.microprofile.config.ConfigProvider;
+import org.jboss.jandex.DotName;
+import org.jbpm.quarkus.devui.runtime.rpc.events.JBPMDevUIEventPublisher;
import
org.kie.kogito.quarkus.extensions.spi.deployment.KogitoDataIndexServiceAvailableBuildItem;
import org.jbpm.quarkus.devui.deployment.data.UserInfo;
import org.jbpm.quarkus.devui.runtime.config.DevConsoleRuntimeConfig;
import org.jbpm.quarkus.devui.runtime.config.DevUIStaticArtifactsRecorder;
-import org.jbpm.quarkus.devui.runtime.rpc.JBPMDevuiJsonRPCService;
+import org.jbpm.quarkus.devui.runtime.rpc.JBPMDevUIJsonRPCService;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.IsDevelopment;
@@ -96,8 +100,18 @@ public class DevConsoleProcessor {
}
@BuildStep(onlyIf = IsDevelopment.class)
- public JsonRPCProvidersBuildItem createJsonRPCServiceForJBPMDevUi() {
- return new JsonRPCProvidersBuildItem(JBPMDevuiJsonRPCService.class);
+ public JsonRPCProvidersBuildItem
createJsonRPCServiceForJBPMDevUi(BuildProducer<AdditionalBeanBuildItem>
beanBuildItemBuildProducer) {
+
+ // Adding JBPMDevUIEventPublisher to the CDI container only in DEV mode
+ AdditionalBeanBuildItem jBPMDevUIEventPublisherBean =
AdditionalBeanBuildItem.builder()
+ .addBeanClasses(JBPMDevUIEventPublisher.class)
+
.setDefaultScope(DotName.createSimple(ApplicationScoped.class.getName()))
+ .setRemovable()
+ .build();
+
+ beanBuildItemBuildProducer.produce(jBPMDevUIEventPublisherBean);
+
+ return new JsonRPCProvidersBuildItem(JBPMDevUIJsonRPCService.class);
}
@BuildStep(onlyIf = IsDevelopment.class)
diff --git
a/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-runtime/src/main/java/org/jbpm/quarkus/devui/runtime/rpc/JBPMDevUIEventPublisher.java
b/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-runtime/src/main/java/org/jbpm/quarkus/devui/runtime/rpc/JBPMDevUIEventPublisher.java
deleted file mode 100644
index 399274f3540..00000000000
---
a/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-runtime/src/main/java/org/jbpm/quarkus/devui/runtime/rpc/JBPMDevUIEventPublisher.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.jbpm.quarkus.devui.runtime.rpc;
-
-import jakarta.enterprise.context.ApplicationScoped;
-import jakarta.enterprise.inject.Default;
-
-import org.kie.kogito.event.DataEvent;
-import org.kie.kogito.event.EventPublisher;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import io.quarkus.arc.profile.IfBuildProfile;
-
-import java.util.Collection;
-import java.util.Objects;
-@ApplicationScoped
-@IfBuildProfile("dev")
-public class JBPMDevUIEventPublisher implements EventPublisher {
-
- private Runnable onProcessEvent;
- private Runnable onTaskEvent;
- private Runnable onJobEvent;
-
- @Override
- public void publish(DataEvent<?> event) {
- switch (event.getType()) {
- case "ProcessInstanceStateDataEvent":
- maybeRun(onProcessEvent);
- break;
- case "UserTaskInstanceStateDataEvent":
- maybeRun(onTaskEvent);
- break;
- case "JobEvent":
- maybeRun(onJobEvent);
- break;
- }
- }
-
- @Override
- public void publish(Collection<DataEvent<?>> events) {
- events.forEach(this::publish);
- }
-
- private void maybeRun(Runnable runnable) {
- if (Objects.nonNull(runnable)) {
- runnable.run();
- }
- }
-
- public void setOnProcessEventListener(Runnable onProcessEvent) {
- this.onProcessEvent = onProcessEvent;
- }
-
- public void setOnTaskEventListener(Runnable onTaskEvent) {
- this.onTaskEvent = onTaskEvent;
- }
-
- public void setOnJobEventListener(Runnable onJobEvent) {
- this.onJobEvent = onJobEvent;
- }
-}
\ No newline at end of file
diff --git
a/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-runtime/src/main/java/org/jbpm/quarkus/devui/runtime/rpc/JBPMDevuiJsonRPCService.java
b/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-runtime/src/main/java/org/jbpm/quarkus/devui/runtime/rpc/JBPMDevUIJsonRPCService.java
similarity index 72%
rename from
packages/jbpm-quarkus-devui/jbpm-quarkus-devui-runtime/src/main/java/org/jbpm/quarkus/devui/runtime/rpc/JBPMDevuiJsonRPCService.java
rename to
packages/jbpm-quarkus-devui/jbpm-quarkus-devui-runtime/src/main/java/org/jbpm/quarkus/devui/runtime/rpc/JBPMDevUIJsonRPCService.java
index 287e5629549..b17260436c8 100644
---
a/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-runtime/src/main/java/org/jbpm/quarkus/devui/runtime/rpc/JBPMDevuiJsonRPCService.java
+++
b/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-runtime/src/main/java/org/jbpm/quarkus/devui/runtime/rpc/JBPMDevUIJsonRPCService.java
@@ -23,29 +23,33 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.Optional;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.jbpm.quarkus.devui.runtime.forms.FormsStorage;
+import org.jbpm.quarkus.devui.runtime.rpc.events.JBPMDevUIEventPublisher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import io.smallrye.mutiny.Uni;
-import io.quarkus.arc.profile.IfBuildProfile;
import io.smallrye.mutiny.Multi;
import io.vertx.core.Vertx;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.client.WebClientOptions;
+
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
-
-import org.eclipse.microprofile.config.ConfigProvider;
-import org.jbpm.quarkus.devui.runtime.forms.FormsStorage;
-
import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+import static
org.jbpm.quarkus.devui.runtime.rpc.events.JBPMDevUIEventPublisher.JOB_EVENT;
+import static
org.jbpm.quarkus.devui.runtime.rpc.events.JBPMDevUIEventPublisher.PROCESS_INSTANCE_STATE_DATA_EVENT;
+import static
org.jbpm.quarkus.devui.runtime.rpc.events.JBPMDevUIEventPublisher.USER_TASK_INSTANCE_STATE_DATA_EVENT;
@ApplicationScoped
-@IfBuildProfile("dev")
-public class JBPMDevuiJsonRPCService {
+public class JBPMDevUIJsonRPCService {
private static final String DATA_INDEX_URL = "kogito.data-index.url";
- private static final Logger LOGGER =
LoggerFactory.getLogger(JBPMDevuiJsonRPCService.class);
+ private static final Logger LOGGER =
LoggerFactory.getLogger(JBPMDevUIJsonRPCService.class);
public static final String PROCESS_INSTANCES = "ProcessInstances";
public static final String USER_TASKS = "UserTaskInstances";
@@ -55,32 +59,32 @@ public class JBPMDevuiJsonRPCService {
public static final String ALL_PROCESS_INSTANCES_IDS_QUERY = "{
\"operationName\": \"getAllProcessesIds\", \"query\": \"query
getAllProcessesIds{ ProcessInstances{ id } }\" }";
public static final String ALL_JOBS_IDS_QUERY = "{ \"operationName\":
\"getAllJobsIds\", \"query\": \"query getAllJobsIds{ Jobs{ id } }\" }";
- private WebClient dataIndexWebClient;
-
private final Vertx vertx;
- private final JBPMDevUIEventPublisher eventPublisher;
+ private final JBPMDevUIEventPublisher jbpmDevUIEventPublisher;
private final FormsStorage formsStorage;
+
private DataIndexCounter processesCounter;
private DataIndexCounter tasksCounter;
private DataIndexCounter jobsCounter;
@Inject
- public JBPMDevuiJsonRPCService(Vertx vertx, JBPMDevUIEventPublisher
eventPublisher, FormsStorage formsStorage) {
+ public JBPMDevUIJsonRPCService(Vertx vertx,
Instance<JBPMDevUIEventPublisher> jbpmDevUIEventPublishers, FormsStorage
formsStorage) {
this.vertx = vertx;
- this.eventPublisher = eventPublisher;
+ this.jbpmDevUIEventPublisher = jbpmDevUIEventPublishers.get(); // We
can rely on JBPMDevUIEventPublisher will be resolved since both beans are only
available in DEV Mode.
this.formsStorage = formsStorage;
}
@PostConstruct
public void init() {
Optional<String> dataIndexURL =
ConfigProvider.getConfig().getOptionalValue(DATA_INDEX_URL, String.class);
- dataIndexURL.ifPresent(this::initDataIndexWebClient);
+ String dataIndexUrl = dataIndexURL.orElseThrow(() -> new
RuntimeException("Cannot initialize JBPMDevUIJsonRPCService, '" +
DATA_INDEX_URL + "' is not configured"));
+ initCounters(dataIndexUrl);
}
- private void initDataIndexWebClient(String dataIndexURL) {
+ private void initCounters(String dataIndexURL) {
try {
URL url = new URL(dataIndexURL);
- this.dataIndexWebClient = WebClient.create(vertx,
buildWebClientOptions(url));
+ WebClient dataIndexWebClient = WebClient.create(vertx,
buildWebClientOptions(url));
String contextPath = url.getPath();
this.processesCounter = new
DataIndexCounter(ALL_PROCESS_INSTANCES_IDS_QUERY, PROCESS_INSTANCES,
@@ -88,11 +92,12 @@ public class JBPMDevuiJsonRPCService {
this.tasksCounter = new DataIndexCounter(ALL_TASKS_IDS_QUERY,
USER_TASKS, contextPath, vertx, dataIndexWebClient);
this.jobsCounter = new DataIndexCounter(ALL_JOBS_IDS_QUERY, JOBS,
contextPath, vertx, dataIndexWebClient);
-
this.eventPublisher.setOnProcessEventListener(processesCounter::refresh);
- this.eventPublisher.setOnTaskEventListener(tasksCounter::refresh);
- this.eventPublisher.setOnJobEventListener(jobsCounter::refresh);
+
jbpmDevUIEventPublisher.registerListener(PROCESS_INSTANCE_STATE_DATA_EVENT,
processesCounter::refresh);
+
jbpmDevUIEventPublisher.registerListener(USER_TASK_INSTANCE_STATE_DATA_EVENT,
tasksCounter::refresh);
+ jbpmDevUIEventPublisher.registerListener(JOB_EVENT,
jobsCounter::refresh);
} catch (Exception ex) {
LOGGER.warn("Cannot configure dataIndexWebClient with
'kogito.data-index.url'='{}':", dataIndexURL, ex);
+ throw new RuntimeException(ex);
}
}
@@ -121,6 +126,7 @@ public class JBPMDevuiJsonRPCService {
@PreDestroy
public void destroy() {
+ jbpmDevUIEventPublisher.clear();
processesCounter.stop();
tasksCounter.stop();
jobsCounter.stop();
diff --git
a/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-runtime/src/main/java/org/jbpm/quarkus/devui/runtime/rpc/events/JBPMDevUIEventPublisher.java
b/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-runtime/src/main/java/org/jbpm/quarkus/devui/runtime/rpc/events/JBPMDevUIEventPublisher.java
new file mode 100644
index 00000000000..a7d94b98a89
--- /dev/null
+++
b/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-runtime/src/main/java/org/jbpm/quarkus/devui/runtime/rpc/events/JBPMDevUIEventPublisher.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.jbpm.quarkus.devui.runtime.rpc.events;
+
+import org.kie.kogito.event.DataEvent;
+import org.kie.kogito.event.EventPublisher;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import static java.util.Optional.ofNullable;
+
+public class JBPMDevUIEventPublisher implements EventPublisher {
+
+ public static final String PROCESS_INSTANCE_STATE_DATA_EVENT =
"ProcessInstanceStateDataEvent";
+ public static final String USER_TASK_INSTANCE_STATE_DATA_EVENT =
"UserTaskInstanceStateDataEvent";
+ public static final String JOB_EVENT = "JobEvent";
+
+ private final Map<String, Runnable> listeners = new HashMap<>();
+
+ public void registerListener(String eventType, Runnable listener) {
+ listeners.put(eventType, listener);
+ }
+
+ public void clear() {
+ this.listeners.clear();
+ }
+
+ @Override
+ public void publish(DataEvent<?> event) {
+ ofNullable(listeners.get(event.getType())).ifPresent(Runnable::run);
+ }
+
+ @Override
+ public void publish(Collection<DataEvent<?>> events) {
+ events.forEach(this::publish);
+ }
+}
diff --git
a/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-runtime/src/test/java/org/jbpm/quarkus/devui/runtime/rpc/events/JBPMDevUIEventPublisherTest.java
b/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-runtime/src/test/java/org/jbpm/quarkus/devui/runtime/rpc/events/JBPMDevUIEventPublisherTest.java
new file mode 100644
index 00000000000..60200df5c6c
--- /dev/null
+++
b/packages/jbpm-quarkus-devui/jbpm-quarkus-devui-runtime/src/test/java/org/jbpm/quarkus/devui/runtime/rpc/events/JBPMDevUIEventPublisherTest.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.jbpm.quarkus.devui.runtime.rpc.events;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.kogito.event.DataEvent;
+
+import static
org.jbpm.quarkus.devui.runtime.rpc.events.JBPMDevUIEventPublisher.JOB_EVENT;
+import static
org.jbpm.quarkus.devui.runtime.rpc.events.JBPMDevUIEventPublisher.PROCESS_INSTANCE_STATE_DATA_EVENT;
+import static
org.jbpm.quarkus.devui.runtime.rpc.events.JBPMDevUIEventPublisher.USER_TASK_INSTANCE_STATE_DATA_EVENT;
+
+import static org.mockito.Mockito.*;
+
+public class JBPMDevUIEventPublisherTest {
+
+ private Runnable processEventListener;
+ private Runnable taskEventListener;
+ private Runnable jobEventListener;
+
+ private JBPMDevUIEventPublisher eventsPublisher;
+
+ @BeforeEach
+ public void init() {
+ processEventListener = mock(Runnable.class);
+ taskEventListener = mock(Runnable.class);
+ jobEventListener = mock(Runnable.class);
+
+ eventsPublisher = new JBPMDevUIEventPublisher();
+ eventsPublisher.registerListener(PROCESS_INSTANCE_STATE_DATA_EVENT,
processEventListener);
+ eventsPublisher.registerListener(USER_TASK_INSTANCE_STATE_DATA_EVENT,
taskEventListener);
+ eventsPublisher.registerListener(JOB_EVENT, jobEventListener);
+ }
+
+ @Test
+ public void onProcessStateEvent() {
+
eventsPublisher.publish(mockKogitoDataEvent(PROCESS_INSTANCE_STATE_DATA_EVENT));
+ verify(processEventListener, times(1)).run();
+ verify(taskEventListener, never()).run();
+ verify(jobEventListener, never()).run();
+ }
+
+ @Test
+ public void onTaskStateEvent() {
+
eventsPublisher.publish(mockKogitoDataEvent(USER_TASK_INSTANCE_STATE_DATA_EVENT));
+ verify(processEventListener, never()).run();
+ verify(taskEventListener, times(1)).run();
+ verify(jobEventListener, never()).run();
+ }
+
+ @Test
+ public void onJobEvent() {
+ eventsPublisher.publish(mockKogitoDataEvent(JOB_EVENT));
+ verify(processEventListener, never()).run();
+ verify(taskEventListener, never()).run();
+ verify(jobEventListener, times(1)).run();
+ }
+
+ private DataEvent<?> mockKogitoDataEvent(String eventType) {
+ DataEvent<?> event = mock(DataEvent.class);
+ when(event.getType()).thenReturn(eventType);
+ return event;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]