Yes it is possible to use a decision table for the if part of a sentry. But there is not attribute (or something like that) to reference the dmn in the if part.
You can use an expression which calls a method of a bean. There you could evaluate a decision table.
The implementation MyBean#evaluateDecision() could be as followed:
public class MyBean {
public boolean evaluateDecision(DelegateCaseExecution caseExecution) {
ProcessEngineServices services = caseExecution.getProcessEngineServices();
DecisionService decisionService = services.getDecisionService();
DmnDecisionTableResult decisionResult = decisionService.evaluateDecisionTableById("..").evaluate();
// do something with the result
boolean result = ...;
return result;
}
}
It is important that the invoked method must return a boolean value.
Thanks Roman for your detailed answer. It helped a lot. I will try it.
For my understanding: <condition>${myBean.evaluateDecision(caseExecution)}</condition>
Is this a Camunda-Feature, that allows to use such expressions like “${…}” or is it part of the CMMN Standard?
Does this approach work with any scope of a bean? (@SessionScoped, @RequestScoped, etc.)
No it is not part of the CMMN Standard. The CMMN standard only specify that the condition of the if part must be an expression. And Camunda BPM uses therefore JUEL (Java Unified Expression Language) (see 1).
To be honest, I am not sure. But I would say yes. Just try it out
this sound very interesting, as it maked sentries much more powerful, because I can execute DMN or any other custom logic.
One further question: What about test support? When testing BPMN processes (using camunda-bpm-mockito) I can easily register delegate (or listener or…) mocks and unit test my process without writing a single line of java delegate code.
What about those custom beans? They are not JavaDelegate and I cannot use a DelegateExpression on a sentry. Is there any “native” test support or do I have to manage that using Spring’s testing capabilities?