From 6ea8110499d59bd9608661cf98002c5ed8ec2651 Mon Sep 17 00:00:00 2001 From: Christoph Oesterheld Date: Tue, 26 Nov 2024 18:05:03 +0100 Subject: [PATCH 1/2] fix(user-task): prevent npe for non-tenant configurations (#67) --- .../vanillabp/camunda8/wiring/Camunda8TaskWiring.java | 5 ++--- .../camunda8/wiring/Camunda8UserTaskHandler.java | 10 +++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/spring-boot/src/main/java/io/vanillabp/camunda8/wiring/Camunda8TaskWiring.java b/spring-boot/src/main/java/io/vanillabp/camunda8/wiring/Camunda8TaskWiring.java index 9a73652..855f4bc 100644 --- a/spring-boot/src/main/java/io/vanillabp/camunda8/wiring/Camunda8TaskWiring.java +++ b/spring-boot/src/main/java/io/vanillabp/camunda8/wiring/Camunda8TaskWiring.java @@ -113,11 +113,10 @@ public void openWorkers() { .jobType("io.camunda.zeebe:userTask") .handler(userTaskHandler) .timeout(Integer.MAX_VALUE) // user-tasks are not fetched more than once - .name(workerId) - .tenantId(tenantId); + .name(workerId); final var workerProperties = camunda8Properties.getUserTaskWorkerProperties(workflowModuleId); workerProperties.applyToUserTaskWorker(userTaskWorker); - return userTaskWorker; + return tenantId != null ? userTaskWorker.tenantId(tenantId) : userTaskWorker; }) .forEach(workers::add); diff --git a/spring-boot/src/main/java/io/vanillabp/camunda8/wiring/Camunda8UserTaskHandler.java b/spring-boot/src/main/java/io/vanillabp/camunda8/wiring/Camunda8UserTaskHandler.java index c75b2a9..b792808 100644 --- a/spring-boot/src/main/java/io/vanillabp/camunda8/wiring/Camunda8UserTaskHandler.java +++ b/spring-boot/src/main/java/io/vanillabp/camunda8/wiring/Camunda8UserTaskHandler.java @@ -15,7 +15,11 @@ public class Camunda8UserTaskHandler implements JobHandler { private static final Logger logger = LoggerFactory.getLogger(Camunda8UserTaskHandler.class); private static final int MAX_ATTEMPTS_OF_ASSIGNING_USERTASKS = 1000; - + + // default tenant identifier used by camunda 8 if multi-tenancy is disabled + // see https://docs.camunda.io/docs/self-managed/concepts/multi-tenancy/#the-tenant-identifier + private static final String DEFAULT_TENANT_ID = ""; + private final Map taskHandlers = new HashMap<>(); private final String workerId; @@ -31,8 +35,8 @@ private String internalKey( final String tenantId, final String bpmnProcessId, final String elementId) { - - return tenantId + "#" + bpmnProcessId + "#" + elementId; + final var tenantIdKey = DEFAULT_TENANT_ID.equals(tenantId) ? null : tenantId; + return tenantIdKey + "#" + bpmnProcessId + "#" + elementId; } From 512d3a5dd2fa760a11412bb9beddce84503259dc Mon Sep 17 00:00:00 2001 From: Christoph Oesterheld Date: Fri, 29 Nov 2024 09:53:36 +0100 Subject: [PATCH 2/2] refactor: define the conditional tenant configuration more explicit --- .../io/vanillabp/camunda8/wiring/Camunda8TaskWiring.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spring-boot/src/main/java/io/vanillabp/camunda8/wiring/Camunda8TaskWiring.java b/spring-boot/src/main/java/io/vanillabp/camunda8/wiring/Camunda8TaskWiring.java index 855f4bc..f50d8db 100644 --- a/spring-boot/src/main/java/io/vanillabp/camunda8/wiring/Camunda8TaskWiring.java +++ b/spring-boot/src/main/java/io/vanillabp/camunda8/wiring/Camunda8TaskWiring.java @@ -114,9 +114,14 @@ public void openWorkers() { .handler(userTaskHandler) .timeout(Integer.MAX_VALUE) // user-tasks are not fetched more than once .name(workerId); + + if (tenantId != null) { + userTaskWorker.tenantId(tenantId); + } + final var workerProperties = camunda8Properties.getUserTaskWorkerProperties(workflowModuleId); workerProperties.applyToUserTaskWorker(userTaskWorker); - return tenantId != null ? userTaskWorker.tenantId(tenantId) : userTaskWorker; + return userTaskWorker; }) .forEach(workers::add);