-
Notifications
You must be signed in to change notification settings - Fork 9
How to write delegates
Delegate is a method with an annotaion @DelegateExecute
in class marked with an annotation @CamundaDelegate
.
Example:
@CamundaDelegate
class SimpleDelegate {
@DelegateExecute
fun doNothing() {}
}
This delegate can be accessed by name simpleDelegate_doNothing
.
By delault the name consists of 2 parts: the name of the class and the name of the method separated by _
. Each part can be overrideв via a parameter in the annotation.
Example:
@CamundaDelegate("nonSimpleDelegate")
class SimpleDelegate {
@DelegateExecute
fun doNothing() {}
}
Delegate name is nonSimpleDelegate_doNothing
.
If necessary, you can add aliases for the delegate using the annotation DelegateAliases
.
Each delegate name must be unique
Each required method parameter must be resolved by DelegateArgumentResolver.
Common resolvers:
-
ContextVariableResolver - resolvers for context variable. Add annotation
@Variable
to parameter to use it -
DelegateExecutionResolver - resolvers for delegate context. Add annotation
@DelegateExecutionAnn
to parameter to use it
Example:
@CamundaDelegate
class SimpleDelegate {
@DelegateExecute
fun doNothing(
@Variable("local") localVariable: String,
@Variable("optional") optionalVariable: String?,
@Variable("global", isLocal = false) globalVariable: String,
@DelegateExecutionAnn execution: DelegateExecution
) {}
}
In Kotlin method argumets with
?
is optional. In Java optional parameter should be marked with any@Nullable
annotation
You can write custom resolvers
Return value from delegate method can be processed by DelegateInterceptor
(by default return value is ignored).
Common interceptors:
-
SingleResultExecutionWriter - this interceptor write single variable to delegate execustion. To use it mark method an annotaion
@SingleResultVariable
and set variable name -
MultipleResultExecutionWriter - this interceptor write multiple variables to delegate execustion. To use it mark method an annotaion
@MultipleResults
and all field from return class marked an annotation@ResultVariable
will be recorded into delegate execution
Example:
@CamundaDelegate
class SimpleDelegate {
@DelegateExecute
@SingleResultVariable("result")
fun doNothing(
): String {
return "string";
}
}
You can write custom delegate interceptors with your logic.