Changeset 78:729749c49089 default default/master tip master

Updated example for the Camunda Quarkus extension
author unexist
date Mon, 16 Aug 2021 18:19:12 +0200
parents 8e9b37db5564
children
files README.adoc todo-service-camunda-quarkus/pom.xml todo-service-camunda-quarkus/src/main/java/dev/unexist/showcase/todo/adapter/CamundaResource.java todo-service-camunda-quarkus/src/main/java/dev/unexist/showcase/todo/application/.gitkeep todo-service-camunda-quarkus/src/main/java/dev/unexist/showcase/todo/infrastructure/camunda/StartInterceptor.java
diffstat 4 files changed, 54 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/README.adoc	Mon Aug 16 18:13:59 2021 +0200
+++ b/README.adoc	Mon Aug 16 18:19:12 2021 +0200
@@ -14,6 +14,7 @@
 - https://docs.camunda.org/manual/7.15/reference/rest/overview/embeddability/
 - https://camunda.com/blog/2021/03/external-task-client-spring-bootified/
 - https://camunda.com/blog/2021/08/camunda-platform-runtime-7160-alpha4-released/
+- https://github.com/camunda/camunda-bpm-examples/tree/master/quarkus-extension/simple-rest-example
 
 === Kogito
 
--- a/todo-service-camunda-quarkus/pom.xml	Mon Aug 16 18:13:59 2021 +0200
+++ b/todo-service-camunda-quarkus/pom.xml	Mon Aug 16 18:19:12 2021 +0200
@@ -15,7 +15,7 @@
 
     <properties>
         <camunda-bpm-quarkus-engine.version>7.16.0-alpha4</camunda-bpm-quarkus-engine.version>
-        <camunda-spin-dataformat-json-jackson.version>1.9.2</camunda-spin-dataformat-json-jackson.version>
+        <camunda-spin-dataformat-json-jackson.version>1.11.0</camunda-spin-dataformat-json-jackson.version>
     </properties>
 
     <dependencies>
@@ -24,6 +24,14 @@
             <groupId>io.quarkus</groupId>
             <artifactId>quarkus-container-image-jib</artifactId>
         </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-arc</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-jdbc-h2</artifactId>
+        </dependency>
 
         <!-- Camunda -->
         <dependency>
--- a/todo-service-camunda-quarkus/src/main/java/dev/unexist/showcase/todo/adapter/CamundaResource.java	Mon Aug 16 18:13:59 2021 +0200
+++ b/todo-service-camunda-quarkus/src/main/java/dev/unexist/showcase/todo/adapter/CamundaResource.java	Mon Aug 16 18:19:12 2021 +0200
@@ -12,8 +12,8 @@
 package dev.unexist.showcase.todo.adapter;
 
 import dev.unexist.showcase.todo.domain.todo.TodoBase;
-import dev.unexist.showcase.todo.infrastructure.camunda.CamundaEngine;
 import org.camunda.bpm.engine.ProcessEngine;
+import org.camunda.bpm.engine.RepositoryService;
 import org.camunda.bpm.engine.runtime.ProcessInstance;
 import org.camunda.bpm.engine.variable.Variables;
 import org.camunda.bpm.engine.variable.value.ObjectValue;
@@ -40,7 +40,10 @@
     private static final Logger LOGGER = LoggerFactory.getLogger(CamundaResource.class);
 
     @Inject
-    CamundaEngine camundaEngine;
+    RepositoryService camundaRepositoryService;
+
+    @Inject
+    ProcessEngine processEngine;
 
     @POST
     @Consumes(MediaType.APPLICATION_JSON)
@@ -53,14 +56,22 @@
             @APIResponse(responseCode = "500", description = "Server error")
     })
     public Response create(TodoBase base, @Context UriInfo info) {
-        ProcessEngine ProcEngine = this.camundaEngine.getProcessEngine();
+        String deploymentId = camundaRepositoryService.createDeployment()
+                .addClasspathResource("todo.bpmn")
+                .deploy()
+                .getId();
+
+        LOGGER.info("Deployment {} started", deploymentId);
 
-        ObjectValue todoAsJson = Variables.objectValue(base)
-                        .serializationDataFormat("application/json").create();
+        this.camundaRepositoryService.activateProcessDefinitionById("todo");
 
-        ProcessInstance processInstance = ProcEngine.getRuntimeService()
+        ObjectValue objectValue = Variables.objectValue(base)
+                .serializationDataFormat(Variables.SerializationDataFormats.JSON)
+                .create();
+
+        ProcessInstance processInstance = this.processEngine.getRuntimeService()
                 .createProcessInstanceByKey("todo")
-                .setVariable("todo", todoAsJson)
+                .setVariable("todo", objectValue)
                 .executeWithVariablesInReturn();
 
         String id = processInstance.getId();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/todo-service-camunda-quarkus/src/main/java/dev/unexist/showcase/todo/infrastructure/camunda/StartInterceptor.java	Mon Aug 16 18:19:12 2021 +0200
@@ -0,0 +1,26 @@
+/**
+ * @package Showcase
+ *
+ * @file Camunda interceptor
+ * @copyright 2021 Christoph Kappel <christoph@unexist.dev>
+ * @version $Id$
+ *
+ * This program can be distributed under the terms of the Apache License v2.0.
+ * See the file LICENSE for details.
+ **/
+
+package dev.unexist.showcase.todo.infrastructure.camunda;
+
+import org.camunda.bpm.engine.cdi.annotation.StartProcess;
+import org.camunda.bpm.engine.cdi.impl.annotation.StartProcessInterceptor;
+
+import javax.annotation.Priority;
+import javax.enterprise.context.Dependent;
+import javax.interceptor.Interceptor;
+
+@Priority(1)
+@Dependent
+@Interceptor
+@StartProcess
+public class StartInterceptor extends StartProcessInterceptor {
+}
\ No newline at end of file