How to use Java class for Flow Condition Type?

I would like to use a Java Class for the condition in sequence flows. However the Modeler only gives me Expression and Script options. My logic for these conditions would be better served by using Java code. The code will just need to evaluate some process variables and return a boolean. However I don’t see any examples of this, how can this be done?

Usually a condition on a sequence flow is best kept as a basic expression. That makes it easier to read and maintain. but if you really want to run a JavaClass you’d probably have to use a execution listener before the gateway.

Your requirement

does not seem like you require Java code. You can evaluate existing process data within expressions, which can become quite powerful.

Please see Expression Language | docs.camunda.org and Unified Expression Language - The Java EE 5 Tutorial esp. section Examples of EL Expressions.

If really necessary you could even use the expression to call a method.

Here is an example of the Groovy code. I have several of these each with a different type values and these are reused a lot so with Groovy I have to copy/paste a lot. I’d prefer to reuse a class that has all these in one place perhaps just with a different method name for the type value.

for(Map<String, Object> dmnResult : dmnResults)

{
if(dmnResult.get(“type”).equals(“publishAndWait”))
{
return true;
}
}

return false;

I don’t think this can be done with Expression (EL)

I have not used execution listener before, how would I do that and how does that direct the flow after the gateway?

Using expression to call a method (I assume you mean on a bean) sounds like a good option, how do I do that?

As mentioned:

However, the logic you posted above shows that the data you want to evaluate is the results of a DMN and you just want to check if any rule lead to a result “publishAndWait”. Have you considers determining the value of your boolean for the gateway condition in the DMN already?

I’m new to BPMN & DMN but I don’t think I can put that looping logic inside a DMN. The DMN is where the records/values are set but then I need to loop through those to see what is set. I think I need code to do this.

Thanks for the link to the EL expressions using a bean…that worked great!

You could also reference an external script, so you don;t have to keep copy/pasting the logic – just reference the script location in your classpath