23 Using the Business Rule Service Component

This chapter describes how to use a business rule service component to integrate an SOA composite application with Oracle Business Rules. A business rule service component is also called a Decision component. You can add business rules as part of an SCA application or as part of a BPEL process.

This chapter includes the following sections:

For more examples of using Oracle Business Rules, see:

23.1 Introduction to the Business Rule Service Component

A Decision component, also called a business rule service component, supports use of Oracle Business Rules in an SOA composite application. Decision components support the following SOA composite usage:

23.1.1 Integrating BPEL Processes, Business Rules, and Human Tasks

You can create an SOA composite application that includes BPEL process, business rule, and human task service components. These components are complementary technologies. BPEL processes focus on the orchestration of systems, services, and people. Business rules focus on decision making and policies. Human tasks enable you to model a workflow that describes the tasks for users or groups to perform as part of an end-to-end business process flow.

Some examples of where business rules can be used include:

  • Dynamic processing

    Rules can perform intelligent routing within the business process based on service level agreements or other guidelines. For example, if the customer requires a response within one day, send a loan application to the QuickLoan loan agency only. If the customer can wait longer, then route the request to three different loan agencies.

  • Externalize business rules in the process

    There are typically many conditions that must be evaluated as part of a business process. However, the parameters to these conditions can be changed independently of the process. For example, you provide loans only to customers with a credit score of at least 650. This value may be changed dynamically based on new guidelines set by business analysts.

  • Data validation and constraint checks

    Rules can validate input documents or apply additional constraints on requests. For example, a new customer request must always be accompanied with an employment verification letter and bank account details.

  • Human task routing

    Rules are frequently used in the context of human tasks in the business process:

    • Policy-based task assignments dispatch tasks to specific roles or users. For example, a process that handles incoming requests from a portal can route loan requests and insurance quotes to a different set of roles.

    • Load balancing of tasks among users. When a task is assigned to a set of users or a role, each user in that role acquires a set of tasks and acts on them in a specified time. For new incoming tasks, policies may be applied to set priorities on the task and put them in specific user queues. For example, a specific loan agent is assigned a maximum of 10 loans at any time.

For more information about creating business rules in the Human Task editor of a human task component, see Section 25.3.7.2, "Specifying Advanced Task Routing Using Business Rules."

23.2 Introduction to Creating and Editing Business Rules

This section describes how to get started with business rules and provides a brief introduction to the main sections of Oracle JDeveloper that you use to design business rules.

23.2.1 How to Create Business Rules Components

You can add Business Rule components using the SOA Composite Editor.

To create a Business Rule component:

  1. Follow the instructions in Table 23-1 to start Oracle JDeveloper.

    Table 23-1 Starting Oracle JDeveloper

    To Start... On Windows... On UNIX...

    Oracle JDeveloper

    Click JDev_Oracle_Home\JDev\bin\jdev.exe or create a shortcut

    $ORACLE_HOME/jdev/bin/jdev


  2. Create a Business Rule service component through one of the following methods:

    As a service component in an existing SOA composite application:

    1. From the Component Palette, drag a Business Rule service component into the SOA Composite Editor.

    In a new application:

    1. From the Application Navigator, select File > New > Applications > SOA Application.

      This starts the Create SOA Application wizard.

    2. In the Name your application page, enter an application name in the Name field.

    3. In the Directory field, enter a directory path in which to create the SOA composite application and project.

    4. Click Next.

    5. In the Name your project page, enter a unique project name in the Project Name field. The project name must be unique across SOA composite applications. This is because the uniqueness of a composite is determined by its project name. For example, do not perform the actions described in Table 23-2.

      Table 23-2 Restrictions on Naming an SOA Project

      Create an Application Named... With an SOA Project Named...

      Application1

      Project1

      Application2

      Project1


      During deployment, the second deployed project (composite) overwrites the first deployed project (composite).

    6. Click Next.

    7. In the Configure SOA settings page, select Composite with Business Rule.

    8. Click Finish.

    Each method causes the Create Business Rules dialog shown in Figure 23-1 to appear.

    Figure 23-1 Create Business Rules Dialog

    Description of Figure 23-1 follows
    Description of "Figure 23-1 Create Business Rules Dialog"

  3. Provide the required details. For more information on providing Inputs and Outputs and on using the Import Dictionary option with this dialog, see Oracle Fusion Middleware User's Guide for Oracle Business Rules.

  4. Click OK.

