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:
    • AUTHORING -> PROJECT AUTHORING -> NEW ITEM -> GUIDED RULE
    • Guided Rule: Total Shopping Cart
    • Package: DEFAULT
    • (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, add first with green '+' on right
  • We want to modify value of ShoppingCart ($sc)
    • in pop-up, Modify $sc...

Creating guided rules

  • click on pencil icon, select field cartTotal
  • assign via pencil icon Literal value: 0.0

Creating guided rules

  • Can you complete the second action (THEN) in same way?
    • modify value of ShoppingCart field cartItemPromoSavings to following formula (paste without back-ticks):
    • `($sc.cartItemPromoSavings == 0.0) ? 0.0 : $sc.cartItemPromoSavings * -1`
    • hint: use formula instead of literal value...

Creating guided rules

  • Expand the 'show options' and add attributes, use green '+' on right:
    • check NO-LOOP box
    • RULEFLOW-GROUP: total-rules

Creating guided rules

  • Save the rule and ensure your package builds:
    • OPEN PROJECT EDITOR -> BUILD & DEPLOY
    • (should see green pop-up 'Build Successful')

Creating guided rules

  • First we will create a new guided rule:
    • AUTHORING -> PROJECT AUTHORING -> NEW ITEM -> GUIDED RULE
    • Guided Rule: Apply Cart Item Promotions
    • Package: DEFAULT
    • (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

  • Start by importing model object ShoppingCartItem for this rule:
    • CONFIG tab on the bottom of rule
    • NEW ITEM button at top, select ShoppingCartItem from Import list

Creating guided rules

  • Import model object PromoEvent for this rule:
    • CONFIG tab on the bottom of rule
    • NEW ITEM button at top, select PromoEvent from Import list

Creating guided rules

  • Finally import 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

  • The condition (WHEN) Part I, back to Editor tab:
    • 'There is a ShoppingCartItem'
    • assign a variable name to this ShoppingCart '$sci'
    • looking for $sci with 'itemId'
    • assign by clicking, variable name to itemID: '$itemId'

Creating guided rules

  • The condition (WHEN) Part IIa
    • top green + sign adds second condition
    • start with from Entry Point and fill in: 'Promo Stream'

Creating guided rules

  • The condition (WHEN) Part IIa
    • within condition click on red '(click to add patterns...)'
    • add PromoEvent, results in 'There is a PromoEvent'

Creating guided rules

  • The condition (WHEN) 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 (WHEN) Part IIc
  • click on all of the following" line to add:
    • an itemId equal to the Bound variable: '$itemId'

Creating guided rules

  • The condition (WHEN) Part IIc
  • click on all of the following" line to add:
    • a percentageOff bound to a variable called '$pctOff'
    • percentageOff is over sliding window: 'none'

Creating guided rules

  • The conditions (WHEN) are finished, should look like:

Creating guided rules

  • The action (THEN) part of our rule is next (use green '+'):
    • '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

Creating guided rules

  • Save the rule and ensure your package builds:
    • OPEN PROJECT EDITOR -> BUILD & DEPLOY
    • (should see green pop-up 'Build Successful')

Lab results...

Eric D. Schabell
JBoss Technology Evangelist
@ericschabell
http://schabell.org

JBoss BRMS Workshop

Lab 06 - Create Technical Rules (DRL)