SOA 11g Tutorial: Business Rules

 

This is part of the Oracle SOA11g hands on tutorials.

If Then Rules

Add Rule

* Open POProcessing > composite.xml
* Drag and drop Business Rules icon onto the Components lane
* On Create Business Rules screen,
– Select
Create Dictionary
– Enter
Name: ManualApproval
Package:
* Click green plus icon, followed by Input
– On Type Chooser screen, click the Import Schema Files… icon (upper right corner)
– Enter or browse to c:\po\schemas\OrderBookingDiscount.xsd. Copy to Project is checked.
– Click OK
– On Localize Files screen:
Maintain original directory structure for imported files: checked.
– Click OK.
– Select price on Type Chooser. Click OK
* Back on Create Business Rules screen, click green plus icon followed by Output
– On Type Chooser screen,
select OrderBookingDiscount.xsd -> discountandshipping
click OK
* Click OK on Create Business Rules screen

Edit Rule

* Double click rules icon to open ManualApproval.rules editor
* Select Ruleset1 on the left panel
* Click Create Rule under the IF/THEN Rule panel
* Click insert test block under IF
* Select left operand and select price -> price
* Select == sign and select >=
* Select right operand and enter 5000, hit enter key
* Select insert action block under THEN, and select assert new
* Select target -> discountandshipping
* Click edit properties to bring up Properties dialog, enter
approvalRequired: true
discount: 0
price: price.price
shipping: 0
– Click OK on Properties dialog
* Click the green plus sign followed by Create Rule to add another rule (rule2)
* Click <insert test>
* Click left operand and select price -> price
* Select == sign and select < * Select right operand and enter 5000, hit enter key * Select insert action block under THEN, and select assert new * Select target -> discountandshipping
* Click edit properties, on Properties dialog, enter:
approvalRequired: false
discount: 0
price: price.price
shipping: 0
– Click OK

Wire Rule