23.2.2 Introduction to Working with Business Rules in Rules Designer

When you are working with business rules Oracle JDeveloper displays Rules Designer. For more information on the windows shown with Rules Designer, see Section 2.5, "Introduction to the Business Rules Designer".

23.3 Adding Business Rules to a BPEL Process

You can use a Decision component, also called a business rule service component, to execute business rules in a BPEL process.

23.3.1 How to Add Business Rules to a BPEL Process

You add business rules to a BPEL process using a Business Rule component. When you add a business rule component to a BPEL process you need to include input and output variables to provide input to the rules and obtain results back from the business rules.

A business rule component enables you to execute business rules and make business decisions based on the rules. To create a business rule component, also called a Decision component, you drag-and-drop a Business Rule from the component palette into the BPEL process.

To add a business rule to a BPEL process:

  1. Create a BPEL process service component. For more information, see Section 5.1, "Introduction to the BPEL Process Service Component".

  2. Expand the BPEL process. For example, expand the BPEL process to view receiveInput and callbackClient as shown in Figure 23-2.

    Figure 23-2 Adding A Business Rule to a BPEL Process

    Description of Figure 23-2 follows
    Description of "Figure 23-2 Adding A Business Rule to a BPEL Process"

  3. Select Business Rule from the BPEL Activities and Components section of the Component Palette and drag-and-drop a Business Rule into the position where the business rules are needed. For example, drag-and-drop a Business Rule between receiveInput and callbackClient, as shown in Figure 23-3.

    Figure 23-3 Drag-and-drop a Business Rule into a BPEL Process

    Description of Figure 23-3 follows
    Description of "Figure 23-3 Drag-and-drop a Business Rule into a BPEL Process"

  4. Oracle JDeveloper displays the business rule in the diagram. In the business rule area you can select an existing Oracle Business Rules dictionary or enter the name of a new dictionary to create. The Business Rule area includes a field to enter the business rule name. In the Name field enter a name. For example, enter GetCreditRating, as shown in Figure 23-4. If you previously created a dictionary, in the Dictionary field, select an existing dictionary.

    Figure 23-4 Business Rule Added to Auto Loan BPEL Process

    Description of Figure 23-4 follows
    Description of "Figure 23-4 Business Rule Added to Auto Loan BPEL Process"

  5. In the Business Rule area for the Business Rule Dictionary, click the Create Dictionary icon to display the Create Business Rules dialog.

  6. In the Create Business Rules dialog you do the following:

    • Specify a name for the Oracle Business Rules dictionary and a package name.

    • Specify the input and output data elements for the business rule. For example, for a sample Decision component named GetCreditRating, the input is a rating request document. The output is generated when you run the business rules, and for this example is a rating document. For example, in BPEL you can create two new variables, RatingRequest and Rating that carry the input and output data for the GetCreditRating rules.

    Enter a name for the Oracle Business Rules dictionary. For example, enter GetCreditRating, as shown in Figure 23-5.

    Figure 23-5 Adding GetCreditRating Business Rule Dictionary

    Description of Figure 23-5 follows
    Description of "Figure 23-5 Adding GetCreditRating Business Rule Dictionary"

Add inputs for business rule:

  1. In the Create Business Rules dialog, from the dropdown menu next to the Add icon select Add Input Variable... to create the input variable.

    This displays the Add Input Variable dialog.

  2. In the Add Input Variable dialog expand the Process folder and select the Variables folder immediately inside the Process.

  3. Right-click the Variables folder and from the dropdown list select Create Variable... as shown in Figure 23-6.

    Figure 23-6 Add Input Variable

    Description of Figure 23-6 follows
    Description of "Figure 23-6 Add Input Variable"

    This displays the Create Variable dialog.

  4. In the Create Variable dialog, in the Name field enter a value. For example, enter RatingRequest as shown in Figure 23-7.

    Figure 23-7 Create Variable Dialog

    Description of Figure 23-7 follows
    Description of "Figure 23-7 Create Variable Dialog"

  5. In the Create Variable Type area click the Browse Elements icon. Use the navigator to locate the schema element type for the input variable. For example, select the ratingrequest type. Add any needed types using the Type Chooser.

  6. Click the Import Schema File icon to import the schema. For example, import CreditRatingTypes.xsd. Also import any other required schema for your application.

  7. In the Type Chooser dialog, select ratingrequest and click OK.

  8. In the Create Variable dialog, click OK.

  9. In the Add Input Variable dialog, click OK.

