Skip Headers
Oracle® SOA Suite Developer's Guide
10g (10.1.3.1.0)

Part Number B28764-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

7.8 Using Business Rules and a Decide Activity

Business rules are statements that describe the policies of a company. When Oracle BPEL Process Manager is used in combination with a business rules engine such as Oracle Business Rules, you can effect changes in a BPEL process that are related to a company's policies without modifying, stopping, or redeploying the BPEL process itself. Moreover, a business analyst or anyone familiar with the policies of a company can change business rules without involving BPEL developers.

After business rules are defined using Oracle Business Rules, you add the following to implement the rules within a BPEL process:

The process of integrating business rules with the preceding components of Oracle BPEL Process Manager is shown in Figure 7-18.

Figure 7-18 Integrating Business Rules with Oracle BPEL Process Manager Components

Description of Figure 7-18 follows
Description of "Figure 7-18 Integrating Business Rules with Oracle BPEL Process Manager Components"

In the SOA Order Booking application, the BPEL process includes a decide activity that works with a rule that implements the company's policy. Manual credit approval is required for all orders over $1000 unless the customer has platinum status.

See the following for more information about using business rules:

7.8.1 How to Use the Decision Service Wizard to Create a Decision Service Partner Link

Use the Decision Service Wizard to select a rule set or function that you created in the Oracle Business Rules Rules Engine. You also select the invocation pattern that you want performed from the following options:

  • Assert facts only: Select the rule engine facts you want to assert (send factual data to the rules engine) in the future. You assign the required data for the facts with a BPEL assign activity. The underlying rule session must be stateful. Otherwise, the asserted facts are not visible to subsequent rule engine invocations.

  • Retrieve results: Retrieve a result from the business rules engine. The values of these results may have changed by past execution of a rule set acting on these facts. The wizard assumes that it has a stateful rule session in its cache from which a result can be retrieved. This is the case if the invocation pattern Assert facts and execute rule set was executed previously in the BPEL process.

  • Assert facts and execute rule set: The same as Assert facts only, except that the rule set is executed after the facts are asserted. The wizard creates (or uses) a stateful rule session. Otherwise, the result of executing this pattern is lost. No results are retrieved from the business rules engine.

  • Assert facts, execute rule set, and retrieve results: The same as Assert facts and execute rule set, except that the results are retrieved from the business rules engine. You map the results of rule set execution to BPEL variables with an assign activity. The rules session remains active. This enables you to reuse previously asserted facts.

  • Assert facts, execute rule set, retrieve results, and reset the session: The same as Assert facts, execute rule set, and retrieve results, except that the results are reset for the next time that you invoke the web service. Resetting the session clears the previously asserted fact values.

  • Execute function: Select to execute a function. Functions are also defined in dictionaries. For rule sets, you select input and output facts. For functions, you work with a fixed set of input parameters and a single return value.

  • Execute function and reset the session: The same as Execute function, except that a stateful rule session is created for this pattern. All fact values are reset after retrieving the return value of the function.

