Once these rules have been evaluated, an underwriting decision needs to be made based on the outcome. The following rules from the Decision.drl are used:
rule "Underwriting decision" when $loanApp : (LoanApplication(affordabilityFlag == Flag.NOT_AFFORDABLE) or LoanApplication( feedbackMsgSize > 0)) then $loanApp.setStatus(Flag.FAILED); end
Once all facts are inserted into the working memory, where they may be modified or retracted, the rule engine will find all possible matches for the facts. All candidate rules found during this matching stage are added to the rule engine's agenda. The agenda manages the execution order of these conflicting rules using a conflict resolution strategy. Conflict resolution is required when there are multiple rules on the agenda that are candidates for execution. The rules that are candidates for execution are examined to determine the next set of rule actions to execute based on a predetermined resolution scheme. Since firing a rule may affect the state of the working memory, the rule engine needs to know in what order the rules should fire.
Drools uses different strategies for conflict resolution (please refer to the Drools manual for an in-depth discussion). For this article we use salience, which is the most-used strategy. For this strategy, the rule author specifies that a particular rule has a higher priority (the higher salience rule) than the other matching rules. The highest priority rule is picked from all the matching rules.
When writing and authoring rules, one shouldn't make an assumption that the rules will fire in any particular order or follow some sort of flow. This minimizes the need to resort to any of the conflict resolution strategies described above.
Let's illustrate how conflict resolution is applied to the affordability assessment example described earlier:
rule "Income multiples" salience -3 when Borrower( $grossIncome : grossIncome ) Property( value > (new Double($grossIncome.doubleValue()*3))) $loanApp : LoanApplication() then $loanApp.setAffordabilityFlag(Flag.NOT_AFFORDABLE); end rule "Affordability Model" salience -4 when Borrower( $affordableLoanAmount : affordableLoanAmount ) Property( value > (new Double($affordableLoanAmount.doubleValue()))) $loanApp : LoanApplication() then $loanApp.setAffordabilityFlag(Flag.NOT_AFFORDABLE); end
To make an affordability assessment, lenders can apply either the income multiples rule or use the affordability model rule. The application of the affordability model rule may result in a value that exceeds the value obtained from the income multiple rule. When this happens, lenders usually will disregard the affordability model rule and make their final affordability assessment from the income multiple rule. This is accomplished in Drools by giving the income multiple rule a higher salience value.
Testing the Mortgage Underwriting Example
The example was tested using JBoss Drools 3.0.4 and JDK 1.5. A run of the JUnit test displays the following results:
Testing successful application ============================= Feedback message size=0 Affordability Flag=AFFORDABLE Underwriting Decision=PASSED Testing all feedback messages ============================= Property should be built after 1965 Type of property should be Owner Occupied Credit score should be greater than 600 Borrower minimum age should be 18 Loan to value ratio should not be greater than 80 Loan Amount should be between $100,000 and $400,000 Feedback message size=6 Affordability Flag=NOT_AFFORDABLE Underwriting Decision=FAILED
A feedback report can be created out of this data and displayed to the lender for further analysis.
In this article, I have shown how the Drools rule engine can be used to abstract complex business rules in a service that can be part of a larger enterprise service framework. A service that automates mortgage underwriting decisions was used as a case study; the patterns used to implement this service using Drools can be applied to many other problem domains that are well-suited to a rules-based approach. The article highlights through a real-world example important features of the Drools rule engine: externalization of rapidly changing business policies using rule-based programming, runtime evaluation of rules, and conflict resolution. The article did not cover deployment considerations or change-management issues.
- Sample code for this article
- Drools documentation library
- "Getting Started With the Java Rule Engine API (JSR 94)"
- JSR 94: JavaTM Rule Engine API
- JUnit test framework
Birali Hakizumwami is currently working as an application architect.
Return to ONJava.com.
Error when running JUnit test
2008-12-01 19:32:12 emas [View]
Storing the Drool Rules in a database
2008-04-19 07:53:30 firstname.lastname@example.org [View]
Problem in running Sample Code
2008-03-20 05:09:41 Vishal Deshmukh [View]
How to deal with the db access in Rule Engine Solution
2007-03-02 00:13:17 FoxFromChina [View]
Big Plus for testing, minus for console outputs in tests
2007-01-25 00:45:39 klausikm [View]
2007-01-21 04:32:42 dlinsin [View]
WebObjects: D2* technologies
2007-01-18 21:49:37 Josh Paul | [View]
other related O'Reilly Articles
2007-01-18 04:24:19 Paul Browne | [View]