Skip to content
Amogh Shah edited this page Oct 21, 2023 · 3 revisions

Known Vulnerabilities Support

How to define rules in Simple Rules Engine?

1. Define Namespace:

Namespace is nothing but keeping same nature of rules together. A namespace can have many rules with unique sequence number. Namespace name should be unique within an app. To execute RuleEngine you have to fetch the namespace from DB and give it to RuleEngine, rule engine will fetch all rules defined within that namespace and execute it one after another.

2. Define Rules with a Namespace:

Once you defined a Namespace now you can create rules within it. Rules have the following properties:

  • Name (required): any string name to identify the rule in a better way.
  • Description (optional): any string which will describe about the rule.
  • Sequence (required): a number. This should be unique within the selected namespace. Within a namespace multiple rules can not have same sequence number, and if duplication in sequence number is found then only first rule will be considered by Rules Engine.
  • Condition (required): set of conditions that should be satisfied in order to apply the rule (or to execute action defined). You can also use Mendix Expression Language (MEL to define conditions by using Mendix object passed as input to RuleEngine
  • Action (required): set of actions to perform when conditions are satisfied. By using Mendix Expression Language (MEL) we can modify the input/output Mendix objects and can also call a Microflow.

How to execute RulesEngine?

To execute rules you can use "RulesExecutor" JavaAction from __UseMe folder of the module. This JavaAction takes 3 inputs:

  • RulesNamespace (required): A namespace have set of rules defined, to execute those rules you have to fetch and pass RulesNamespace object and engine will fetch all the rules defined within it.
  • InputData (optional): An Mendix object as input to engine, on which rules conditions will be executed
  • OutputData (optional): An Mendix object as output to engine, on which rules actions will be executed. By default, InputData object can also be used in actions.

This JavaAction returns nothing. RulesEngine will fetch all the rules defined within passed namespace, it will also sort all the rules by Sequence number. Keeping lower sequence number at first to execute and so on. If multiple rules shares the same sequence number than only the first rule of the same sequence number will be considered and others will be skipped (a warning message will be seen in console if such case happens).

1. How RulesEngine executes the rules?

As this is a simple, stupid rules engine, so there is no complex logic written. Rules are executed in following manner:

  • Rules are sorted by sequence number, the lowest sequence number will be the first and so on.
  • Rules are always executed one after the another
  • Condition defined in a rule is evaluated first, if it is satisfied then it's corresponding action is executed; else if condition is not satisfied then it's action won't be executed and moved to next rules if any.
  • In case of any exception while evaluating Condition or executing Action, rule engine will throw an error and stop execution of any further rules. Though any modifications done on InputData/OutputData won't be rolled back.
  • While executing Action or Condition on Mendix object current Mendix context will be used and if no context found (Is this even possible?) then system context will be created.
Clone this wiki locally