Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

New annotation names and defaults #229

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ZeebeCustomHeaders {}
public @interface CustomHeaders {

// Double check what will happen with Properties?

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited // has to be inherited to work on spring aop beans
public @interface ZeebeDeployment {
public @interface Deployment {

@Deprecated
String[] classPathResources() default {};
// Are there other @Deployment annotations in the JAva Spring Boot space so this could create confusion?
// Alternative naming ideas:
// @ZeebeDeployment
// @CamundaDeployment

String[] resources() default {};

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ZeebeWorker {
public @interface JobWorker {
chDame marked this conversation as resolved.
Show resolved Hide resolved
// Alternative naming ideas:
// JobSubscription
// JobListener

String type() default ""; // set to empty string which leads to method name being used (if not ${zeebe.client.worker.default-type}" is configured) Implemented in ZeebeWorkerAnnotationProcessor

Expand All @@ -29,7 +32,7 @@
* Set to true, all variables are fetched independent of any other configuration
* via fetchVariables or @ZeebeVariable.
*/
boolean forceFetchAllVariables() default false;
boolean fetchAllVariables() default false;

/**
* If set to true, the job is automatically completed after the worker code has finished.
Expand All @@ -38,7 +41,7 @@
* You can still throw exceptions if you want to raise a problem instead of job completion.
* You could also raise a BPMN problem throwing a {@link io.camunda.zeebe.spring.client.exception.ZeebeBpmnError}
*/
boolean autoComplete() default false;
boolean autoComplete() default true;

boolean enabled() default true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ZeebeVariable {

public @interface Variable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ZeebeVariablesAsType {}
public @interface VariablesAsType {
// Alternative naming ideas:
// @Variables
// @VariablesObject
// @VariablesAsObject
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.api.command.DeployResourceCommandStep1;
import io.camunda.zeebe.client.api.response.DeploymentEvent;
import io.camunda.zeebe.spring.client.annotation.ZeebeDeployment;
import io.camunda.zeebe.spring.client.annotation.Deployment;
import io.camunda.zeebe.spring.client.bean.ClassInfo;
import io.camunda.zeebe.spring.client.annotation.value.ZeebeDeploymentValue;
import io.camunda.zeebe.spring.client.annotation.value.factory.ReadZeebeDeploymentValue;
Expand All @@ -25,7 +25,7 @@
/**
* Always created by {@link AnnotationProcessorConfiguration}
*
* Loop throgh @{@link ZeebeDeployment} annotations to deploy resources to Zeebe
* Loop throgh @{@link Deployment} annotations to deploy resources to Zeebe
* once the {@link io.camunda.zeebe.spring.client.lifecycle.ZeebeClientLifecycle} was initialized.
*/
public class ZeebeDeploymentAnnotationProcessor extends AbstractZeebeAnnotationProcessor {
Expand All @@ -44,7 +44,7 @@ public ZeebeDeploymentAnnotationProcessor(ReadZeebeDeploymentValue reader) {

@Override
public boolean isApplicableFor(ClassInfo beanInfo) {
return beanInfo.hasClassAnnotation(ZeebeDeployment.class);
return beanInfo.hasClassAnnotation(Deployment.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.camunda.zeebe.spring.client.annotation.value;

import io.camunda.zeebe.spring.client.annotation.ZeebeVariable;
import io.camunda.zeebe.spring.client.annotation.Variable;
import io.camunda.zeebe.spring.client.bean.CopyNotNullBeanUtilsBean;
import io.camunda.zeebe.spring.client.bean.MethodInfo;
import io.camunda.zeebe.spring.client.bean.ParameterInfo;
Expand Down Expand Up @@ -240,7 +240,7 @@ public ZeebeWorkerValue initializeFetchVariables(boolean forceFetchAllVariables,
}

private List<ParameterInfo> readZeebeVariableParameters(MethodInfo methodInfo) {
return methodInfo.getParametersFilteredByAnnotation(ZeebeVariable.class);
return methodInfo.getParametersFilteredByAnnotation(Variable.class);
}

public ZeebeWorkerValue initializeJobType(String jobType, MethodInfo methodInfo, String defaultWorkerType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.camunda.zeebe.spring.client.annotation.value.factory;

import io.camunda.zeebe.spring.client.annotation.ZeebeDeployment;
import io.camunda.zeebe.spring.client.annotation.Deployment;
import io.camunda.zeebe.spring.client.annotation.value.ZeebeDeploymentValue;
import io.camunda.zeebe.spring.client.bean.ClassInfo;

Expand All @@ -9,12 +9,12 @@
import java.util.Optional;
import java.util.stream.Collectors;

public class ReadZeebeDeploymentValue extends ReadAnnotationValue<ClassInfo, ZeebeDeployment, ZeebeDeploymentValue> {
public class ReadZeebeDeploymentValue extends ReadAnnotationValue<ClassInfo, Deployment, ZeebeDeploymentValue> {

private static final String CLASSPATH_ALL_URL_PREFIX = "classpath*:";

public ReadZeebeDeploymentValue() {
super(ZeebeDeployment.class);
super(Deployment.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import io.camunda.zeebe.client.api.worker.JobClient;
import io.camunda.zeebe.client.api.worker.JobHandler;
import io.camunda.zeebe.client.impl.Loggers;
import io.camunda.zeebe.spring.client.annotation.ZeebeCustomHeaders;
import io.camunda.zeebe.spring.client.annotation.ZeebeVariable;
import io.camunda.zeebe.spring.client.annotation.CustomHeaders;
import io.camunda.zeebe.spring.client.annotation.Variable;
import io.camunda.zeebe.spring.client.annotation.ZeebeVariablesAsType;
import io.camunda.zeebe.spring.client.bean.ParameterInfo;
import io.camunda.zeebe.spring.client.annotation.value.ZeebeWorkerValue;
Expand Down Expand Up @@ -70,7 +70,7 @@ private List<Object> createParameters(JobClient jobClient, ActivatedJob job, Lis
arg = jobClient;
} else if (ActivatedJob.class.isAssignableFrom(clazz)) {
arg = job;
} else if (param.getParameterInfo().isAnnotationPresent(ZeebeVariable.class)) {
} else if (param.getParameterInfo().isAnnotationPresent(Variable.class)) {
try {
// TODO make this work for complex types as well
arg = clazz.cast(job.getVariablesAsMap().get(param.getParameterName()));
Expand All @@ -84,7 +84,7 @@ private List<Object> createParameters(JobClient jobClient, ActivatedJob job, Lis
} catch (RuntimeException e) {
throw new RuntimeException("Cannot assign process variables to type '" + clazz.getName() + "' when executing job '"+job.getType()+"', cause is: " + e.getMessage(), e);
}
} else if (param.getParameterInfo().isAnnotationPresent(ZeebeCustomHeaders.class)) {
} else if (param.getParameterInfo().isAnnotationPresent(CustomHeaders.class)) {
try {
arg = job.getCustomHeaders();
} catch (RuntimeException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import static org.assertj.core.api.Assertions.assertThat;

import io.camunda.zeebe.spring.client.annotation.ZeebeDeployment;
import io.camunda.zeebe.spring.client.annotation.ZeebeVariable;
import io.camunda.zeebe.spring.client.annotation.Deployment;
import io.camunda.zeebe.spring.client.annotation.Variable;
import io.camunda.zeebe.spring.client.annotation.ZeebeWorker;
import org.junit.jupiter.api.Test;

import java.beans.Introspector;

public class ClassInfoTest {

@ZeebeDeployment(classPathResources = "/1.bpmn")
@Deployment(classPathResources = "/1.bpmn")
public static class WithDeploymentAnnotation {

}
Expand All @@ -36,13 +36,13 @@ public void handle() {

public static class WithZeebeWorkerVariables {
@ZeebeWorker(type = "bar", timeout = 100L, fetchVariables = "var3")
public void handle(@ZeebeVariable String var1, @ZeebeVariable int var2) {
public void handle(@Variable String var1, @Variable int var2) {
}
}

public static class WithDisabledZeebeWorker {
@ZeebeWorker(type = "bar", enabled = false)
public void handle(@ZeebeVariable String var1, @ZeebeVariable int var2) {
public void handle(@Variable String var1, @Variable int var2) {
}
}

Expand All @@ -65,14 +65,14 @@ public void getBeanInfo() throws Exception {

@Test
public void hasZeebeeDeploymentAnnotation() throws Exception {
assertThat(beanInfo(new WithDeploymentAnnotation()).hasClassAnnotation(ZeebeDeployment.class))
assertThat(beanInfo(new WithDeploymentAnnotation()).hasClassAnnotation(Deployment.class))
.isTrue();
}

@Test
public void hasNoZeebeeDeploymentAnnotation() throws Exception {
assertThat(
beanInfo(new WithoutDeploymentAnnotation()).hasClassAnnotation(ZeebeDeployment.class))
beanInfo(new WithoutDeploymentAnnotation()).hasClassAnnotation(Deployment.class))
.isFalse();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.camunda.zeebe.spring.client.bean.value.factory;

import io.camunda.zeebe.spring.client.annotation.ZeebeDeployment;
import io.camunda.zeebe.spring.client.annotation.Deployment;
import io.camunda.zeebe.spring.client.annotation.value.factory.ReadZeebeDeploymentValue;
import io.camunda.zeebe.spring.client.bean.ClassInfo;
import io.camunda.zeebe.spring.client.annotation.value.ZeebeDeploymentValue;
Expand Down Expand Up @@ -79,12 +79,12 @@ public void shouldReadNoClassPathResourcesTest() {
assertFalse(valueForClass.isPresent());
}

@ZeebeDeployment(classPathResources = "/1.bpmn")
@Deployment(classPathResources = "/1.bpmn")
private static class WithSingleClassPathResource {

}

@ZeebeDeployment(classPathResources = {"/1.bpmn", "/2.bpmn"})
@Deployment(classPathResources = {"/1.bpmn", "/2.bpmn"})
private static class WithMultipleClassPathResource {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.camunda.zeebe.client.api.response.ProcessInstanceEvent;
import io.camunda.zeebe.spring.client.EnableZeebeClient;
import io.camunda.zeebe.spring.client.lifecycle.ZeebeClientLifecycle;
import io.camunda.zeebe.spring.client.annotation.ZeebeDeployment;
import io.camunda.zeebe.spring.client.annotation.Deployment;

import java.util.Date;
import java.util.UUID;
Expand All @@ -19,7 +19,7 @@
@SpringBootApplication
@EnableZeebeClient
@EnableScheduling
@ZeebeDeployment(resources = "classpath:demoProcess.bpmn")
@Deployment(resources = "classpath:demoProcess.bpmn")
public class StarterApplication {

private static Logger log = LoggerFactory.getLogger(StarterApplication.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.camunda.zeebe.client.api.worker.JobClient;
import io.camunda.zeebe.client.api.response.ActivatedJob;
import io.camunda.zeebe.spring.client.EnableZeebeClient;
import io.camunda.zeebe.spring.client.annotation.ZeebeVariable;
import io.camunda.zeebe.spring.client.annotation.Variable;
import io.camunda.zeebe.spring.client.annotation.ZeebeWorker;
import java.time.Instant;
import java.util.Collections;
Expand Down Expand Up @@ -39,19 +39,19 @@ private static void logJob(final ActivatedJob job, Object parameterValue) {
job.getVariables());
}

@ZeebeWorker(type = "foo", autoComplete = true)
@ZeebeWorker(type = "foo", autoComplete = true)
public void handleFooJob(final ActivatedJob job) {
logJob(job, null);
}

@ZeebeWorker(type = "bar", autoComplete = true)
public Map<String, Object> handleBarJob(final JobClient client, final ActivatedJob job, @ZeebeVariable String a) {
@ZeebeWorker(type = "bar", autoComplete = true)
public Map<String, Object> handleBarJob(final JobClient client, final ActivatedJob job, @Variable String a) {
logJob(job, a);
return Collections.singletonMap("someResult", "42");
}

@ZeebeWorker(type = "fail", autoComplete = true, forceFetchAllVariables = true)
public void handleFailingJob(final JobClient client, final ActivatedJob job, @ZeebeVariable String someResult) {
public void handleFailingJob(final JobClient client, final ActivatedJob job, @Variable String someResult) {
logJob(job, someResult);
throw new ZeebeBpmnError("DOESNT_WORK", "This will actually never work :-)");
}
Expand Down