From bc2f9762bd41b6246e5154f82b1829f7e31f9cb3 Mon Sep 17 00:00:00 2001 From: Stephan Pelikan Date: Tue, 17 Dec 2024 16:40:38 +0100 Subject: [PATCH] Use decimal values for task ids instead of hex values (#69) --- .../Camunda8AdapterConfiguration.java | 3 +- .../camunda8/Camunda8VanillaBpProperties.java | 38 +++++++++++++++---- .../service/Camunda8ProcessService.java | 17 +++++++-- .../camunda8/wiring/Camunda8TaskHandler.java | 10 ++++- 4 files changed, 54 insertions(+), 14 deletions(-) diff --git a/spring-boot/src/main/java/io/vanillabp/camunda8/Camunda8AdapterConfiguration.java b/spring-boot/src/main/java/io/vanillabp/camunda8/Camunda8AdapterConfiguration.java index 1110752..5e803dc 100644 --- a/spring-boot/src/main/java/io/vanillabp/camunda8/Camunda8AdapterConfiguration.java +++ b/spring-boot/src/main/java/io/vanillabp/camunda8/Camunda8AdapterConfiguration.java @@ -171,7 +171,8 @@ public Camunda8TaskHandler camunda8TaskHandler( idPropertyName, tenantId, workflowModuleId, - bpmnProcessId); + bpmnProcessId, + camunda8Properties.isTaskIdAsHexString(workflowModuleId)); } diff --git a/spring-boot/src/main/java/io/vanillabp/camunda8/Camunda8VanillaBpProperties.java b/spring-boot/src/main/java/io/vanillabp/camunda8/Camunda8VanillaBpProperties.java index e5b03de..aea72a8 100644 --- a/spring-boot/src/main/java/io/vanillabp/camunda8/Camunda8VanillaBpProperties.java +++ b/spring-boot/src/main/java/io/vanillabp/camunda8/Camunda8VanillaBpProperties.java @@ -2,11 +2,10 @@ import io.camunda.zeebe.client.api.worker.JobWorkerBuilderStep1; import io.vanillabp.springboot.adapter.VanillaBpProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.util.StringUtils; - import java.time.Duration; import java.util.Map; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.util.StringUtils; @ConfigurationProperties(prefix = VanillaBpProperties.PREFIX, ignoreUnknownFields = true) public class Camunda8VanillaBpProperties { @@ -27,7 +26,7 @@ public void setWorkflowModules(Map work } private static final WorkflowModuleAdapterProperties defaultProperties = new WorkflowModuleAdapterProperties(); - private static final AdapterConfiguration defaultAdapterProperties = new AdapterConfiguration(); + private static final WorkflowModuleAdapterConfiguration defaultAdapterProperties = new WorkflowModuleAdapterConfiguration(); public String getTenantId( final String workflowModuleId) { @@ -46,6 +45,17 @@ public String getTenantId( } + public boolean isTaskIdAsHexString( + final String workflowModuleId) { + + final var configuration = workflowModules + .getOrDefault(workflowModuleId, defaultProperties) + .getAdapters() + .getOrDefault(Camunda8AdapterConfiguration.ADAPTER_ID, defaultAdapterProperties); + return configuration.isTaskIdAsHexString(); + + } + public WorkerProperties getUserTaskWorkerProperties( final String workflowModuleId) { @@ -97,6 +107,20 @@ public WorkerProperties getWorkerProperties( } + public static class WorkflowModuleAdapterConfiguration extends AdapterConfiguration { + + private boolean taskIdAsHexString = false; + + public boolean isTaskIdAsHexString() { + return taskIdAsHexString; + } + + public void setTaskIdAsHexString(boolean taskIdAsHexString) { + this.taskIdAsHexString = taskIdAsHexString; + } + + } + public static class AdapterConfiguration extends WorkerProperties { private boolean useTenants = true; @@ -125,15 +149,15 @@ public static class WorkflowModuleAdapterProperties { String workflowModuleId; - private Map adapters = Map.of(); + private Map adapters = Map.of(); private Map workflows = Map.of(); - public Map getAdapters() { + public Map getAdapters() { return adapters; } - public void setAdapters(Map adapters) { + public void setAdapters(Map adapters) { this.adapters = adapters; } diff --git a/spring-boot/src/main/java/io/vanillabp/camunda8/service/Camunda8ProcessService.java b/spring-boot/src/main/java/io/vanillabp/camunda8/service/Camunda8ProcessService.java index c1829c0..7311d23 100644 --- a/spring-boot/src/main/java/io/vanillabp/camunda8/service/Camunda8ProcessService.java +++ b/spring-boot/src/main/java/io/vanillabp/camunda8/service/Camunda8ProcessService.java @@ -229,6 +229,15 @@ public DE correlateMessage( } + private long getTaskIdAsLong( + final String taskId) { + + return camunda8Properties.isTaskIdAsHexString(parent.getWorkflowModuleId()) + ? Long.parseLong(taskId, 16) + : Long.parseLong(taskId); + + } + @Override public DE completeTask( final DE workflowAggregate, @@ -239,7 +248,7 @@ public DE completeTask( taskId, attachedAggregate -> { client - .newCompleteCommand(Long.parseLong(taskId, 16)) + .newCompleteCommand(getTaskIdAsLong(taskId)) .variables(attachedAggregate) .send() .join(); @@ -262,7 +271,7 @@ public DE completeUserTask( taskId, attachedAggregate -> { client - .newCompleteCommand(Long.parseLong(taskId, 16)) + .newCompleteCommand(getTaskIdAsLong(taskId)) .variables(attachedAggregate) .send() .join(); @@ -286,7 +295,7 @@ public DE cancelTask( taskId, attachedAggregate -> { client - .newThrowErrorCommand(Long.parseLong(taskId)) + .newThrowErrorCommand(getTaskIdAsLong(taskId)) .errorCode(errorCode) .send() .join(); @@ -355,7 +364,7 @@ private DE runInTransaction( new Camunda8TransactionProcessor.Camunda8TestForTaskAlreadyCompletedOrCancelled( methodSignature, () -> client - .newUpdateTimeoutCommand(Long.parseUnsignedLong(taskIdToTestForAlreadyCompletedOrCancelled, 16)) + .newUpdateTimeoutCommand(getTaskIdAsLong(taskIdToTestForAlreadyCompletedOrCancelled)) .timeout(Duration.ofMinutes(10)) .send() .join(5, TimeUnit.MINUTES), // needs to run synchronously diff --git a/spring-boot/src/main/java/io/vanillabp/camunda8/wiring/Camunda8TaskHandler.java b/spring-boot/src/main/java/io/vanillabp/camunda8/wiring/Camunda8TaskHandler.java index 4b13060..5baa36d 100644 --- a/spring-boot/src/main/java/io/vanillabp/camunda8/wiring/Camunda8TaskHandler.java +++ b/spring-boot/src/main/java/io/vanillabp/camunda8/wiring/Camunda8TaskHandler.java @@ -48,6 +48,8 @@ public class Camunda8TaskHandler extends TaskHandlerBase implements JobHandler, private final String bpmnProcessId; + private final boolean publishUserTaskIdAsHexString; + private ZeebeClient zeebeClient; public Camunda8TaskHandler( @@ -59,7 +61,8 @@ public Camunda8TaskHandler( final String idPropertyName, final String tenantId, final String workflowModuleId, - final String bpmnProcessId) { + final String bpmnProcessId, + final boolean publishUserTaskIdAsHexString) { super(workflowAggregateRepository, bean, method, parameters); this.taskType = taskType; @@ -67,6 +70,7 @@ public Camunda8TaskHandler( this.tenantId = tenantId; this.workflowModuleId = workflowModuleId; this.bpmnProcessId = bpmnProcessId; + this.publishUserTaskIdAsHexString = publishUserTaskIdAsHexString; } @@ -93,7 +97,9 @@ public void handle( try { final var businessKey = getVariable(job, idPropertyName); - final var taskId = Long.toHexString(job.getKey()); + final var taskId = publishUserTaskIdAsHexString + ? Long.toHexString(job.getKey()) + : Long.toString(job.getKey()); LoggingContext.setLoggingContext( Camunda8AdapterConfiguration.ADAPTER_ID,