Task 1: Designing the main rule project for the decision service

You create a vocabulary so that business users can write business rules in a natural language. You use Rule Designer to create the vocabulary from a Java™ object model.

About this task

As a developer, you want to create a business rule vocabulary that business users can use to write and edit rules. The vocabulary must consist of terms that are familiar to the business users. The process of creating a vocabulary is called verbalization.

In this task, you create a business object model (BOM) that is based on an object model that is defined in a Java project. The following diagram shows how the classes and members of the BOM relate to the vocabulary that is familiar to the business users.

Diagram shows the design of the business object model.

Step 1: Starting Rule Designer and importing the Java object model

Rule Designer is an Eclipse development environment for business rule applications. You can develop both rule projects and Java projects in this environment.

Before you begin

The file from which you copy rules for this tutorial is available in only American English (en_US). To use Rule Designer in American English, add the following lines to <InstallDir>/eclipse/eclipse.ini before -vmargs, where <InstallDir> is the installation directory for your instance of Rule Designer:

-nl
en_US

Procedure

  1. Start Rule Designer (see Preparing to develop rule applications).
  2. Select a workspace. When the Workspace Launcher window opens, it shows your default workspace. If the workspace is not empty, switch to a workspace that is empty. If you want to create a workspace, change the name of the workspace in the Workspace Launcher, and click OK.
    Tip: If you do not see the Workspace Launcher window when you start Rule Designer, you can change the workspace by clicking File > Switch Workspace.
  3. Optional: If the connection wizard opens, connect to the cloud portal:
    1. Enter the URL for your cloud portal in the following format: https://<vhostname>.bpm.ibmcloud.com/
    2. Click Connect and enter your cloud credentials.
    3. Click Finish.
  4. Close the Eclipse Welcome page to see the Rule perspective.
    If the Rule perspective is not open, click Window > Perspective > Open Perspective > Other, select Rule, and click Open.
  5. Click File > Import. In the Import wizard, expand General > Existing Projects into Workspace, and click Next.
  6. Choose Select root directory, browse to <InstallDir>/odm-cloud-getting-started-master, and click OK. InstallDir is your directory for the files downloaded from GitHub (see Preparing and removing the tutorial project).
  7. Make sure that miniloan-xom is selected, and deselect Miniloan Service.
  8. Click Finish to import the project.

Results

The Rule perspective contains various views that you learn about in this tutorial, such as the Rule Explorer and the Decision Service Map.

The Rule Explorer shows miniloan-xom, which contains the execution object model (XOM) that you use in the tutorial. The XOM is the model against which you run rules. It references the application objects and data, and is the base implementation of the BOM (see Overview: BOM and execution object model (XOM)). The miniloan package holds the Borrower and Loan Java classes.

Notice the Rule Project Map tab. When you work on a decision service, the Rule Project Map tab shows the Decision Service Map, which contains the different steps for making and deploying a decision service. You can use the Decision Service Map as a guide to the creation process for the decision service. If the Decision Service Map is not displayed, click Window > Show View > Rule Project Map to open it.

The following image shows the Rule Project Map in the tab bar.

Image shows the Rule Project Map tab

Step 2: Creating a rule project for a decision service

In Rule Designer, you store the business logic of your application in a decision service. A decision service can consist of a main rule project and optional standard rule projects to split the logic of your business application into different parts. Each rule project can contain rule artifacts, a BOM, a vocabulary, and a reference to the XOM. In a rule project, you can manage, build, and debug the items that comprise the business logic of your application. In this tutorial, you create only a main rule project to simplify the logic of the application.

Procedure

  1. Ensure that you are in the Rule perspective, and the Rule Project Map is in the bottom tab bar.
  2. In the Decision Service Map in the Rule Project Map tab, click Create main rule project.
  3. Ensure that Main Rule Project is selected under Decision Service Rule Projects, and click Next.
  4. In the Project name field, type my decision service.
    Use the default location.

    The name my decision service is used throughout the tutorial. You can use a different name to avoid conflicts with other projects when you publish the decision service. For example, you can prefix my decision service with your initials.

  5. Click Finish.

    The Rule Explorer displays my decision service.

    The rule project contains empty folders. You use the rules and bom folders to store your rules and BOM.

Step 3: Importing the XOM into your rule project

You import the XOM from the Miniloan Java project.

Procedure

  1. In the Rule Explorer, click my decision service.

    The Decision Service Map displays the steps to follow to design your rule project.

  2. In the Decision Service Map, click Import XOM.
  3. In the Import XOM dialog, ensure that Java execution object model is selected, and click OK.
  4. In the Projects tab, select miniloan-xom and click Apply and Close:
    Image shows the required Java project.

