< Previous | Next >

Task 2: Orchestrating

In this task, you use a ruleflow to specify the order in which rules are executed.

A ruleflow is a way to organize the sequence in which rules are processed by the rule engine. In Rule Designer you orchestrate rule execution using a ruleflow.

Orchestrating the rule execution using a ruleflow

Time This task should take you about 15 to 25 minutes to complete.

Step 1: Create rule packages

The Miniloan application first validates the data about the loan and the borrower, and, if the data is valid, assesses whether the borrower is eligible for the loan.

When defining the flow of execution, you organize your rules into packages that contain related rules. In this case, you have a package of rules related to validation, and another related to eligibility. You then treat these rule packages as tasks in the ruleflow.

To create a rule package:

  1. In Rule Designer, in the Orchestrate part of the Rule Project Map, click Add rule package.
    Tip: You can also right-click the my rule project/rules folder in the Rule Explorer and click New > Rule Package.
  2. In the New Rule Package wizard, enter validation in the Package field, and then click Finish.

    The new validation rule package opens in the Rule Explorer.

  3. Create another package named eligibility.

Your rule project now contains two packages for storing your rules:

New rule packages in the Rule Explorer

Step 2: Create the ruleflow diagram

To define the high level flow of execution of business rules, you create a ruleflow. A ruleflow consists of rule tasks and logical links between these tasks. You need two tasks in the ruleflow: one for validation and one for eligibility.

To create a ruleflow:

  1. In the Orchestrate part of the Rule Project Map, click Add ruleflow.
    Tip: You can also right-click the my rule project/rules folder in the Rule Explorer and click New > Ruleflow.
  2. In the New Ruleflow wizard, make sure that the Source folder field is set to /my rule project/rules, and that the Package field is empty.
  3. In the Name field, type miniloan.
  4. Click Finish.

    The ruleflow editor opens, and enables you to construct the flow of tasks graphically. You specify how tasks are chained together: how, when, and under what conditions they will be executed.

  5. Click Ruleflow start node Create a start node and then click in the ruleflow editor.

    The ruleflow start node is displayed in the ruleflow editor.

  6. Click Ruleflow end node Create an end node and then click in the ruleflow editor.

    You now have a start node and an end node for your ruleflow.

Step 3: Define rule tasks

To define the ruleflow, you select the rule packages to include, and then create the transitions between them.

To define the rule tasks:

  1. Drag the validation rule package from the Rule Explorer and drop it into the ruleflow editor.

    The validation rule package becomes a rule task in the ruleflow. By dropping this package into the ruleflow editor, any rule that you create in the package will be part of the execution, unless you specify otherwise.

  2. Drag the eligibility rule package from the Rule Explorer and drop it into the ruleflow editor.
  3. Click Create a transition button Create a transition and create the following transitions (shown as arrows) by clicking the first item and then clicking the second item:
    1. The start node and the validation task.
    2. The validation task and the eligibility task.
    3. The eligibility task and the end node.
    4. The validation task and the end node.

      Some errors are displayed on the transitions to indicate that the conditions are missing:

      Ruleflow errors
  4. Click Create a transition button Create a transition to deselect the transition tool.
  5. Click Layout All Nodes button Layout All Nodes to format the ruleflow diagram.
  6. Save your work.

Step 4: Define the main transition

You can define conditions on transitions in the ruleflow. In this ruleflow, you set a transition condition so that rules in the eligibility package are run only when data is validated.

To define the main transition:

  1. Click the transition from validation to eligibility.

    The Properties view opens and shows the condition for this transition.

    Tip: If you cannot see the Properties view, click Window > Show View > Properties to open the Properties view.
  2. In the Label field, type data approved.
  3. Make sure Use BAL for transition condition is selected, to write the condition using the Business Action Language (BAL).
  4. In the text area, type a space to display the Content Assist box, and double-click the items to form the following statement: 'the loan' is approved.
    Tip: You can also type the statement directly in the text area.

    The Properties view should look like this:

    Properties view: Condition page

    The transition from validation to the end node is automatically set to else.

  5. Save the changes.

    Your ruleflow should now look like this:

    Ruleflow diagram

Step 5: Define the final action

You can also define a final action to display a message at the end of the execution.

To define the final action:

  1. Click the end node.

    The Properties view lets you enter the final action.

  2. In the Final Action section, make sure Use BAL for action is selected.
  3. In the text area, type a space to display the Content Assist box, and enter the following final action:

    print the approval status of 'the loan' ;

    Note: You must add a semicolon (;) at the end of the line.

    At execution time, this final action displays a message in the Console indicating the status of the loan at the end of rule execution.

  4. In the ruleflow editor, click outside the diagram, and in the Properties view, make sure that the main flow task is set to true.
  5. Save your work and close the ruleflow editor.

You have now defined the flow of execution. In the next task, you will write an action.

< Previous | Next >