Class RuleEngine
The engine is based on the GraalVM script engine which provides an advanced polyglot language feature. This allows to evaluate scripts in different programming languages (e.g. Java, JavaScript, Ruby, Python, R, LLVM, WebAssembly, etc.).
From a BPMN Event element, the Script Language can be defined by the property 'txtBusinessRuleEngine' or by a a comment added to the first line of a script in the following format:
// graalvm.languageId=js
A Script can access all basic item values from the current workItem and also the event by the provided member variables 'workitem' and 'event'.
The CDI bean can be replaced by an alternative CDI implementation to provide an extended functionality.
NOTE: The implementation replaces the old RuleEngien which was based on the Nashorn Script Engine. The engine to detect deprecated scripts and convert them automatically into the new format. It is recommended to replace deprecated scripts.
- Version:
- 4.0
- Author:
- Ralph Soika
-
Field Summary
-
Constructor Summary
ConstructorDescriptionThis method initializes the default script engine.RuleEngine
(String languageID) This method initializes the script engine with a specific languageId. -
Method Summary
Modifier and TypeMethodDescriptionThis helper method converts the member variable 'result' of the current context into a Map object and returns a new instance of a ItemCollection holding the values of the map.org.graalvm.polyglot.Value
boolean
evaluateBooleanExpression
(String script, ItemCollection workitem) This method evaluates a boolean expression.evaluateBusinessRule
(String script, ItemCollection workitem, ItemCollection event) This method evaluates the business rule.org.graalvm.polyglot.Context
Returns the current polyglot context This method implements a lazy initialization of the context.void
Sets the value of a member using an identifier.
-
Field Details
-
DEFAULT_LANGUAGE_ID
- See Also:
-
INVALID_SCRIPT
- See Also:
-
-
Constructor Details
-
RuleEngine
public RuleEngine()This method initializes the default script engine. -
RuleEngine
This method initializes the script engine with a specific languageId.- Parameters:
scriptLanguage
-
-
-
Method Details
-
getContext
public org.graalvm.polyglot.Context getContext()Returns the current polyglot context This method implements a lazy initialization of the context. See Issue #822 We also set the option 'WarnInterpreterOnly' to false. See also here: https://www.graalvm.org/22.0/reference-manual/js/FAQ/ Issue #821- Returns:
-
putMember
Sets the value of a member using an identifier. The member value is subject to polyglot value mapping rules as described in Context.asValue(Object).- Parameters:
identifier
-value
-
-
eval
-
evaluateBooleanExpression
public boolean evaluateBooleanExpression(String script, ItemCollection workitem) throws PluginException This method evaluates a boolean expression. An optional documentContext can be provided as member Variables to be used by the script- Parameters:
documentContext
- optional workitem context- Returns:
- boolean
- Throws:
PluginException
-
evaluateBusinessRule
public ItemCollection evaluateBusinessRule(String script, ItemCollection workitem, ItemCollection event) throws PluginException This method evaluates the business rule. The method returns the instance of the evaluated result object which can be used to continue evaluation. If a rule evaluation was not successful, the method returns null.An optional documentContext and a event object can be provided as member Variables to be used by the script
- Parameters:
workitem
- optional document contextevent
- optional bpmn event context- Returns:
- evaluated result instance
- Throws:
PluginException
-
convertResult
This helper method converts the member variable 'result' of the current context into a Map object and returns a new instance of a ItemCollection holding the values of the map.var result={};result.name='xxx';result.count=42;
- Parameters:
engine
-- Returns:
- ItemCollection holding the item values of the variable or null if no variable with the given name exists or the variable has not properties.
-