Step 4: Creating the business object model

Before you can create and edit business rules, you must create a BOM. You can create a BOM manually or automatically by parsing your XOM. You use Rule Designer to parse the Java classes in the XOM, and create the BOM from their methods and properties. Then, you can write rules that use the verbalized terms that are contained in the BOM.

Procedure

  1. In the Decision Service Map, click Create BOM.
    Tip: You can also right-click the bom folder in the Rule Explorer and click New > BOM Entry.
  2. In the New BOM Entry wizard, in the Name field, type miniloan.
  3. Ensure that Create a BOM entry from a XOM is selected, and then click Next.
  4. In the Choose a XOM entry field, click Browse XOM, select platform:/miniloan-xom, and then click OK.
  5. Under Select classes, select the miniloan package. Selecting the package selects all the classes in the package.
    Image shows the miniloan package in the BOM Entry dialog.
    The miniloan package contains the Borrower and Loan classes.
  6. Click Next.
  7. On the BOM Verbalization page, you must select the All Methods check box.
    The All Methods check box ensures that all the methods are verbalized in addition to the elements already selected.
    Selecting the All Methods check box.
  8. Click Finish.
  9. In the Rule Explorer, double-click bom > miniloan to open the BOM Editor, and take a moment to look at the BOM.

    In the BOM Editor, expand the miniloan entry:

    Image shows the expanded miniloan BOM entry.

    In your BOM, you now have two classes that are equivalent to the XOM classes Borrower and Loan.

  10. Double-click the Loan class to open it in the BOM editor.

    All the Java members and methods are converted and assigned a default verbalization.

  11. In the Members section, double-click the addToMessages(String) method.

    The BOM editor switches to the Member tab. In the Member Verbalization section, you can see that the verbalization of this method is add a string to the messages of a loan:

    Image shows the method verbalization in the Member Verbalization section

    The verbalization is also used in the Rule Editor.

  12. Close the miniloan tab to close the BOM Editor:
    Image shows how to close the BOM Editor.

Step 5: Defining a decision operation

A ruleset is a runable package that includes rule artifacts and other elements. It contains a set of rules that can be run by the rule engine. You must define the contents of the ruleset and the parameters that allow the client application and the ruleset to exchange information. A decision operation includes all the settings that are needed to define the contents of the ruleset and its parameters.

Procedure

  1. In the Decision Service Map, click Add decision operation.
  2. In the New Decision Operation wizard, in the Name field, type my operation.
  3. Click Next.
    The Source Rule Project window opens.
  4. Ensure that my decision service is selected, and then click Finish.
  5. In the Decision Service Map, click Go to operation map.
  6. Select my decision service > deployment > my operation.dop, and click OK.
    Image shows the my decision service folder.

    The operation map opens and shows the different actions that you can do. The links in the map open different editors.

    Image shows the operation map.

Step 6: Designing the operation signature

Client applications interact with a ruleset by using input and output parameters. These parameters are defined in the signature of a decision operation. They are equivalent to Java method parameters. They are references that you can use when you write rules.

Procedure

To enable a decision to be made on the status of a loan, you create ruleset parameters for the borrower and the loan:

  • The borrower is an IN parameter. The value of the IN parameter is provided as input to the ruleset when run.

  • The loan is an IN_OUT parameter. The value of the IN_OUT parameter is provided as input to the ruleset when run, and can be modified by the ruleset and provided as output when the run completes.

  1. In the operation map, click Add variable set.
  2. In the New Variable Set wizard, in the Name field, type my parameters.
  3. Click Finish.
  4. Define the borrower parameter:
    1. Click Add.
      A new row is displayed with default values.
    2. In the Name column, type borrower.
    3. In the Type column, click the ... button, and then double-click the Borrower type in the Matching types box.

      The miniloan.Borrower type is displayed in the Type column.

    4. In the Verbalization column, type the borrower.
  5. Repeat step 4 to define the loan parameter:
    • Name: loan
    • Type: Loan
    • Verbalization: the loan

    Your variable set is shown as follows:

    Image shows the variable set.
  6. Click the Eclipse Save button to save your work, and close the my parameters variable set editor.
  7. In the Operation Map, click Bind variables.
  8. Expand my parameters in the Eligible variables part of the Decision Operation Signature editor:
    Image shows eligible variables.
    1. Drag borrower to the input parameters.
    2. Drag loan to the input-output parameters.

    The decision operation signature is displayed as follows:

    Image shows the parameters for the decision operation signature.
  9. Save your work, and close my operation.

What to do next

In the next task, you create a ruleflow to orchestrate how the rules run.