Add outputs for business rule:

  1. In the Create Business Rules dialog, from the dropdown menu next to the Add icon, select Add Output Variable.... This displays the Add Output Variable dialog. Use this dialog to create an output variable. For example, create an output variable for GetCreditRating in the same way you created the input variable.

  2. In the Add Output Variable dialog select the scope by selecting the Variables folder under Process.

  3. Right-click and from the dropdown list select Create Variable.... This displays the Create Variable dialog.

  4. In the Create Variable dialog, in the Name field enter the output variable name. For example enter Rating.

  5. In the Create Variable dialog, in the Type area select the Browse elements icon and use the Type Chooser dialog to enter the type for the output variable. For example, expand the CreditRatingTypes.xsd and select the element type rating.

  6. In the Type Chooser dialog, click OK.

  7. In the Create Variable dialog, click OK.

  8. In the Add Output Variable dialog, click OK.

    This displays the Create Business Rules dialog, as shown in Figure 23-8.

    Figure 23-8 Create Business Rules Dialog with Input and Output Variables

    Description of Figure 23-8 follows
    Description of "Figure 23-8 Create Business Rules Dialog with Input and Output Variables"

Set options and create decision service and business rules dictionary:

  1. If you do not want to use the default service name, then select the Advanced tab and in the Service Name field enter the service name. For example enter the service name CreditRatingService.

  2. Determine if the Decision Component is stateful or stateless with Reset Session. For more information, see Section 23.3.5, "What You Need to Know About Decision Component Stateful Operation".

  3. In the Create Business Rules dialog, click OK. Oracle JDeveloper creates the Decision component and the dictionary and displays Rules Designer, as shown in Figure 23-9.

Figure 23-9 Rules Designer Canvas Where You Work with Business Rules

Description of Figure 23-9 follows
Description of "Figure 23-9 Rules Designer Canvas Where You Work with Business Rules"

For information on Rules Designer, see Oracle Fusion Middleware User's Guide for Oracle Business Rules.

23.3.2 What Happens When You Add Business Rules to a BPEL Process

When you add business rules to a BPEL process, Oracle JDeveloper creates a Decision component to control and run the business rules using the Business Rule Service Engine.

A Decision component consists of the following:

  • Rules or Decision Tables that are evaluated using the Rules Engine. These are defined using Rules Designer and stored in a business rules dictionary.

  • A description of the facts required for specific rules to be evaluated and the decision function to call. Each ruleset that contains rules or Decision Tables is exposed as a service with facts that are input and output, and the name of an Oracle Business Rules decision function. The facts are exposed through XSD definitions when you define the inputs and outputs for the business rule. A Decision function is stored in an Oracle Business Rules dictionary. For more information, see Oracle Fusion Middleware User's Guide for Oracle Business Rules.

  • A web service wraps the input, output, and the call to the underlying Business Rule service engine.

    This web service lets business processes assert and retract facts as part of the process. In some cases, all facts can be asserted from the business process as one unit. In other cases, the business process can incrementally assert facts and eventually consult the rule engine for inferences. Therefore, the service supports both stateless and stateful interactions.

    You can create a variety of such Decision components.

    For more information, see Oracle Fusion Middleware User's Guide for Oracle Business Rules.

23.3.3 What Happens When You Create a Business Rules Dictionary

After you create an application, a project, and a rules dictionary, the rules dictionary appears in the structure pane in Oracle JDeveloper and Rules Designer opens in the main canvas.

As part of the create Business Rule dialog you either select an existing dictionary or a new rule dictionary is created with the following pre-loaded data:

  • XML fact type model based on the input and output information of the Business Rule.

  • A Ruleset that needs to be completed by adding rules or Decision Tables. With an existing dictionary, you use the import option to specify a dictionary that may already contain the rules or Decision Tables.

  • A service component with the input and output contract of the Decision component.

  • A Decision component for the rule dictionary and wires to the BPEL process.

