We presume we want to calculate a discount for people travelling from the US to an airport in the US or an airport in another region. Based on the age and/or the destination region of the traveller a discount is given.
For the processing of the data I use the Pentaho ETL tool (PDI - Pentaho Data Integration)
This is what the transformation looks like:
The second stream going downwards from the "Rule Engine" step (an optional stream) will output the detailed results of all rules.
Here is what the sample data from the "Data Grid" step looks like, including the "discount_percent" field. This is the data that arrives at the "Rule Engine" step.
To define the business logic a free web based application is available. The Business Rules Maintenance Tool. It allows to define complex business logic and actions that are executed based on the results. Because the rules and actions are defined independant fron your IT process (the ETL process in this case), the IT logic and the business logic is separated from each other. And thus if one of them changes, the other part does not have to be touched. A clear separation of responsibilities between the IT and the business.
Here is the business logic to calculate discount percentages:
- All travellers under the age of three travel for free. 100% discount.
- All travellers at the age of 50 or above years and travelling to Europe get a 25% discount.
In the screenprint below you can see two rule groups defined. These are the two definitions of the business logic listed above. Each rulegroup then contains the rules as they are described in the business logic.
The rule is very easy. It is just one rule checking if the "age" field contains a value that is smaller than three and if so, the "discount_percent" field is set to "100".
And now you can run the ETL. The rule engine will check the data and execute the actions as appropriate according to the data. Here is the screenprint of the results of the rule engine and after they passed the "Calculator" step:
As always: I welcome all comments or questions. All tools - the rule engine, the web application and the transformation step are open source and free of use. There is documentation available and the tools are all already used in production environments.
Everything is available for your download at Github: http://github.com/uwegeercken.