To use the decision service wizard to create a decision service partner link:

  1. Drag and drop a Decision Service under one of the Services swim lanes.

  2. Use the Decision Service Wizard to specify the invocation pattern and rule set or function, as shown in Figure 7-19.

    Figure 7-19 Decision Service Wizard

    Decision Service Wizard
    Description of "Figure 7-19 Decision Service Wizard"

    1. Enter a service name.

      This will be the name of the partner link.

    2. Enter a namespace or accept the default.

    3. Select an invocation pattern.

    4. Click the flashlight icon next to the Ruleset or Function field (the field that appears depends on the invocation pattern that you selected).

    5. Click the Create Rule Engine Connection icon (the icon on the left).

  3. Use the Rule Explorer to create a connection to a business rules engine and select a rule set or function.

    After you select a rule set or function, you are returned to the Explorer window with a connection to the repository of the rule set or function displaying in the navigation tree.

  4. Use the Create Rule Engine Connection dialog to select the type of repository in which the rule sets and functions are stored in the business rules engine.

    For this release, the Oracle Rules Engine repository is supported.

  5. Enter the file repository directory (or browse using the folder icon) and click Next.

    You are returned to the Rule Explorer window with a connection to the repository of the rule set or function displayed in the navigation tree.

  6. Expand the dictionary and dictionary version nodes, select the rule set, and click OK.

  7. Use the Decision Service Wizard: Select a Result or Function dialog to specify input facts and option output (watch) facts and click Next.

    The assert facts enable you to assert a fact to the rule set or function (send factual data to the business rules engine). The watch facts enable you to return results from the rule set or function. Watch facts only appear if you selected an invocation pattern that retrieves results.

    1. Select one of the following:

      Check here to assert all descendants from the top level element: Enables you to assert all the descendants of the selected rule set or function. For example, assume that a purchase order rule set contains three items. If this check box is selected, the purchase order and all three items are asserted. If this check box is not selected, only the purchase order is asserted.

      Check here to add more invocation patterns: Enables you to add additional interaction patterns to the same partner link. You can only add additional rule set invocation patterns, and not function invocation patterns.

  8. Use the Decision Service Wizard: Copy XSD Files dialog to review the on-screen messages to ensure that all necessary XSD schema files for this project are imported from the repository by the wizard.

    The wizard attempts to identify all the schema files in the repository that must be imported into this project. Based on this attempt, this window can display the following status messages:

    • If the Decision Service Wizard finds the schema files to import, the directory paths to the files display at the top of this window. No action is required on your part.

    • If the Decision Service Wizard cannot find the schema files to import, the directory paths to the files displays at the top of this window. You must manually copy these files to the specified directory.

    • If this XSD schema file includes or imports other schema files, ensure that those files are copied into the bpel\rules\xsd subdirectory of your BPEL project indicated on-screen. Ensure that you use only relative directory paths for these schema files.

  9. Click Next.

    The decision service partner link is created.

7.8.2 How to Create a Decide Activity

The decide activity enables you to create a BPEL process activity that invokes the decision service partner link you created with the Decision Service wizard. This activity also enables you to create copy operation assignments between the fact data in your rule set or function and BPEL variables.

When complete, a decide activity consisting of assign and invoke activities to the decision service partner link is created.

To create a decide activity:

  1. Drag and drop a Decide activity into your BPEL process.

  2. Enter a name, select the decision service partner link you created, and the invocation pattern (operation to perform).

  3. Click Assign Input Facts, then click Create to create mappings for the input facts.

    This enables you to create assignments that map BPEL input variables to automatically created BPEL variables that correspond to the input (assert) fact type.

  4. If you selected an invocation pattern that retrieves results, click Assign Output Facts, and then click Create to create mappings for the output facts.

    This enables you to create assignments that map automatically created BPEL variables that correspond to the output (watch) fact type.

  5. Click OK when complete.

    A decide activity consisting of assign and invoke activities to the decision service partner link is created.

7.8.3 What Happens When You Use Business Rules and a Decide Activity

A new decision service partner link for the web service is created that interfaces with the Oracle Business Rules Rules Engine. A WSDL file based on the rule set is generated.

The Decision Service Wizard provides the following:

  • Dynamic processing (provides for intelligent routing, validation of policies within a process, and constraint checks)

  • Integration with the ad-hoc participant type workflow (provides policy-based task assignment, various escalation policies, and load balancing of tasks)

  • Integration with business activity monitoring (sends alerts based on certain policies and dynamic processing-based reasoning)

Example 7-8 shows the source code the RequiresManualApproval decide activity in the SOA Order Booking application.

Example 7-8 Source Code for the RequiresManualApproval Decide Activity

