Building Enterprise Services with Drools Rule Engine
Pages: 1, 2, 3, 4, 5
Let's highlight some important methods from this class:
-
readRule: Loads all the rules stored in the fileruleFileNameand returns aRuleBaseobject that contains the rule package. -
doRun: Creates a new instance ofWorkingMemory, usesassertObjectto place known facts (LoanApplication,Borrower, andPropertyobjects) into the memory, and calls thefireAllRules()on theWorkingMemoryclass. We are using theRuleBaseobject returned by thereadRules()method to create a newWorkingMemoryfor each session, and then discard it when finished.
Underwriting Rules Using Drools .drl Files
We will start by describing the underwriting process and policies and how to define rules from these policies. Two .drl files will be provided: Underwriting.drl contains the underwriting policy rules and Decision.drl contains the underwriting decisions rules. The underwriting process typically has two stages:
- Assessment of the applicant's ability to repay:
-
Two considerations go into assessing whether an applicant will be able to repay.
-
Policy rules surrounding the applicant and loan, such as the minimum criteria that the applicant must satisfy to qualify for the loan. The criteria may cover, for example, minimum and maximum age of applicant, unacceptable credit history, minimum and maximum loan amounts, maximum loan-to-value ratios (LTVs), maximum income multiples, and thresholds or cut-off points for the credit score. Typically, these criteria are specified by the lender.
-
Affordability assessment: The affordability model service can provide this type of service to assess whether the applicant can afford the loan applied for.
These rules can be written in Drools Underwriting.drl as:
rule "Age verification" when Borrower(age < 18) $loanApp : LoanApplication() then $loanApp.addFeedbackMessage(FeedbackMessages.MIN_AGE); end rule "Credit score" when Borrower(creditScore <= 600) $loanApp : LoanApplication() then $loanApp.addFeedbackMessage(FeedbackMessages.MIN_CREDIT_SCORE); end rule "Loan Amount limits" when $loanApp : (LoanApplication(loanAmount <= 100000.0) or LoanApplication(loanAmount >= 400000.0)) then $loanApp.addFeedbackMessage(FeedbackMessages.LOAN_AMOUNT_LIMITS); end rule "Maximum Loan-to-value ratio" when $loanApp : LoanApplication(loanToValueRatio > 80.0) then $loanApp.addFeedbackMessage(FeedbackMessages.LTV); end 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 -
- Assessment of the adequacy of the property:
Two considerations go into assessing the adequacy of the property.
-
Policy rules surrounding the property, such as the minimum criteria that the property must satisfy in order for the loan to be granted. The criteria may include, for example, type of property, construction method or materials, and date of construction. These criteria are typically specified by the lender, but may reflect the requirements of insurers.
-
Valuation of the property: The property valuation service can provide this valuation by using different methods to calculate the property value offered as security in a mortgage application.
These rules can be written in Drools Underwriting.drl as:
rule "Property type" when Property(purpose != Flag.OWNER_OCCUPIED) $loanApp : LoanApplication() then $loanApp.addFeedbackMessage(FeedbackMessages.PROP_TYPE); end rule "Property age" when Property(yearBuilt < 1965) $loanApp : LoanApplication() then $loanApp.addFeedbackMessage(FeedbackMessages.PROP_YEAR_BUILT); end -