23.3.4 What You Need to Know About Invoking Business Rules in a BPEL Process

When you add business rules to a BPEL process Oracle JDeveloper creates a Decision Service that supports calling Oracle Business Rules with the inputs you supply, and returning the outputs with results. The Decision Service provides access to Oracle Business Rules Engine at runtime as a web service. For more information, see Oracle Fusion Middleware User's Guide for Oracle Business Rules.

23.3.5 What You Need to Know About Decision Component Stateful Operation

A Decision Component running in a business rules service engine supports either stateful or stateless operation. The Reset Session checkbox in the Create Business Rules dialog provides support for these two modes of operation.

By default the Reset Session checkbox is selected which indicates stateless operation. Stateless operation means that, at runtime, the rule session is released after the Decision Component invocation.

When Reset Session is unselected, the underlying Oracle Business Rules object is kept in the memory of the business rules service engine at a separate location (so that it is not given back to the Rule Session Pool when the operation is finished). A subsequent use of the Decision component re-uses the cached RuleSession object, with all its state information from the callFunctionStateful invocation, and then releases it back to the Rule Session pool once the callFunctionStateless operation is finished. Thus, when Reset Session is unselected the rule session is saved for a subsequent request and a sequence of Decision Service invocations from the same BPEL process should always end with a stateless invocation.

23.4 Adding Business Rules to an SOA Composite Application

To work with Oracle Business Rules in an SOA composite application, you create an application and add business rules.

The business rule service component enables you to integrate your SOA composite application with business rules. This creates a business rule dictionary and enables you to execute business rules and make business decisions based on the rules.

After creating a project in Oracle JDeveloper, you need to create a Business Rule Service component within the project. When you add a business rule you can create input and output variables to provide input to the service component and to obtain results from the service component.

To use business rules with Oracle JDeveloper, you do the following:

  • Add a business rules service component

  • Create input and output variables for the service component

  • Create an Oracle Business Rules dictionary

23.4.1 How to Add Business Rules to an SOA Composite Application

To work with Oracle Business Rules in an SOA composite application you use Oracle JDeveloper to create an application, a project, and then add a business rule component.

To create an SOA application with business rules:

  1. Create an SOA application and project. For more information, see Section 4.2.1, "How to Create an Application and a Project". For an SOA composite using business rules, pick the required technologies for your application. For example, you may need the following for an SOA application with business rules: ADF Business Components, Java, and XML. You move these items to the Selected area on the Project Technologies tab.

  2. In the Application Navigator, if the SOA composite editor is not showing, then in your project expand SOA Content folder and double-click composite.xml to launch the SOA composite editor.

  3. From the Component Palette, drag-and-drop a Business Rule from the Service Components area of the SOA menu to the Components lane of the SOA composite editor, as shown in Figure 23-10.

    Figure 23-10 Adding Business Rules to an SOA Composite Application

    Description of Figure 23-10 follows
    Description of "Figure 23-10 Adding Business Rules to an SOA Composite Application"

  4. When you drag-and-drop a Business Rule, Oracle JDeveloper displays the Create Business Rules dialog as shown in Figure 23-11.

    Figure 23-11 Adding Business Rules to an SOA Composite and Creating a Dictionary

    Description of Figure 23-11 follows
    Description of "Figure 23-11 Adding Business Rules to an SOA Composite and Creating a Dictionary"

Add inputs for business rules:

  1. In the Create Business Rules dialog, from the dropdown menu next to the Add icon select Input... to add input for the business rule. This displays the Type Chooser dialog.

  2. In the Type Chooser dialog, add inputs. If the schema is available in the Project Schema Files, skip to step 9 to select the appropriate schema.

  3. Click the Import Schema File... icon. This brings up the Import Schema File dialog.

  4. In the Import Schema File dialog click Browse Resources to choose the XML schema elements for the input. This displays the SOA Resource Browser dialog.

  5. In the SOA Resource Browser dialog, navigate to find the schema for your business rules input. For example, select the order.xsd schema file, and click OK.

  6. In the Import Schema File dialog select Copy to Project, as shown in Figure 23-12.

    Figure 23-12 Importing Schema for Input to Business Rules

    Description of Figure 23-12 follows
    Description of "Figure 23-12 Importing Schema for Input to Business Rules"

  7. In the Import Schema File dialog, click OK.

  8. In the Localize Files dialog, click OK.

  9. Use the Type Chooser dialog navigator to locate and select the input from the schema and click OK. For example, select the CustomerOrder element as the input.