<scope name="RequiresManualApproval">
  <bpelx:annotation>
    <bpelx:pattern patternName="bpelx:decide"></bpelx:pattern>
  </bpelx:annotation>
  <variables>
    <variable name="com_oracle_demos_orderbooking_Approve" element="ns27:approve"/>
    <variable name="dsIn" messageType="ns28:assertExecuteWatchStatefulMessage"/>
    <variable name="dsOut" messageType="ns28:assertExecuteWatchStatefulDecisionMessage"/>
  </variables>
  <faultHandlers>
    <catchAll>
      <switch name="Switch_2">
        <case condition="bpws:getVariableData('inputVariable','payload','/
          client:SOAOrderBookingProcessRequest/ns4:PurchaseOrder/ns4:OrderInfo/
          ns4:OrderPrice') >= 1000">
          <assign name="Assign_4">
            <copy>
              <from expression="true()"/>
              <to variable="requiresApproval"/>
            </copy>
          </assign>
        </case>
        <otherwise>
          <assign name="Assign_4">
            <copy>
              <from expression="false()"/>
              <to variable="requiresApproval"/>
            </copy>
          </assign>
        </otherwise>
      </switch>
    </catchAll>
  </faultHandlers>
  <sequence name="Sequence_16">
    <assign name="BPEL_Header">
      <copy>
        <from expression="'DecisionService'"/>
        <to variable="dsIn" part="payload"
            query="/ns28:assertExecuteWatchStateful/@name"/>
      </copy>
      <copy>
        <from expression="concat(ora:getProcessURL(), '/decisionservices.decs')"/>
        <to variable="dsIn" part="payload"
            query="/ns28:assertExecuteWatchStateful/ns28:configURL"/>
      </copy>
      <copy>
        <from expression="ora:getProcessId()"/>
        <to variable="dsIn" part="payload"
            query="/ns28:assertExecuteWatchStateful/ns28:bpelInstance/ns13:processId"/>
      </copy>
      <copy>
        <from expression="ora:getProcessVersion()"/>
        <to variable="dsIn" part="payload"
            query="/ns28:assertExecuteWatchStateful/ns28:bpelInstance/ns13:processVersion"/>
      </copy>
      <copy>
        <from expression="ora:getDomainId()"/>
        <to variable="dsIn" part="payload"
            query="/ns28:assertExecuteWatchStateful/ns28:bpelInstance/ns13:domainId"/>
      </copy>
      <copy>
        <from expression="ora:getProcessURL()"/>
        <to variable="dsIn" part="payload"
            query="/ns28:assertExecuteWatchStateful/ns28:bpelInstance/ns13:processURL"/>
      </copy>
      <copy>
        <from expression="ora:getInstanceId()"/>
        <to variable="dsIn" part="payload"
            query="/ns28:assertExecuteWatchStateful/ns28:bpelInstance/ns13:instanceId"/>
      </copy>
      <copy>
        <from expression="ora:getConversationId()"/>
        <to variable="dsIn" part="payload"
            query="/ns28:assertExecuteWatchStateful/ns28:bpelInstance/ns13:conversationId"/>
      </copy>
    </assign>
    <assign name="BPEL_Var_To_Rule_Facts">
      <copy>
        <from expression="number(bpws:getVariableData('inputVariable','payload','/
          client:SOAOrderBookingProcessRequest/ns4:PurchaseOrder/ns4:OrderInfo/
          ns4:OrderPrice'))"/>
        <to variable="com_oracle_demos_orderbooking_Approve"
            query="/ns27:approve/ns27:price"/>
       </copy>
       <copy>
         <from expression="string(bpws:getVariableData('customerServiceResponse',
           'parameters','/ns3:findCustomerByIdResponse/ns3:return/ns3:status'))"/>
         <to variable="com_oracle_demos_orderbooking_Approve"
             query="/ns27:approve/ns27:status"/>
       </copy>
    </assign>
    <assign name="Facts_To_Rule_Service">
      <copy>
        <from variable="com_oracle_demos_orderbooking_Approve"/>
        <to variable="dsIn" part="payload"
            query="/ns28:assertExecuteWatchStateful/ns28:assertList/ns27:approve"/>
      </copy>
    </assign>
    <invoke name="Invoke" partnerLink="DecisionServicePL"
            portType="ns28:IDecisionService"
            operation="assertExecuteWatchStateful" inputVariable="dsIn"
            outputVariable="dsOut"/>
    <assign name="Rule_Service_To_Facts">
      <copy>
        <from variable="dsOut" part="payload"
              query="/ns28:assertExecuteWatchStatefulDecision/ns28:resultList/ns27:approve"/>
        <to variable="com_oracle_demos_orderbooking_Approve"/>
      </copy>
    </assign>
    <assign name="Facts_To_BPEL_Var">
      <copy>
        <from variable="dsOut" part="payload"
              query="/ns28:assertExecuteWatchStatefulDecision/ns28:resultList/
                ns27:approve/ns27:approvalRequired"/>
        <to variable="requiresApproval"/>
      </copy>
    </assign>
  </sequence>
</scope>