Lab 05 - Create Guided Rules
Lab Goal
To create guided rules calculating shopping cart totals, totaling shopping cart items, and apply promotions for Cool Store
Creating guided rules
- First we will create a new guided rule:
Total Shopping Cart
AUTHORING -> PROJECT AUTHORING -> NEW ITEM -> GUIDED RULE
RESOURCE NAME: Total Shopping Cart
(don't check the DSL box this time)
Creating guided rules
- Start by importing model object
ShoppingCart
for this rule:
CONFIG tab on the bottom of rule
NEW ITEM button at top, select ShoppingCart from Import list
Creating guided rules
- Now return to the
Edit
tab an start designing our rule
- The condition (WHEN):
'There is a ShoppingCart'
- assign a variable name to this ShoppingCart
'$sc'
Creating guided rules
- The action (THEN) is a two part action
- We want to operate on the given ShoppingCart ($sc)
- Modify value of ShoppingCart field cartTotal to 0
- Modify value of ShoppingCart field cartItemPromoSavings to following formula:
- `($sc.cartItemPromoSavings == 0.0) ? 0.0 : $sc.cartItemPromoSavings * -1`
Creating guided rules
- Expand the 'show options' and add:
check NO-LOOP box
RULEFLOW-GROUP: total-rules
- `($sc.cartItemPromoSavings == 0.0) ? 0.0 : $sc.cartItemPromoSavings * -1`
- Save the rule
- Ensure your package builds:
TOOLS -> PROJECT EDITOR -> BUILD & DEPLOY
(should see green pop-up 'Build Successful')
Creating guided rules
- Now the final guided rule will be created on your own:
Apply Cart Item Promotions
AUTHORING -> PROJECT AUTHORING -> NEW ITEM -> GUIDED RULE
RESOURCE NAME: Apply Cart Item Promotions
don't check the DSL box this time
Creating guided rules
- The condition (WHEN) is two fold
- Part I is about a ShoppingCartItem
- Part II is about a PromoEvent that monitors an event stream
'Promo Stream'
- The action (THEN) will modify two ShoppingCart fields
- promoSavings field
- price field
Creating guided rules
- The condition Part I:
'There is a ShoppingCartItem'
- assign a variable name to this ShoppingCart
'$sci'
'with itemId'
- assign a variable name to this itemID
'$itemId'
Creating guided rules
- The condition Part IIa
- top green
+
sign adds second condition
- start with from Entry Point and fill in:
'Promo Stream'
- within condition use
click to add patterns
- add
PromoEvent
, results in 'There is a PromoEvent'
Creating guided rules
- The condition Part IIb
- clicking on `PromoEvent` gives a pop-up
- select entry
All of (And)
- results in
'with all of the following'
Creating guided rules
- The condition Part IIc
- click on
all of the following"
line to add:
- an itemId equal to the ShoppingCartItem
'$itemId'
- a percentageOff assigned variable
'$pctOff'
- percentageOff is over sliding window:
'none'
Creating guided rules
- The action part of our rule is next:
'Modify value of ShoppingCartItem ($sci)'
'promoSavings is set to 0.0'
'Modify value of ShoppingCartItem ($sci)'
'price is set to 0.0'
Creating guided rules
- Expand the 'show options' and add:
check NO-LOOP box
RULEFLOW-GROUP: promo-cart-rules
- Save the rule.
- Ensure your package builds:
TOOLS -> PROJECT EDITOR -> BUILD & DEPLOY
(should see green pop-up 'Build Successful')
- JBoss BRMS & BPM Suite Articles
- JBoss BPM Suite Demos
- JBoss bpmPaaS Demos