Camunda Expression Evaluation

Hi everyone,

currently I am working on a tool that checks the validity of BPMN models. Part of this is the evaluation of expressions which can be used in many variations. As of now, every kind of expression can be resolved using the open source implementation of JUEL.

The problem is to resolve expressions like the following expression taken from the camunda example project:

${dateTime().plusWeeks(1).toDate()}

This causes a TreeBuilderException during the creation of the tree in the Parser.class. My question now is how the camunda engine resolves suchs expressions. I tried to use org.camunda.bpm.engine.impl.juel.Tree and org.camunda.bpm.engine.impl.juel.TreeBuilder to resolve the expression, but same as the standard JUEL implementation, this returns a TreeBuilderException.

I hope someone can help me here. Cheers and thanks in advance
Sascha Di Bernardo

This is the starting point when the engine parses a JUEL expression:

Maybe you can start digging from there to find what you are looking for.

Hey Thorben,
thanks for providing a starting point. Unfortunately, calling this method with the parameter ${dateTime().plusWeeks(1).toDate()} again results in an exception.

org.camunda.bpm.engine.impl.javax.el.ELException: Could not resolve function ‘dateTime’
at org.camunda.bpm.engine.impl.juel.Tree.bind(Tree.java:122)
at org.camunda.bpm.engine.impl.juel.TreeValueExpression.(TreeValueExpression.java:65)
at org.camunda.bpm.engine.impl.juel.ExpressionFactoryImpl.createValueExpression(ExpressionFactoryImpl.java:428)
at org.camunda.bpm.engine.impl.juel.ExpressionFactoryImpl.createValueExpression(ExpressionFactoryImpl.java:73)
at org.camunda.bpm.engine.impl.el.ExpressionManager.createValueExpression(ExpressionManager.java:77)

What does “Could not resolve function” in this context mean? Note, that this expression is taken from theinvoice example, in case you want to verify or cross check.

Thanks and have a nice day
Sascha

Hi Sascha,

You will have to add a function mapper for the dateTime function, see https://github.com/camunda/camunda-bpm-platform/blob/master/engine/src/main/java/org/camunda/bpm/engine/impl/el/DateTimeFunctionMapper.java.

That said, you can also simply build a proper process engine and then use the engine’s expression manager as outlined here: Rest api to evaluate an expression of gateway

Cheers,
Thorben

Hi Thorben,

this might work if I want to evaluate the dateTime function, however I need to dynamically evaluate possible method invocations. Is there any possible solution, using the camunda engine, to evaluate such method invocations which are done via expressions?
Can the engine work with custom invocations such as ${doThis().doThat(1)} which might be declared in the delegates?

Cheers,
Sascha

Not sure, but it depends where and when you are checking the validity of a bpmn. Are you in the same exact execution environment? same beans defined? same situations?

To check JUEL expression or groovy ones, or any other dynamically typed languages, you have to test with running environment. For example the doThis() method can be injected at runtime and you cannot check it’s validity before that moment.

Quick follow up: I am trying to resolve data flow anomalies (i.e. writing to variables that dont exist or reading variables that are null, etc.). To be able to resolve such anomalies, I extract all process variables from the model and the referenced classes or beans. This works fine as long as the expressions don’t consist of method invocations such as described in the first post.

In order for this to work, I also need to know how method invocations in e.g. user tasks are resolved (because there does not exist any reference to a class/bean).

I hope this provides some explanation for the use case and what I exactly want to achieve.

Cheers,
Sascha

Hey Mizar,

as of now, this is a static evaluation prior any deployment. In the given use case, I have access to the project to be deployed as well as the beans etc. This means, that I have the model which consists of a e.g. user task that uses said expression from the first post and I have the project structure and content.
With that said, I thought I could extract from ${doThis().doThat(1)} two methods: first doThis() and then doThat(1). Then I would scan the project for said methods and try to retrieve any manipulation to the variables inside said methods in order to check for data flow anomalies.
In case such expression would be inside a e.g. serviceTask, then I would simply look into the bean/class.

So you arer unning this in a sort of testing environment? This is only worth if you have static methods for limited operations. When you sai ‘manipulation to the variables’ it means you are testing them (like in a Test Case). So you are creating dinamically test cases?

I did something similar in my project but it was limited to the calling syntax ( (I check if all method and bean called from diagram really exist in my java code). and not controlling all the flow, because the methods will involve calling sql procedures and process variables.

I’m interested though if you find a deeper solution.

It could be frustrating but the best (and slow) way to test a bpmn validity is with the testing framework provided (along with all its limits) and the ability for you to foresee what will be the meaningful cases.

Another way is to check everything with a separate camunda server used for testing (sometimes is faster). This I do often, along with the bpmn syntax checking before deploy.

Yes, all of this is done as a JUnit test. I have the beanmapping, spring context (if exists), the model and the project in my testing environment, so I can access all of the classes prior deployment to run static evaluation of process variables.

If you want to look deeper into it, check the tooling Im working on vPAV.
The problem occurs right here https://github.com/viadee/vPAV/blob/master/src/main/java/de/viadee/bpm/vPAV/processing/ProcessVariableReader.java#L994

As of now, I think of using an AST parser to parse the whole project tree, but this is to be done in the future.
Any suggestions are highly appreciated!

Cheers,
Sascha

I see! It’s wonderful.

I cannot give more hints right now, but I must say that your tool and all its features could be insanely useful to every bpmn designer.

Thanks alot for the kind words.
Feel free to spread the word, so the BPMN community can contribute and give input in order to improve the functionality

Cheers,
Sascha