Add outputs for business rules:

  1. In the Create Business Rules dialog, from the dropdown menu next to the Add icon select Output....

  2. In the Type Chooser dialog, in a manner similar to adding an input add the output. For example, add OrderApproval from the order.xsd and click OK.

  3. This displays the Create Business Rules dialog, as shown in Figure 23-13.

    Figure 23-13 Create Business Rules Dialog with Input and Output

    Description of Figure 23-13 follows
    Description of "Figure 23-13 Create Business Rules Dialog with Input and Output"

Set options and create decision service and business rules dictionary:

  1. In the Create Business Rules dialog, select Expose as Composite Service.

  2. If you do not want to use the default service name, then select the Advanced tab and in the Service Name field enter the service name.

  3. In the Create Business Rules dialog, click OK. This creates the Business Rule component, also called a Decision component, and Oracle JDeveloper shows the Business Rule component in the canvas workspace as shown in Figure 23-14.

    Figure 23-14 Business Rule Component in SOA Composite

    Description of Figure 23-14 follows
    Description of "Figure 23-14 Business Rule Component in SOA Composite"

  4. Double-click the Decision component (for example the OracleRules1 business rule). This opens Rules Designer, as shown in Figure 23-15. The validation log shows validation warnings for the input and output facts. By working with Rules Designer to define rules or decision tables, you remove these warning messages.

    Figure 23-15 Rules Designer Showing New Dictionary for SOA Composite Application

    Description of Figure 23-15 follows
    Description of "Figure 23-15 Rules Designer Showing New Dictionary for SOA Composite Application"

For information on Rules Designer, see Oracle Fusion Middleware User's Guide for Oracle Business Rules.

23.4.2 How to Select and Modify a Decision Function in a Business Rule Component

You can specify one or more decision functions as inputs for calling Oracle Business Rules as a component in a composite application. For example, you can specify a particular decision function as the input when multiple decision functions are available in an Oracle Business Rules dictionary.

To specify a decision function in a composite application:

  1. Add a decision function to the Oracle Business Rules dictionary. For more information, see Oracle Fusion Middleware User's Guide for Oracle Business Rules.

  2. Add a Business Rule component to the composite application. For more information, see Section 23.4.1, "How to Add Business Rules to an SOA Composite Application".

  3. Select a business rule component, as shown in Figure 23-16.

    Figure 23-16 Selecting a Business Rule Component in a Composite Application

    Description of Figure 23-16 follows
    Description of "Figure 23-16 Selecting a Business Rule Component in a Composite Application"

  4. Select the decision function port of interest. For example, select the port for DF_2 as shown in Figure 23-17.

    Figure 23-17 Selecting a Decision Function Port in a Business Rule Component

    Description of Figure 23-17 follows
    Description of "Figure 23-17 Selecting a Decision Function Port in a Business Rule Component"

  5. When you select the port, Oracle JDeveloper shows the port information in the Property Inspector.

  6. When you double-click the port, Oracle JDeveloper displays the Update Interface dialog for the port as shown in Figure 23-18.

    Figure 23-18 Update Interface Dialog for a Decision Function in a Business Rule Decision Port

    Description of Figure 23-18 follows
    Description of "Figure 23-18 Update Interface Dialog for a Decision Function in a Business Rule Decision Port"

23.5 Running Business Rules in a Composite Application

You run business rules as part of a Decision component within an SOA composite application. The business rules are executed by the Business Rule Service Engine. You can use Oracle Enterprise Manager Fusion Middleware Control Console to monitor the Business Rule Service Engine and to test an SOA composite application that includes a Decision component. For more information, see Oracle Fusion Middleware Administrator's Guide for Oracle SOA Suite.