Task 3: Authoring rules

You write an action rule and import other rules for your rule project.

About this task

As a developer, you write the initial business rules. You want to enable business users to write and edit business rules in a web environment.

You create an action rule, and then you import the rest of the rules for your project. An action rule states the actions to take under certain conditions. You write the following rule, which is based partly on the vocabulary that you created earlier in this tutorial:

if
  the amount of 'the loan' is more than 1,000,000
then
   add "The loan cannot exceed 1,000,000" to the messages of 'the loan';
   reject 'the loan' ;

Step 1: Creating an action rule

You create the action rule that rejects any loan request that has an amount that is greater than 1,000,000.

Procedure

  1. In Rule Designer, in the Author part of the Operation Map, click Add action rule.
    Tip: You can also right-click the validation package in the Rule Explorer and click New > Action Rule.
  2. In the Package field, type validation, and in the Name field, type maximum amount.
  3. Click Finish. The Intellirule editor opens.

Results

You created an action rule file and opened Intellirule, a text editor for writing and editing business rules.

Step 2: Completing the action rule

You use the code completion menu in Intellirule to complete the action rule. You must create the parts of the rule, and use the completion mechanism to select phrases from a list of rule fragments to author the rule.

Before you begin

Ensure that Rule Designer is running in American English. Check that the locale property of the maximum amount rule is set to en_US.

Procedure

  1. In the Intellirule editor, type if, and then press Space. The Content Assist box opens:
    Image shows the Content Assist box.

    Select terms and phrases from the menu to compose the following expression:

    if the amount of 'the loan' is more than 1,000,000
    
  2. On the next line, type then, press Space, and then press Ctrl+Shift+Space to activate the tree view of the completion menu. The tree view displays possible phrases to select for your rules.
  3. In the tree view, type message to display only terms and phrases about messages:
    Image shows possible phrases for your rule.
  4. Double-click add <a string> to the messages of <a loan> to insert it, and then use the Content Assist box to finish building the following expression:
    add "The loan cannot exceed 1,000,000" to the messages of 'the loan' ;
    
    Important: You must add a semicolon (;) to the end of the line.
  5. If you are still in the Content Assist box, press Esc.
  6. Press Enter to create a new line, enter a space, and then write the following statement. You can use the Content Assist box:
    reject 'the loan' ;
    
  7. Press Ctrl+Shift+F to format the rule.

    The rule looks as follows:

    if
       the amount of 'the loan' is more than 1,000,000
    then
       add "The loan cannot exceed 1,000,000" to the messages of 'the loan';
       reject 'the loan' ;
    
  8. Save your work and close the Intellirule editor.

Results

You created the business rule for an action rule by using Intellirule.

For more information about using the rule editors, see Working with action rules.

Step 3: Importing remaining rules

You add the rules that determine whether a borrower is eligible for a loan. In this step, you import the eligibility rules into your rule project.

Procedure

  1. Click File > Import > General > File System, and then click Next.
  2. In the From directory field, click Browse and select <InstallDir>/gettingstarted/DecisionServer/answer/Miniloan Service, and then click Select folder.
    Note: Ignore the message There are no resources currently selected for import. The Eclipse message prompts you to do the following action.
  3. The Miniloan Service folder opens in one of the panes in the Import wizard. Expand the folder to Miniloan Service/rules and select the check box next to eligibility.
    Tip:

    Mac OS users cannot expand folders when importing rule projects. To see the subdirectories:

    1. Click the Browse button next to the From Directory text box.
    2. Select the eligibility folder to import it.
    3. Click Open.
  4. Optional: Click eligibility, and then clear the .rulepackage check box.
    Your project does not need the .rulepackage file:
    Image shows the Import wizard.
  5. In the Into folder field, click Browse, select my decision service, and then click OK.
  6. Under Options, select the Overwrite existing resources without warning option:
    Image shows options in rule import wizard.
  7. Click Finish.

Results

The eligibility rules are now in your project in the Rule Explorer.

Step 4: Viewing the imported rules

You view the imported rules in your project.

Procedure

  1. In the Rule Explorer, expand eligibility and double-click the rules to review them:
    minimum credit score

    Rejects the loan if the credit score is too low.

    minimum income

    Rejects the loan if the income is too low for the yearly repayments.

    repayment and score

    Rejects the loan based on various values of the debt-to-income ratio and credit score. As a decision table, it represents rules that share conditions and actions. Each row in the table represents a rule. Place your cursor over the number of a row to view the corresponding rule as hover help.

    Note: Rows with no actions display a warning about invalid or incomplete rows. These rows fill gaps in the table, and they are ignored when you run the project.
  2. Double-click the miniloan ruleflow to open it.
  3. In the Ruleflow Editor, double-click the eligibility task.
  4. In the Properties view, open the Rule Selection tab, and expand the eligibility package:
    Image shows the rules that are in the eligibility task.

    By default, all the rules are used when the task is run by the rule engine.

  5. Close the Ruleflow Editor.

What to do next

You created rules and defined the ruleflow to run them, and you used ruleset parameters as data to be processed by the ruleset. In the next task, you test and debug your rules.