Search Tutorials


Getting started with Drools Decision Table using Drools 6 Simple example | JavaInUse



Drools Tutorials- Understanding Drools Decision Table using Simple Example

Overview

In previous chapter we implemented a drools project for a jewellery shop to give discount according to the type of jewellery. The rules for this discount calculations we had written in a drl file. In this chapter we implement the same rules using the Drools Decision Table.Drools Decision Tables are excel based decision tables

JBoss Drools - Table of Contents

JBoss Drools Hello World JBoss Drools Hello World-Stateful Knowledge Session using KieSession JBoss Drools- Understanding Drools Decision Table using Simple Example Understand Drools Stateful vs Stateless Knowledge Session Drools Tutorials- Backward Chaining simple example Drools Tutorials- Understanding attributes salience, update statement and no-loop using Simple Example Drools Tutorials- Understanding Execution Control in Drools using Simple Example Drools Tutorials- Integration with Spring MVC Drools Tutorials- Integration with Spring Boot

Video

This tutorial is explained in the below Youtube Video.

Why use Drools Decision Table-

We had stated in a previous chapter that the main advantage of Drools is that the logic can also be changed by a non technical person. But if we look at the .drl file, any modification will also require technical knowledge. As the .drl becomes more complicated the more difficult it will become for non technical persons like Business Analysts. Also frequent changes to the drools file is cumbersome.Hence this format, decision tables, is a very good option to use where something is going to be changed frequently by non-programmers.

Lets Begin

Here we will be modifying the project we created in previous tutorial. In the pom.xml we will have to add an additional dependency for drools decision table-
<dependency>
    <groupId>org.drools</groupId>
     <artifactId>drools-decisiontables</artifactId>
     <version></version>
</dependency>
	

The only other change will be we will delete the rules.drl file and instead create a rules.xls in its place.<>
drools7_1

Our Rules.xls is as follows-
  • RuleSet attribute- which says that this excel is a rule set. We have set this as rules.
  • Import attribute-Imports all the Java classes to be used for rules. In our case the Product class.
  • Notes-For giving the description of the drools decision table.
  • RuleTable DiscountCalculation is name of RuleTable below
  • Next row has CONDITION and ACTION columns, as the names indicate they are used for mentioning on which conditions what action is to be taken. Under condition column have specified the condition that depending on type of product set the discount which is specified under the actions column.


drools7_2

This is the only change required. Run the DroolsTest.java class as before.
drools1_1

Download Source Code

Download it - Drools Decision table example

JBoss Drools Hello World
JBoss Drools Hello World-Stateful Knowledge Session using KieSession
Understand Drools Stateful vs Stateless Knowledge Session
Drools Tutorials- Backward Chaining simple example
Drools Tutorials- Understanding attributes salience, update statement and no-loop using Simple Example  
Drools Tutorials- Understanding Execution Control in Drools using Simple Example
Drools Tutorials- Integration with Spring
Drools Interview Questions
Drools-Main Menu.