Skip to content

Commit a09a6f4

Browse files
committed
fixed a bug where the variable name was not fetched from the annotation field name
1 parent 3fa00cb commit a09a6f4

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/properties/PropertyBasedZeebeWorkerValueCustomizer.java

+26-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.apache.commons.lang3.StringUtils.*;
44

5+
import io.camunda.zeebe.client.api.response.ActivatedJob;
56
import io.camunda.zeebe.spring.client.annotation.Variable;
67
import io.camunda.zeebe.spring.client.annotation.VariablesAsType;
78
import io.camunda.zeebe.spring.client.annotation.ZeebeVariable;
@@ -44,6 +45,12 @@ public void customize(ZeebeWorkerValue zeebeWorker) {
4445
}
4546

4647
private void applyFetchVariables(ZeebeWorkerValue zeebeWorkerValue) {
48+
if (hasActivatedJobInjected(zeebeWorkerValue)) {
49+
LOG.debug(
50+
"Worker '{}': ActivatedJob is injected, no variable filtering possible",
51+
zeebeWorkerValue.getName());
52+
return;
53+
}
4754
if (zeebeWorkerValue.isForceFetchAllVariables()) {
4855
LOG.debug("Worker '{}': Force fetch all variables is enabled", zeebeWorkerValue.getName());
4956
zeebeWorkerValue.setFetchVariables(new String[0]);
@@ -54,7 +61,7 @@ private void applyFetchVariables(ZeebeWorkerValue zeebeWorkerValue) {
5461
}
5562
variables.addAll(
5663
readZeebeVariableParameters(zeebeWorkerValue.getMethodInfo()).stream()
57-
.map(ParameterInfo::getParameterName)
64+
.map(this::extractVariableName)
5865
.collect(Collectors.toList()));
5966
variables.addAll(readVariablesAsTypeParameters(zeebeWorkerValue.getMethodInfo()));
6067
zeebeWorkerValue.setFetchVariables(variables.toArray(new String[0]));
@@ -65,6 +72,24 @@ private void applyFetchVariables(ZeebeWorkerValue zeebeWorkerValue) {
6572
}
6673
}
6774

75+
private boolean hasActivatedJobInjected(ZeebeWorkerValue zeebeWorkerValue) {
76+
return zeebeWorkerValue.getMethodInfo().getParameters().stream()
77+
.anyMatch(p -> p.getParameterInfo().getType().equals(ActivatedJob.class));
78+
}
79+
80+
private String extractVariableName(ParameterInfo parameterInfo) {
81+
Variable annotation = parameterInfo.getParameterInfo().getAnnotation(Variable.class);
82+
if (annotation != null) {
83+
if (Variable.DEFAULT_NAME.equals(annotation.name())) {
84+
return parameterInfo.getParameterName();
85+
} else {
86+
return annotation.name();
87+
}
88+
} else {
89+
return parameterInfo.getParameterName();
90+
}
91+
}
92+
6893
private List<ParameterInfo> readZeebeVariableParameters(MethodInfo methodInfo) {
6994
List<ParameterInfo> result = methodInfo.getParametersFilteredByAnnotation(Variable.class);
7095
result.addAll(methodInfo.getParametersFilteredByAnnotation(ZeebeVariable.class));

0 commit comments

Comments
 (0)