Evaluate condition using Java

60 views
Skip to first unread message

ma...@stefan-beer.eu

unread,
Jul 17, 2014, 11:32:27 AM7/17/14
to camunda-...@googlegroups.com
Hi,

is it possible to evaluate a condition of a SequenceFlow using, for example, an ExecutionListener or something similar? I.e. can the evaluation be delegated to custom Java code?

Kind regards,

Stefan

Sebastian Menski

unread,
Jul 18, 2014, 3:16:03 AM7/18/14
to camunda-...@googlegroups.com, ma...@stefan-beer.eu
Hi Stefan,

no it is currently not possible to use Java code as condition of a sequence flow. But with our new 7.2.0-alpha3 release it is now possible to use a script
as condition. For more information on that please see the docs on conditional sequence flows and scripting.

I don't know what you want to achieve but maybe you could use Groovy for your use case.

Cheers,
Sebastian 

ma...@stefan-beer.eu

unread,
Jul 18, 2014, 4:10:16 AM7/18/14
to camunda-...@googlegroups.com, ma...@stefan-beer.eu
Thanks for your reply.

Our use case: We have a custom expression language, which we'd like to use for conditions. Of course, those expressions can't be evaluated using Java UEL or any other built-in mechanism.

Consider the following SequenceFlow:

<sequenceFlow id="SeqFlow_1" name="" sourceRef="ExclusiveGateway_1" targetRef="EndEvent_1">
<conditionExpression>CUSTOM EXPRESSION</conditionExpression>
</sequenceFlow>

When the gateway in the example above starts evaluating the conditions of the different outgoing sequence flows to decide which path to take, it would be helpful to have some callback mechanism to evaluate the custom expression, for example:

interface ConditionListener {
boolean evaluateCondition(String theConditionExpression);
}

Let a class implement the interface:

public class MyCustomEvaluator implements ConditionListener {
...
}

And then hook the class into the expression:

<conditionExpression class="my.package.MyCustomEvaluator">CUSTOM EXPRESSION</conditionExpression>

Maybe I can use the scripting approach, but a mechanism like the one just described would be (a lot) more convenient... :-)

Sebastian Menski

unread,
Jul 18, 2014, 4:33:31 AM7/18/14
to camunda-...@googlegroups.com, ma...@stefan-beer.eu
Hi Stefan,

a condition listener interface is currently not planed for camunda BPM.

But If you got your own expression language you could implement your own JSR223 scripting engine.
This are only two interfaces to implement. We did something similar for template engines (see the github
project). After that you could use your expression language everywhere you could use a script.

But please note that this extended support for scripting was first introduced in the newly 7.2.0-alpha3.

Cheers,
Sebastian

ma...@stefan-beer.eu

unread,
Jul 18, 2014, 4:56:00 AM7/18/14
to camunda-...@googlegroups.com, ma...@stefan-beer.eu
I'll have a look at the JSR. Thanks a lot!

Stefan

ma...@stefan-beer.eu

unread,
Jul 23, 2014, 3:04:48 AM7/23/14
to camunda-...@googlegroups.com, ma...@stefan-beer.eu
FYI and that of other readers:

I implemented the two interfaces of the JSR and everything works nicely.

Stefan

Reply all
Reply to author
Forward
0 new messages