|Oracle® Fusion Middleware Developer's Guide for Oracle SOA Suite
11g Release 1 (22.214.171.124.2)
Part Number E10224-14
|PDF · Mobi · ePub|
This chapter describes how to use a business rule service component to integrate a 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 a SOA composite application or as part of a BPEL process.
This chapter includes the following sections:
For more examples of using Oracle Business Rules, see Oracle Fusion Middleware User's Guide for Oracle Business Rules.
A decision component, also called a business rule service component, supports use of Oracle Business Rules in a SOA composite application. Decision components support the following SOA composite usage:
A decision component can be used within a SOA composite and wired to a BPEL component.
A decision component can be used within a SOA composite and used directly to run business rules.
A decision component can be used with the dynamic routing capability of Mediator.
For more information, see Chapter 20, "Creating Oracle Mediator Routing Rules."
A decision component can be used with the Advanced Routing Rules in Human Workflow.
For more information, see Section 28.4, "Associating Human Tasks with BPEL Processes."
You can create a 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:
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
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 29.5.2, "How to Specify Advanced Task Routing Using Business Rules."
You can create a business rules service component in the SOA composite application of Oracle JDeveloper and then design it by using the Business Rules Designer, which is displayed when you double-click a business rule in the SOA Composite Editor.
The Business Rules Designer consists of the following main sections shown in Figure 25-1. These sections enable you to work with business rules in Oracle JDeveloper.
Figure 25-1 Rules Designer in Oracle JDeveloper
The Application Navigator displays the files in the project. Each project can only contain one composite. But each composite can have multiple components of either the same type or different types (Business Rules, BPEL process, Oracle Mediator, and human workflow).
As you design business rules, additional files, folders, and elements can appear in the Application Navigator.
The Rules Designer window provides a visual view of the selected dictionary component. You use the Rules Designer navigation tabs to select different parts of the dictionary with which to work. The rules designer window displays when you perform one of the following actions:
In a composite, double-click a Business Rule component.
Double-click the Business Rule component in the SOA Composite Editor.
In a BPEL process, double click a business rule.
In the Application Navigator, double-click a business rules dictionary file (a file with the .rules extension)
Click the Design tab with a .rules file selected.
Table 25-1 describes where you can find information about working with a dictionary with Rules Designer.
Table 25-1 Rules Designer Navigation Areas Descriptions
|Rules Designer Navigation Tab||Description|
Rulesets with Rules and Decision Tables
A ruleset provides a unit of execution for rules and for decision tables. A decision table provides a mechanism for describing data processing tasks.
For more information about the Rules Designer navigation areas and its descriptions, see Oracle Fusion Middleware User's Guide for Oracle Business Rules.
The Structure window offers a structural view of the data in the Business Rule dictionary currently selected in the Rules Designer window. You can perform a variety of tasks from this section, by selecting an element and right-clicking on the element, including:
Managing (creating, editing, refreshing, and deleting) elements such as facts, functions, globals, bucketsets, dictionary links, and decision functions
Accessing rulesets, rules, and Decision Tables
Figure 25-2 shows the Structure window.
Figure 25-2 Structure Window with Rules Designer Dictionary
Rules Designer displays the status of dictionary validation in the business rule validation log, as shown in Figure 25-3.
When a dictionary is invalid, Rules Designer produces a list of warning messages and lists the associated dictionary objects that you can use to locate the dictionary object and to correct the problem. You can safely ignore the validation warnings that you see when you create rules using Rules Designer. The validation warnings are removed as you create the rules, but are shown during the intermediate steps. To test or deploy rules, the associated dictionary must not display warnings.
For more information on business rules validation, see Oracle Fusion Middleware User's Guide for Oracle Business Rules.
Figure 25-3 Rules Designer Business Rule Validation Log
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.
You can add Business Rule components using the SOA Composite Editor.
To create a Business Rule component:
Follow the instructions in Table 25-2 to start Oracle JDeveloper.
Create a Business Rule service component through one of the following methods:
As a service component in an existing SOA composite application:
From the Component Palette, drag a Business Rule service component into the SOA Composite Editor.
In a new application:
From the Application Navigator, select File > New > Applications > SOA Application.
This starts the Create SOA Application wizard.
In the Name your application page, enter an application name in the Name field.
In the Directory field, enter a directory path in which to create the SOA composite application and project.
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 25-3.
Table 25-3 Restrictions on Naming a SOA Project
|Create an Application Named...||With a SOA Project Named...|
During deployment, the second deployed project (composite) overwrites the first deployed project (composite).
In the Configure SOA settings page, select Composite with Business Rule.
Each method causes the Create Business Rules dialog shown in Figure 25-4 to appear.
Figure 25-4 Create Business Rules Dialog
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.
You can use a decision component, also called a business rule service component, to execute business rules in 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 must 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:
Create a BPEL process service component. For more information, see Section 4.1, "Introduction to the BPEL Process Service Component."
Expand the BPEL process by double-clicking the process item. For example, expand the BPEL process to view
callbackClient as shown in Figure 25-5.
Figure 25-5 Adding A Business Rule to a BPEL Process
Select Business Rule from the SOA 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
callbackClient, as shown in Figure 25-6.
Figure 25-6 Drag-and-drop a Business Rule into a BPEL Process
Oracle JDeveloper displays the business rule in the diagram. Double-click the business rule component to display the Rule dialog box. The Rule dialog box provides tabs, such as General, Dictionary, Correlation Sets, and so on, where you can select an existing Oracle Business Rules dictionary or enter the name of a new dictionary to create. Under the General tab, in the Name field enter a name for the business rule. For example, enter
GetCreditRating, as shown in Figure 25-7. If you previously created a dictionary, under the Dictionary tab, in the Dictionary field, select an existing dictionary.
Figure 25-7 Business Rule Added to Auto Loan BPEL Process
In the Business Rule area for the Business Rule Dictionary, click the Create Dictionary icon to display the Create Business Rules dialog.
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,
Rating that carry the input and output data for the
Enter a name for the Oracle Business Rules dictionary. For example, enter
GetCreditRating, as shown in Figure 25-8.
Figure 25-8 Adding GetCreditRating Business Rule Dictionary
Add inputs for business rule:
In the Create Business Rules dialog, from the menu next to the Add icon select Add Input Variable... to create the input variable.
This displays the Add Input Variable dialog box.
In the Add Input Variable dialog box, expand the Process folder and select the Variables folder immediately inside the Process.
Right-click the Variables folder, and from the list select Create Variable... as shown in Figure 25-9.
Figure 25-9 Add Input Variable
This displays the Create Variable dialog box.
In the Create Variable dialog box, in the Name field enter a value. For example, enter
RatingRequest as shown in Figure 25-10.
Figure 25-10 Create Variable Dialog
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.
Click the Import Schema File icon to import the schema. For example, import
CreditRatingTypes.xsd. Also import any other required schema for your application.
In the Type Chooser dialog, select ratingrequest and click OK.
In the Create Variable dialog, click OK.
In the Add Input Variable dialog, click OK.
Add outputs for business rule:
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.
In the Add Output Variable dialog select the scope by selecting the Variables folder under Process.
Right-click and from the dropdown list select Create Variable.... This displays the Create Variable dialog.
In the Create Variable dialog, in the Name field enter the output variable name. For example enter
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
In the Type Chooser dialog, click OK.
In the Create Variable dialog, click OK.
In the Add Output Variable dialog, click OK.
This displays the Create Business Rules dialog, as shown in Figure 25-11.
Figure 25-11 Create Business Rules Dialog with Input and Output Variables
Set options and create decision service and business rules dictionary:
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
Determine if the decision component is stateful or stateless with Reset Session. For more information, see Section 25.4.5, "What You May Need to Know About Decision Component Stateful Operation".
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 25-12.
Figure 25-12 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.
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:
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.
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.
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 must 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.
When you create inputs and outputs for a business rule, the XML fact type that is created in the associated dictionary is named based on the schema types for the inputs and outputs that you supply in the Create Business Rules dialog. When you specify schema type for the input and the output, Rules Designer defines fact types and aliases associated with your type selections for input and output. If you only use a single type for both the input and the output, then the decision component creates a single fact that is shown in the Rules Designer Facts tab. This fact represents the fact type you specified and uses an alias name that is a concatenation of both the input variable name and the output variable name. In Rules Designer you can rename this alias if you do not like the default naming scheme for the fact type.
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.
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 after 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.
To work with Oracle Business Rules in a 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 must 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
To work with Oracle Business Rules in a SOA composite application you use Oracle JDeveloper to create an application, a project, and then add a business rule component.
To create a SOA application with business rules:
Create a SOA application and project. For more information, see Section 2.1.1, "How to Create a SOA Application and Project". For a SOA composite using business rules, pick the required technologies for your application. For example, you may need the following for a SOA application with business rules: ADF Business Components, Java, and XML. You move these items to the Selected area on the Project Technologies tab.
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.
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 25-13.
Figure 25-13 Adding Business Rules to a SOA Composite Application
When you drag-and-drop a Business Rule, Oracle JDeveloper displays the Create Business Rules dialog as shown in Figure 25-14.
Figure 25-14 Adding Business Rules to a SOA Composite and Creating a Dictionary
Add inputs for business rules:
In the Create Business Rules dialog box, from the menu next to the Add icon select Input... to add input for the business rule. This displays the Type Chooser dialog.
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.
Click the Import Schema File... icon. This brings up the Import Schema File dialog.
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.
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.
In the Import Schema File dialog select Copy to Project, as shown in Figure 25-15.
Figure 25-15 Importing Schema for Input to Business Rules
In the Import Schema File dialog, click OK.
In the Localize Files dialog, click OK.
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:
In the Create Business Rules dialog, from the dropdown menu next to the Add icon select Output....
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.
This displays the Create Business Rules dialog, as shown in Figure 25-16.
Figure 25-16 Create Business Rules Dialog with Input and Output
Set options and create decision service and business rules dictionary:
In the Create Business Rules dialog, select Expose as Composite Service.
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.
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 25-17.
Figure 25-17 Business Rule Component in SOA Composite
Double-click the decision component (for example the OracleRules1 business rule). This opens Rules Designer, as shown in Figure 25-18. 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 25-18 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.
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:
Add a decision function to the Oracle Business Rules dictionary. For more information, see Oracle Fusion Middleware User's Guide for Oracle Business Rules.
Add a Business Rule component to the composite application. For more information, see Section 25.5.1, "How to Add Business Rules to a SOA Composite Application".
Select a business rule component, as shown in Figure 25-19.
Figure 25-19 Selecting a Business Rule Component in a Composite Application
Select the decision function port of interest. For example, select the port for DF_2 as shown in Figure 25-20.
Figure 25-20 Selecting a Decision Function Port in a Business Rule Component
When you select the port, Oracle JDeveloper shows the port information in the Property Inspector.
When you double-click the port, Oracle JDeveloper displays the Update Interface dialog for the port as shown in Figure 25-21.
Figure 25-21 Update Interface Dialog for a Decision Function in a Business Rule Decision Port
You run business rules as part of a decision component within a SOA composite application. The business rules are executed by the Business Rule Service Engine. You can use Oracle Enterprise Manager Fusion Middleware Control to monitor the Business Rule Service Engine and to test a SOA composite application that includes a decision component. For more information, see Oracle Fusion Middleware Administrator's Guide for Oracle SOA Suite and Oracle Business Process Management Suite.
To test a standalone decision service component by using Oracle Enterprise Manager Fusion Middleware Control, you must provide the name of the decision service as the value of the payload name field in the Test Web Service page as shown in Figure 25-22.
Figure 25-22 Invoking a Standalone Test Decision Service
'name' in payload should be the decision service name as can be seen in the sample
.decs file in Figure 25-23.
Figure 25-23 Sample .decs File
Without the decision service name, it would not be possible to invoke the standalone decision service with just the payload and endpoint details.
You can use Oracle ADF Business Components Fact Types and
ActionTypes from the Business Rules Service Engine. Typically, a decision component can be used within a SOA composite and wired to a BPEL component and the Oracle Business Rules rules act on XML types. The Business Rules Service Engine is called as a web service with a payload containing instances of the XML schema types, and the service engine returns a response similarly.
It is also possible to use Oracle ADF Business Components Fact Types from a decision component. Instead of loading the Oracle ADF Business Components Fact Type instances and passing them to the Business Rules Service Engine, you call the Business Rules Service Engine with configuration information describing how the Oracle ADF Business Components view object rows can be loaded. Special Oracle Business Rules decision functions in the
DecisionPointDictionary and classes in the Oracle Business Rules SDK Decision Point API then load the rows and assert Oracle ADF Business Components fact type instances. When working with Oracle ADF Business Components Fact Types, you write rules that use user-defined Java classes which inherit from ActionType to affect action, such as modifying the Oracle ADF Business Components fact type instances such that they update their underlying database rows.
A decision component requires an XML document as input. The Oracle Business Rules Decision Point dictionary provides an XML Fact Type called
SimpleDecisionPointInput that serves as this input. The primary key(s) of Oracle ADF Business Components are passed to the business rule service component. The business rule service component invokes a user-defined decision function which it invokes to load the Oracle ADF Business Components view object instances, asserts them in the rules engine, and then marshals the results in the following order:
DecisionPointDictionary.DecisionPoint_Preprocessing_Webservice Ruleset: The preprocessing ruleset reads the business component from the database and asserts them as facts.
User-defined rulesets: The user ruleset matches these facts and should assert facts that extend
ActionType to update the business component.
DecisionPointDictionary.DecisionPoint_Postprocessing_Webservice Ruleset: The actual updating is performed by the postprocessing ruleset. Use of
ActionTypes is optional.
For specific instructions on how to use Oracle ADF Business Components Fact Types and
ActionTypes from the Business Rules Service Engine, see the source code for Oracle Business Rules-specific samples available with the Oracle SOA Suite samples.