Skip to content

Commit 6f5f306

Browse files
committed
formatter
1 parent abf63ca commit 6f5f306

File tree

2 files changed

+77
-60
lines changed

2 files changed

+77
-60
lines changed

spring-boot-starter-camunda/src/test/java/io/camunda/zeebe/spring/client/properties/PropertyBasedZeebeWorkerValueCustomizerTest.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package io.camunda.zeebe.spring.client.properties;
22

3+
import static org.assertj.core.api.Assertions.*;
4+
35
import io.camunda.zeebe.spring.client.annotation.value.ZeebeWorkerValue;
46
import org.junit.jupiter.api.Test;
57

6-
import static org.assertj.core.api.Assertions.*;
7-
88
public class PropertyBasedZeebeWorkerValueCustomizerTest {
99
@Test
10-
void shouldApplyOverrides(){
10+
void shouldApplyOverrides() {
1111
ZeebeClientConfigurationProperties properties = new ZeebeClientConfigurationProperties(null);
1212
properties.applyOverrides();
13-
properties.getWorker().getOverride().put("someWorker",new ZeebeWorkerValue().enabled(false));
14-
PropertyBasedZeebeWorkerValueCustomizer customizer = new PropertyBasedZeebeWorkerValueCustomizer(properties);
13+
properties.getWorker().getOverride().put("someWorker", new ZeebeWorkerValue().enabled(false));
14+
PropertyBasedZeebeWorkerValueCustomizer customizer =
15+
new PropertyBasedZeebeWorkerValueCustomizer(properties);
1516
ZeebeWorkerValue original = new ZeebeWorkerValue().type("someWorker").enabled(true);
1617
customizer.customize(original);
1718
assertThat(original.getEnabled()).isEqualTo(false);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.camunda.zeebe.spring.client.annotation.processor;
22

3+
import static org.springframework.util.ReflectionUtils.doWithMethods;
4+
35
import io.camunda.zeebe.client.ZeebeClient;
46
import io.camunda.zeebe.spring.client.annotation.JobWorker;
57
import io.camunda.zeebe.spring.client.annotation.ZeebeWorker;
@@ -8,26 +10,24 @@
810
import io.camunda.zeebe.spring.client.bean.ClassInfo;
911
import io.camunda.zeebe.spring.client.bean.MethodInfo;
1012
import io.camunda.zeebe.spring.client.jobhandling.JobWorkerManager;
11-
import org.slf4j.Logger;
12-
import org.slf4j.LoggerFactory;
13-
import org.springframework.util.ReflectionUtils;
14-
1513
import java.lang.invoke.MethodHandles;
1614
import java.util.ArrayList;
1715
import java.util.List;
1816
import java.util.Optional;
19-
20-
import static org.springframework.util.ReflectionUtils.doWithMethods;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
19+
import org.springframework.util.ReflectionUtils;
2120

2221
/**
2322
* Always created by {@link AnnotationProcessorConfiguration}
2423
*
25-
* Triggered by {@link ZeebeAnnotationProcessorRegistry#postProcessAfterInitialization(Object, String)} to add Handler subscriptions for {@link ZeebeWorker}
26-
* method-annotations.
24+
* <p>Triggered by {@link ZeebeAnnotationProcessorRegistry#postProcessAfterInitialization(Object,
25+
* String)} to add Handler subscriptions for {@link ZeebeWorker} method-annotations.
2726
*/
2827
public class ZeebeWorkerAnnotationProcessor extends AbstractZeebeAnnotationProcessor {
2928

30-
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
29+
private static final Logger LOGGER =
30+
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
3131

3232
private final JobWorkerManager jobWorkerManager;
3333

@@ -36,9 +36,11 @@ public class ZeebeWorkerAnnotationProcessor extends AbstractZeebeAnnotationProce
3636
private String defaultWorkerType;
3737
private String defaultWorkerName;
3838

39-
public ZeebeWorkerAnnotationProcessor(final JobWorkerManager jobWorkerFactory,
40-
final List<ZeebeWorkerValueCustomizer> zeebeWorkerValueCustomizers,
41-
final String defaultWorkerType, final String defaultJobWorkerName) {
39+
public ZeebeWorkerAnnotationProcessor(
40+
final JobWorkerManager jobWorkerFactory,
41+
final List<ZeebeWorkerValueCustomizer> zeebeWorkerValueCustomizers,
42+
final String defaultWorkerType,
43+
final String defaultJobWorkerName) {
4244
this.jobWorkerManager = jobWorkerFactory;
4345
this.zeebeWorkerValueCustomizers = zeebeWorkerValueCustomizers;
4446
this.defaultWorkerType = defaultWorkerType;
@@ -47,78 +49,92 @@ public ZeebeWorkerAnnotationProcessor(final JobWorkerManager jobWorkerFactory,
4749

4850
@Override
4951
public boolean isApplicableFor(ClassInfo beanInfo) {
50-
return beanInfo.hasMethodAnnotation(JobWorker.class) || beanInfo.hasMethodAnnotation(ZeebeWorker.class);
52+
return beanInfo.hasMethodAnnotation(JobWorker.class)
53+
|| beanInfo.hasMethodAnnotation(ZeebeWorker.class);
5154
}
5255

5356
@Override
5457
public void configureFor(ClassInfo beanInfo) {
5558
List<ZeebeWorkerValue> newZeebeWorkerValues = new ArrayList<>();
5659

5760
doWithMethods(
58-
beanInfo.getTargetClass(),
59-
method -> readJobWorkerAnnotationForMethod(beanInfo.toMethodInfo(method)).ifPresent(newZeebeWorkerValues::add),
60-
ReflectionUtils.USER_DECLARED_METHODS);
61-
62-
LOGGER.info("Configuring {} Zeebe worker(s) of bean '{}': {}", newZeebeWorkerValues.size(), beanInfo.getBeanName(), newZeebeWorkerValues);
61+
beanInfo.getTargetClass(),
62+
method ->
63+
readJobWorkerAnnotationForMethod(beanInfo.toMethodInfo(method))
64+
.ifPresent(newZeebeWorkerValues::add),
65+
ReflectionUtils.USER_DECLARED_METHODS);
66+
67+
LOGGER.info(
68+
"Configuring {} Zeebe worker(s) of bean '{}': {}",
69+
newZeebeWorkerValues.size(),
70+
beanInfo.getBeanName(),
71+
newZeebeWorkerValues);
6372
zeebeWorkerValues.addAll(newZeebeWorkerValues);
6473
}
6574

6675
public Optional<ZeebeWorkerValue> readJobWorkerAnnotationForMethod(final MethodInfo methodInfo) {
6776
Optional<JobWorker> methodAnnotation = methodInfo.getAnnotation(JobWorker.class);
6877
if (methodAnnotation.isPresent()) {
6978
JobWorker annotation = methodAnnotation.get();
70-
return Optional.of(new ZeebeWorkerValue()
71-
.methodInfo(methodInfo)
72-
.type(annotation.type())
73-
.timeout(annotation.timeout())
74-
.maxJobsActive(annotation.maxJobsActive())
75-
.pollInterval(annotation.pollInterval())
76-
.autoComplete(annotation.autoComplete())
77-
.requestTimeout(annotation.requestTimeout())
78-
.enabled(annotation.enabled())
79-
80-
// TODO Get rid of those initialize methods but add the attributes as values onto the worker and then auto-initialize stuff when opening the worker
81-
.initializeName(annotation.name(), methodInfo, defaultWorkerName)
82-
.initializeFetchVariables(annotation.fetchAllVariables(), annotation.fetchVariables(), methodInfo)
83-
.initializeJobType(annotation.type(), methodInfo, defaultWorkerType));
79+
return Optional.of(
80+
new ZeebeWorkerValue()
81+
.methodInfo(methodInfo)
82+
.type(annotation.type())
83+
.timeout(annotation.timeout())
84+
.maxJobsActive(annotation.maxJobsActive())
85+
.pollInterval(annotation.pollInterval())
86+
.autoComplete(annotation.autoComplete())
87+
.requestTimeout(annotation.requestTimeout())
88+
.enabled(annotation.enabled())
89+
90+
// TODO Get rid of those initialize methods but add the attributes as values onto the
91+
// worker and then auto-initialize stuff when opening the worker
92+
.initializeName(annotation.name(), methodInfo, defaultWorkerName)
93+
.initializeFetchVariables(
94+
annotation.fetchAllVariables(), annotation.fetchVariables(), methodInfo)
95+
.initializeJobType(annotation.type(), methodInfo, defaultWorkerType));
8496
} else {
8597
Optional<ZeebeWorker> legacyAnnotation = methodInfo.getAnnotation(ZeebeWorker.class);
8698
if (legacyAnnotation.isPresent()) {
8799
ZeebeWorker annotation = legacyAnnotation.get();
88-
return Optional.of(new ZeebeWorkerValue()
89-
.methodInfo(methodInfo)
90-
.type(annotation.type())
91-
.timeout(annotation.timeout())
92-
.maxJobsActive(annotation.maxJobsActive())
93-
.pollInterval(annotation.pollInterval())
94-
.autoComplete(annotation.autoComplete())
95-
.requestTimeout(annotation.requestTimeout())
96-
.enabled(annotation.enabled())
97-
98-
// TODO Get rid of those initialize methods but add the attributes as values onto the worker and then auto-initialize stuff when opening the worker
99-
.initializeName(annotation.name(), methodInfo, defaultWorkerName)
100-
.initializeFetchVariables(annotation.forceFetchAllVariables(), annotation.fetchVariables(), methodInfo)
101-
.initializeJobType(annotation.type(), methodInfo, defaultWorkerType));
100+
return Optional.of(
101+
new ZeebeWorkerValue()
102+
.methodInfo(methodInfo)
103+
.type(annotation.type())
104+
.timeout(annotation.timeout())
105+
.maxJobsActive(annotation.maxJobsActive())
106+
.pollInterval(annotation.pollInterval())
107+
.autoComplete(annotation.autoComplete())
108+
.requestTimeout(annotation.requestTimeout())
109+
.enabled(annotation.enabled())
110+
111+
// TODO Get rid of those initialize methods but add the attributes as values onto
112+
// the worker and then auto-initialize stuff when opening the worker
113+
.initializeName(annotation.name(), methodInfo, defaultWorkerName)
114+
.initializeFetchVariables(
115+
annotation.forceFetchAllVariables(), annotation.fetchVariables(), methodInfo)
116+
.initializeJobType(annotation.type(), methodInfo, defaultWorkerType));
102117
}
103118
}
104119
return Optional.empty();
105120
}
106121

107122
@Override
108123
public void start(ZeebeClient client) {
109-
zeebeWorkerValues
110-
.stream()
111-
.peek(zeebeWorkerValue -> zeebeWorkerValueCustomizers.forEach(customizer -> customizer.customize(zeebeWorkerValue)))
112-
.filter(ZeebeWorkerValue::getEnabled)
113-
.forEach(
114-
zeebeWorkerValue -> {
115-
jobWorkerManager.openWorker(client, zeebeWorkerValue);
116-
});
124+
zeebeWorkerValues.stream()
125+
.peek(
126+
zeebeWorkerValue ->
127+
zeebeWorkerValueCustomizers.forEach(
128+
customizer -> customizer.customize(zeebeWorkerValue)))
129+
.filter(ZeebeWorkerValue::getEnabled)
130+
.forEach(
131+
zeebeWorkerValue -> {
132+
jobWorkerManager.openWorker(client, zeebeWorkerValue);
133+
});
117134
}
118135

119136
@Override
120137
public void stop(ZeebeClient zeebeClient) {
121138
jobWorkerManager.closeAllOpenWorkers();
122139
}
123-
124140
}

0 commit comments

Comments
 (0)