Klasse 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
- Autor:
- Ralph Soika
-
Feldübersicht
Felder -
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungThis method initializes the default script engine.RuleEngine(String languageID) This method initializes the script engine with a specific languageId. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungThis 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.ValuebooleanevaluateBooleanExpression(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.ContextReturns the current polyglot context This method implements a lazy initialization of the context.voidSets the value of a member using an identifier.
-
Felddetails
-
DEFAULT_LANGUAGE_ID
- Siehe auch:
-
INVALID_SCRIPT
- Siehe auch:
-
-
Konstruktordetails
-
RuleEngine
public RuleEngine()This method initializes the default script engine. -
RuleEngine
This method initializes the script engine with a specific languageId.- Parameter:
scriptLanguage-
-
-
Methodendetails
-
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- Gibt zurück:
-
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).- Parameter:
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- Parameter:
documentContext- optional workitem context- Gibt zurück:
- boolean
- Löst aus:
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
- Parameter:
workitem- optional document contextevent- optional bpmn event context- Gibt zurück:
- evaluated result instance
- Löst aus:
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;- Parameter:
engine-- Gibt zurück:
- ItemCollection holding the item values of the variable or null if no variable with the given name exists or the variable has not properties.
-