Sure, I'm happy to give something back.
The aim was to implement a task which could determine whether user authorisation was required for a monetary order with the process being able to handle changing business rules.
The gateway from the task now has one default flow and one flow with a static condition of:
<code>
${nextState == "AUTHORIZATION_REQUIRED"}
</code>
At the start of the process, the following execution variables are loaded:
- "model": the data we are processing
- "configParameters": configuration parameters loaded from a database.
The interesting bit is that the business rule to determine whether authorisation is required is the value of one of the configuration parameters, and is written in expression language.
It is evaluated as follows (I have simplified):
<code>
import de.odysseus.el.ExpressionFactoryImpl;
import de.odysseus.el.util.SimpleContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
// etc
String conditionAuthRequired = configParameters.getString("decisionAuthorisationRequired");
if (evaluateUELBoolean(conditionAuthRequired, model, configParameters)) {
nextState = "AUTHORIZATION_REQUIRED";
} else {
nextState = "AUTHORIZATION_NOT_REQUIRED";
}
public static boolean evaluateUELBoolean(String strExpression, Model model, ConfigParameters configParameters) {
ExpressionFactory factory = new ExpressionFactoryImpl();
SimpleContext context = new SimpleContext();
// Supply the values for model and configParameters to the expression before it is evaluated
context.setVariable("model", factory.createValueExpression(model, Model.class));
context.setVariable("configParameters", factory.createValueExpression(configParameters, ConfigParameters.class));
ValueExpression valueExpression = factory.createValueExpression(context, strExpression, Boolean.class);
return (Boolean) valueExpression.getValue(context);
}
</code>
It works, though the value of the configuration parameter which contains the business logic could become complex quite quickly.
An example we have is for the value of the "decisionAuthorisationRequired" parameter is:
<code>
${configParameters.getStringList('scriptsRequiringAuthorization').contains(model.config.action.id)}
</code>
demonstrating that the expression language can reference both the data model and the configuration parameters.