Integrating a Rules Engine into ADempiere

From ADempiere
Jump to: navigation, search
This Wiki is read-only for reference purposes to avoid broken links.


As the influence of business solutions increases, the complexity of business procedures and the number of different cultures utilising them gets to a higher ratio than ever before, thus demanding the designers and developers constantly adapting the solution to customers' needs. An approach to solve these difficulties will be introduced here, in order to lower the ADempiere life cycle costs.


While companies and organisations find their key to success and survival in rapidly adapting to environment changes and customers' needs, which both will be called as business rules (BR), the traditional software development style has shown inability to handle such constant and urgent needs or at best doing them at a high cost level, hiring several developers and experts to cover the changes, locking the business rules management down to some highly technical and complex languages and tools. The situation gets even worse when considering the fact that ADempiere is becoming more popular and is being localised to many different cultures, requiring partners to customise the solution to their own culture's needs, procedures and laws.
The only solution to this problem is using tools that allow domain-experts, not developers, change the logic by which the business procedures are handled, using a simple and easy to use and learn syntax or even using a GUI. This is where a rules engine (RE) steps in.

What is a RE?

A RE is an expert system, a complete Turing machine, from the academic view. From the practical view it is a set of libraries and utilities which allow the business domain-expert to define, modify or remove BRs, him/herself or even define some language specific to a business domain to express rules and conditions more elegant and easy to understand. Using complex and robust pattern matching algorithms they provide the solution with an inference engine which is able to look at the data as facts and analyse it via the rules the end-user defines and finally infer which action to do as the conclusion.
Everything falls into 2 categories, from the RE perspective:

  • Facts: The application data which varies from what the user enters in a field to the data stored in DB, eg. AD_Role_ID. They match against rules to form conclusions.
  • Rules: They define the logic and how facts should be analysed. Each rule has two parts known as left hand side (LHS) and right hand side (RHS). LHS contains the conditions and RHS defines the actions. A typical representation of a rule is as follows:

Facts may change during the inference process, causing the re-evaluation of rules using the newly modified facts.

Expected feature-set of a RE

With a look to the future, in order for a RE to efficiently integrate into ADempiere, it must have the following feature-set (in order of priority):

  • It must be GPL compatible, in order to avoid lawsuits :-)
  • To adapt ADempiere to standards, it must be JSR-94 compliant. (JSR: Java Specification Requests)
  • It is supposed to have a good performance, meaning that it has a reasonable memory consumption and an acceptable response time.
  • It must accept rules as a decision table in some convenient and popular format such as XLS, CSV or XML.
  • It must be able to be integrated into WF managment system, verifying the soundness of WF transitions.
  • It must be able to allow the end user define domain specific languages (DSL) to simplify the usage and increase the readability of rules.
  • It should provide domain-experts with a simple and straight-forward syntax to sharpen the learning curve. In other words, it must be easy-to-use.
  • It must be able to allow the end user define, modify or remove rules on the fly, thus having a dynamic rule set.
  • It should offer end users a GUI to define, modify or remove rules.
  • It is supposed to be usable in an SOA environment, eg. as a service.

RE applications inside ADempiere

  • It handles after/before save/delete methods, thus verifying logical integrity of data which is one of the most important issues the RE will handle.
  • It shows information/warning/error messages back to user and gets the user's choice as input. The user must be informed about the conclusions and actions RE makes.
  • It manages callouts which then may be made on the fly with no need to compile and deploy them.
  • It handles dynamic validation rules, resulting in more efficient and accurate validation rules.
  • It manages display logic expressions which then may be more sophisticated, covering a broader range of needs.
  • It handles alert rules which then may be more sophisticated, covering a broader range of needs.
  • It does the logic behind ADempiere modules such as Payroll and Accounting. With a RE as the mastermind behind the modules, the most complex logical problems will be solved easily.
  • It does logic behind calculations in decision to price, discount schema, commission, material replenishment, routing the request, etc.
  • It does performance analysis which leads to more complex queries and analysis, making the dashboard more useful and creative.

Caveat Emptor

One should not forget that each advantage gained, brings some disadvantages and problems into existence and so does RE integration. Below is a list of the disadvantages a RE may cause:

  • Sophistication of the ADempiere internals.
  • Performance issues as another layer will be added to the current architecture.


  • Suppose there is a rule for discount to customer in case s/he is VIP. It may be written as follows:
 rule "Discount to Customer VIP"
       getC_BP_Category_ID() = 100001
  • Another example might be this:
 rule "Message to Supplier with PrePayment"
       getPrepayment() > 0
       DisplayMsg("Supplier have Prepayment [Please avoid payment again]");

RE Library Files for Testing

(File space provided by Panji Alam)

What you need before u try :

From Bahman Email :
I, personally, put the files in extend/src/org/adempiere.


  • JBossRules Documentation [1]
  • ILOG JRules White papers [2]
  • Wikipedia [3]

See Also