* Open approveLargeOrder.bpel
* Create a new variable by clicking the Variable icon on the upper left corner.
* On Variables dialog
– Click Variables -> Process -> Variables
– Click green + sign, enter:
Name: approvalRequired
Element: {http://www.globalcompany.com/ns/OrderBooking/rules}discountandshipping
– Click OK
* Click Close
* Drag Business Rule icon and drop before ManualPOApproval Human Task icon
* Double click Rule icon to open the Rule editor
General/Name: ApprovalRule
Dictionary/Dictionary: ManualApproval
* Click Assign Input Facts -> Green plus sign
From -> Expression
bpws:getVariableData(‘inputVariable’,’payload’,’/ns2:Order/ns2:price’) * bpws:getVariableData(‘inputVariable’,’payload’,’/ns2:Order/ns2:qty’)
To -> Business Rule Facts -> Scope – Rule 1 -> Variables -> dsIn -> payload -> callFunctionStateless -> ParameterList -> price -> price
– Click OK
* Click Assign Output Facts _ Green plus sign
From -> Business Rule Facts -> Process -> Scope – Rule 1 -> Variables -> dsOut -> payload -> callFunctionStatelessDecision -> resultList -> discountandshipping
To Variable -> Process -> Variables -> Process -> Variables -> approvalRequired -> discountandshipping
– Click OK
* Click OK on Rule editor

* Drag a Switch icon underneath ApprovalRule
* Drag a Sequence icon into condition branch of newly added Switch block
* Drag ManualPOApproval into the newly added Sequence block
* Drag the Switch block underneath Human Task into the newly added Sequence block
* Set switch evaluation underneath ApprovalRule to
bpws:getVariableData(‘approvalRequired’,’/ns6:discountandshipping/ns6:approvalRequired’) = ‘true’
* Drag an Assign activity into otherwise block
General -> Name: AutoApproved
Copy Rules -> Set outputVariable status to ‘approved’
* Save all

Deploy

* Right click POProcessing and select Deploy -> POProcessing…

Test

Total price under $1000

* Input xml

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body xmlns:ns1="http://xmlns.oracle.com/ns/order">
        <ns1:PurchaseOrder>
            <ns1:CustID>1111</ns1:CustID>
            <ns1:ID>1212</ns1:ID>
            <ns1:productName>HD TV</ns1:productName>
            <ns1:itemType>Electronics</ns1:itemType>
            <ns1:price>900</ns1:price>
            <ns1:quantity>1</ns1:quantity>
            <ns1:status>Initial</ns1:status>
            <ns1:ccType>Mastercard</ns1:ccType>
            <ns1:ccNumber>1234-1234-1234-1234</ns1:ccNumber>
        </ns1:PurchaseOrder>
    </soap:Body>
</soap:Envelope>

* The order should be automatically approved without BPEL process.

Total price between $1000 to $5000

* Input xml

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body xmlns:ns1="http://xmlns.oracle.com/ns/order">
        <ns1:PurchaseOrder>
            <ns1:CustID>1111</ns1:CustID>
            <ns1:ID>1212</ns1:ID>
            <ns1:productName>HD TV</ns1:productName>
            <ns1:itemType>Electronics</ns1:itemType>
            <ns1:price>900</ns1:price>
            <ns1:quantity>5</ns1:quantity>
            <ns1:status>Initial</ns1:status>
            <ns1:ccType>Mastercard</ns1:ccType>
            <ns1:ccNumber>1234-1234-1234-1234</ns1:ccNumber>
        </ns1:PurchaseOrder>
    </soap:Body>
</soap:Envelope>

* The order should be automatically approved using BPEL and Rules, but no need for human task.

Total price more than $5000

* Input xml

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body xmlns:ns1="http://xmlns.oracle.com/ns/order">
        <ns1:PurchaseOrder>
            <ns1:CustID>1111</ns1:CustID>
            <ns1:ID>1212</ns1:ID>
            <ns1:productName>HD TV</ns1:productName>
            <ns1:itemType>Electronics</ns1:itemType>
            <ns1:price>900</ns1:price>
            <ns1:quantity>10</ns1:quantity>
            <ns1:status>Initial</ns1:status>
            <ns1:ccType>Mastercard</ns1:ccType>
            <ns1:ccNumber>1234-1234-1234-1234</ns1:ccNumber>
        </ns1:PurchaseOrder>
    </soap:Body>
</soap:Envelope>

* The order need to be manually approved by BPEL, Rules, and Human Task.

Invalid credit card

* Input xml

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body xmlns:ns1="http://xmlns.oracle.com/ns/order">
        <ns1:PurchaseOrder>
            <ns1:CustID>1111</ns1:CustID>
            <ns1:ID>1212</ns1:ID>
            <ns1:productName>HD TV</ns1:productName>
            <ns1:itemType>Electronics</ns1:itemType>
            <ns1:price>900</ns1:price>
            <ns1:quantity>10</ns1:quantity>
            <ns1:status>Initial</ns1:status>
            <ns1:ccType>Mastercard</ns1:ccType>
            <ns1:ccNumber>4321-4321-4321-4321</ns1:ccNumber>
        </ns1:PurchaseOrder>
    </soap:Body>
</soap:Envelope>

* The order should be automatically rejected by BPEL, no need for Rules, and Human Task.

Decision Table

Add Decision Table

* Open composite.xml file
* Drag a BPEL process to Components lane, enter
Name: FulfillmentProcess
Namespace: http://xmlns.oracle.com/POProcessing/POProcessing/FulfillmentProcess
Template: Asynchronous BPEL Process
Service Name: fulfillmentprocess_client
Expose as a SOAP service: unchecked
Input: {http://xmlns.oracle.com/ns/fulfillment}Fulfillment # Need to import fulfillment.xsd schema
Output: {http://xmlns.oracle.com/ns/fulfillment}CarrierSelection
* Click OK

Add Business Rule

* Drag a Business Rule to the Components lane, enter
Name: FulfillmentRules
Package: fulfillmentrules
Input: Fulfillment
Output: CarrierSelection
Advanced -> Service Name: OracleRulesFulfillment
* Click OK

Wire BPEL and Rule

* Drag a wire from new BPEL to new Rule
* Drag a wire from approveLargeOrder to new BPEL

Define Decision Table

* Double click FulfillmentRules to open rule editor FulfillmentRules.rules

Create Bucketsets

* Click Bucketsets -> Green plus sign -> List of Ranges
Name: OrderTotal
Datatype: double
* On Edit Bucketset – OrderTotal screen
– click green plus sign twice to add two endpoint (total three endpoints)
Endpoint: 5000.0 Range: >=5000.0 Alias: xtralarge
Endpoint: 1000.0 Range: [1000.0..5000.0] Alias: large
Endpoint: -Infinity Range: <1000.0 Alias: small - click OK

Setup Facts

* Click Facts
* Select FulfillmentType
* Click edit icon (pencil)
* On Edit XML Fact screen,
Set Bucketset for total Alias to OrderTotal
– Click OK
* Select CarrierSelection
* Click edit icon (pencil)
* On Edit XML Fact screen,
Check that Bucketset for carrier Alias is set to CarrierValue
* Click OK

Add Decision Table

* Click Ruleset1
* Click Create Decision Table button
Insert Condition
* Click insert condition block
* Double click edit condition block, select FulfillmentType.total
* Click cell below R1 and check small
* Click green plus sign and click Rule, click cell below R2 and set value to large
* Click green plus sign and click Rule, click cell below R3 and set value to xtralarge

Insert Action
* Click insert action -> assert new
* Double click A1 row to open Action Editor
– select CarrierSelection
– check Parameterized
– click OK
* Select carrier values and check the checkboxes
small=USPS, large=UPS, xtralarge=FED_EX
* Click Save All

Define BPEL

* Double click FulfillmentProcess to open fulfillmentProcess.bpel
* Drag a Business Rule process underneath receiveInput
* Double click business rule icon to open Rule editor
* Select Dictionary -> Dictionary: FulfillmentRules
* Add a new Input Fact,
From: inputVariable -> payload -> FulfillmentType
To: Scope – Rule1 -> Variables -> dsIn -> payload -> parameterList -> Fulfillment
* Add a new Output Fact,
From: Scope – Rule1 -> Variables -> dsOut -> payload -> callFunctionSttelessDecision -> resultList -> CarrierSelection
To: outputVariable -> CarrierSelection
* Click OK
* Click OK again
* Save all

Invoke Fulfillment Process

* In composite.xml, double click approveLargeOrder to open the BPEL editor
* Drag an Invoke to the very end of validCreditCard branch
* Wire the new Invoke to FulfillmentProcess
* In Invoke editor,
– Name: Invoke_Fulfillment
– Create an input variable with default values
– click OK
* Drag a Transform activity above Invoke_Fulfillment, double click to open Transform editor,
– Source variable: inputVariable -> payload
– target variable: Invoke_Fulfillment_process_inputVariable -> payload
* Click green plus icon to create a new mapper file
– map customerId
– map orderId
– map both price and qty to multiply function and then map to total
* Save all
* Close mapper file

* Drag a Switch icon underneath Invoke_Fulfillment
* Drag a Sequence icon inside condition branch
* Drag both Transorm1 and Invoke_Fulfillment into new Sequence
* Add condition
bpws:getVariableData(‘outputVariable’,’payload’,’/ns2:Order/ns2:status’) = ‘approved’
* Delete otherwise branch
* Save all and close BPEL file

* In composite.xml , double click routePO to open routePO.mplan
* Click green plus sign -> static routing rule -> service
* Select POProcessing | BPEL Processes | FulfillmentProcess | Services | fulfillmentprocess_client | process
* Add filter criteria
($in.purchaseOrderPart/inp1:PurchaseOrder/inp1:quantity * $in.purchaseOrderPart/inp1:PurchaseOrder/inp1:price) < 1000 * Create new transform file - map customerId - map orderId - map both price and qty to multiply function and then map to total * Save all

Deploy

* Right click POProcessing and select Deploy -> POProcessing…

Test

Total price under $1000

* Use xml request that contains total price under $1000

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body xmlns:ns1="http://xmlns.oracle.com/ns/order">
        <ns1:PurchaseOrder>
            <ns1:CustID>1111</ns1:CustID>
            <ns1:ID>1212</ns1:ID>
            <ns1:productName>HD TV</ns1:productName>
            <ns1:itemType>Electronics</ns1:itemType>
            <ns1:price>900</ns1:price>
            <ns1:quantity>1</ns1:quantity>
            <ns1:status>Initial</ns1:status>
            <ns1:ccType>Mastercard</ns1:ccType>
            <ns1:ccNumber>1234-1234-1234-1234</ns1:ccNumber>
        </ns1:PurchaseOrder>
    </soap:Body>
</soap:Envelope>

* Click Launch Flow Trace button
* On the Flow Trace web page, click FulfillmentProcess BPEL Component
* Click the Flow tab
* Click callbackClient icon
* Check that carrier is USPS

Total price between $1000 to $5000

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body xmlns:ns1="http://xmlns.oracle.com/ns/order">
        <ns1:PurchaseOrder>
            <ns1:CustID>1111</ns1:CustID>
            <ns1:ID>1212</ns1:ID>
            <ns1:productName>HD TV</ns1:productName>
            <ns1:itemType>Electronics</ns1:itemType>
            <ns1:price>900</ns1:price>
            <ns1:quantity>5</ns1:quantity>
            <ns1:status>Initial</ns1:status>
            <ns1:ccType>Mastercard</ns1:ccType>
            <ns1:ccNumber>1234-1234-1234-1234</ns1:ccNumber>
        </ns1:PurchaseOrder>
    </soap:Body>
</soap:Envelope>

* Check that carrier is UPS

Total price more than $5000

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body xmlns:ns1="http://xmlns.oracle.com/ns/order">
        <ns1:PurchaseOrder>
            <ns1:CustID>1111</ns1:CustID>
            <ns1:ID>1212</ns1:ID>
            <ns1:productName>HD TV</ns1:productName>
            <ns1:itemType>Electronics</ns1:itemType>
            <ns1:price>900</ns1:price>
            <ns1:quantity>10</ns1:quantity>
            <ns1:status>Initial</ns1:status>
            <ns1:ccType>Mastercard</ns1:ccType>
            <ns1:ccNumber>1234-1234-1234-1234</ns1:ccNumber>
        </ns1:PurchaseOrder>
    </soap:Body>
</soap:Envelope>

* Approve and check that carrier is FedEx
* Reject and check that Fulfillment BPEL process is NOT called

Invalid credit card

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body xmlns:ns1="http://xmlns.oracle.com/ns/order">
        <ns1:PurchaseOrder>
            <ns1:CustID>1111</ns1:CustID>
            <ns1:ID>1212</ns1:ID>
            <ns1:productName>HD TV</ns1:productName>
            <ns1:itemType>Electronics</ns1:itemType>
            <ns1:price>900</ns1:price>
            <ns1:quantity>10</ns1:quantity>
            <ns1:status>Initial</ns1:status>
            <ns1:ccType>Mastercard</ns1:ccType>
            <ns1:ccNumber>4321-4321-4321-4321</ns1:ccNumber>
        </ns1:PurchaseOrder>
    </soap:Body>
</soap:Envelope>

* Check Fulfillment BPEL process is NOT called

This entry was posted in soa11g. Bookmark the permalink.

3 Responses to SOA 11g Tutorial: Business Rules

Leave a Reply

Your email address will not be published. Required fields are marked *


*

This site uses Akismet to reduce spam. Learn how your comment data is processed.