Skip to content

Commit

Permalink
Merge pull request #70 from camunda-community-hub/feature/task-id-in-…
Browse files Browse the repository at this point in the history
…decimal

Use decimal values for task ids instead of hex values (#69)
  • Loading branch information
stephanpelikan authored Dec 18, 2024
2 parents 04318fd + bc2f976 commit 2a1a7ec
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ public Camunda8TaskHandler camunda8TaskHandler(
idPropertyName,
tenantId,
workflowModuleId,
bpmnProcessId);
bpmnProcessId,
camunda8Properties.isTaskIdAsHexString(workflowModuleId));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -27,7 +26,7 @@ public void setWorkflowModules(Map<String, WorkflowModuleAdapterProperties> 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) {
Expand All @@ -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) {

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -125,15 +149,15 @@ public static class WorkflowModuleAdapterProperties {

String workflowModuleId;

private Map<String, AdapterConfiguration> adapters = Map.of();
private Map<String, WorkflowModuleAdapterConfiguration> adapters = Map.of();

private Map<String, WorkflowAdapterProperties> workflows = Map.of();

public Map<String, AdapterConfiguration> getAdapters() {
public Map<String, WorkflowModuleAdapterConfiguration> getAdapters() {
return adapters;
}

public void setAdapters(Map<String, AdapterConfiguration> adapters) {
public void setAdapters(Map<String, WorkflowModuleAdapterConfiguration> adapters) {
this.adapters = adapters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -239,7 +248,7 @@ public DE completeTask(
taskId,
attachedAggregate -> {
client
.newCompleteCommand(Long.parseLong(taskId, 16))
.newCompleteCommand(getTaskIdAsLong(taskId))
.variables(attachedAggregate)
.send()
.join();
Expand All @@ -262,7 +271,7 @@ public DE completeUserTask(
taskId,
attachedAggregate -> {
client
.newCompleteCommand(Long.parseLong(taskId, 16))
.newCompleteCommand(getTaskIdAsLong(taskId))
.variables(attachedAggregate)
.send()
.join();
Expand All @@ -286,7 +295,7 @@ public DE cancelTask(
taskId,
attachedAggregate -> {
client
.newThrowErrorCommand(Long.parseLong(taskId))
.newThrowErrorCommand(getTaskIdAsLong(taskId))
.errorCode(errorCode)
.send()
.join();
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class Camunda8TaskHandler extends TaskHandlerBase implements JobHandler,

private final String bpmnProcessId;

private final boolean publishUserTaskIdAsHexString;

private ZeebeClient zeebeClient;

public Camunda8TaskHandler(
Expand All @@ -59,14 +61,16 @@ 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;
this.idPropertyName = idPropertyName;
this.tenantId = tenantId;
this.workflowModuleId = workflowModuleId;
this.bpmnProcessId = bpmnProcessId;
this.publishUserTaskIdAsHexString = publishUserTaskIdAsHexString;

}

Expand All @@ -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,
Expand Down

0 comments on commit 2a1a7ec

Please sign in to comment.