Lab 05 - Create Guided Rules

Lab Goal

To create guided rules calculating shopping cart totals,

shopping cart item totals, and apply promotions

for online retail web shop

Create new guided rule

  • In lab 4 you created a guided rule using your DSL
  • Now let's create a guided rule wihtout using a DSL
  • To add a guided rule, first have to return to Asset view
  • Click on retail-webshop project in bread crumb menu at top

Create new guided rule

  • Click on ADD ASSET -> GUIDED RULE to open pop-up and create 'Total Shopping Cart' rule as shown:
  • Click on +OK to create rule

Creating guided rule

  • The guided rule editor is now open before you
  • Note the green `+` signs on the right, these open lists of options
  • Switch tabs by clicking on Data Objects tab

Creating guided rule

  • This view is of the available date model objects for use in this guided rule
  • Using '+New item' add data model objects as as shown (4x)
  • If any object is not showing, it's outside the same package as this guided rule. If that's the case, use +New Item to import (should not be necessary)

Creating guided rule

  • Return to Model tab and start designing guided rule
  • Top green `+` is for the WHEN (condition) section of our rule
  • Click on this top green `+` to open pop-up:

Creating guided rule

  • The condition (WHEN) need is:
    • There is a 'ShoppingCart'
  • Select ShoppingCart from menu and click on +OK

Creating guided rule

  • The condition has now been added to the WHEN section:
  • To assign variable name '$sc' click on ShoppingCart for pop-up
  • Fill in Variable name as shown and click on Set button:

Creating guided rule

  • The action (THEN) is a two part action
  • Click on bottom green '+' on right for pop-up
  • We want to modify value of ShoppingCart ($sc)
    • in pop-up, select Modify $sc... and click +OK to add

Creating guided rule

  • Now add a field cartTotal in THEN section
  • Click on pencil icon and select field cartTotal in pop-up to add:

Creating guided rule

  • Now assign value 0.0 to cartTotal
  • Click on pencil icon next to cartTotal, select Literal value:

Creating guided rule

  • Can you complete the second action (THEN) yourself?
  • 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 rule

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

Don't forget to save

  • Click SAVE and again on confirm pop-up SAVE:

Create new guided rule

  • Let's create a guided rule: Apply Cart Item Promotions
  • To add a guided rule, first have to return to Asset view
  • Click on retail-webshop project in bread crumb menu at top

Create new guided rule

  • Click on ADD ASSET -> GUIDED RULE to open pop-up and create 'Apply Cart Item Promotions' rule as shown:
  • PACKAGE: Default
  • Click on +OK to create rule

Creating guided rule

  • 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
    itch tabs by clicking on Data Objects tab

Creating guided rule

  • Start by adding all domain model objects as shown in the Data Objects tab:
  • Return to the Model tab to start on the guided rule

Creating guided rule

  • The condition (WHEN) Part I:
    • 'There is a ShoppingCartItem'
    • Assign a variable name to this ShoppingCart '$sci'
    • Add a restriction on field 'itemID'
    • Assign by clicking, variable name to itemID: '$itemID'

Creating guided rule

  • The condition (WHEN) Part II:
    • Use top green + to add second condition
    • Start with from Entry Point and fill in: 'Promo Stream'

Creating guided rule

  • The condition (WHEN) Part II (continued):
    • Within condition click on red '(click to add patterns...)'
    • Add PromoEvent, results in 'There is a PromoEvent'

Creating guided rule

  • Next, clicking on `There is a PromoEvent` for a pop-up
  • Select from drop down menu for multiple field constraint:
    • All of (And)
    • Results in 'with all of the following'

Creating guided rule

  • Next, click on 'all of the following' line to add:
    • Add a restriction on a field, select itemId
    • Now use drop down menu to set it 'equal to'

Creating guided rule

  • Next, click on the pencil icon for pop-up:
    • Click on the Advanced options: Bound variable
    • Select itemID from the inserted list

Creating guided rule

  • To wrap up the condition (WHEN), click on 'all of the following' line to add:
    • Add a restriction on a field, select percentOff
    • Click on percentOff and bind field to variable: '$pctOff'
    • percentageOff is over sliding window: 'none'

Creating guided rule

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

Don't forget to save

  • Click SAVE and again on confirm pop-up SAVE:

Creating guided rule

  • The actions (THEN) part of our rule is next, add the following using bottom green `+`:
    • Add: 'Modify value of ShoppingCartItem ($sci)'
    • Use pencil icon adding: 'promoSavings is set to 0.0'
    • Add second: 'Modify value of ShoppingCartItem ($sci)'
    • Use pencil icon adding: 'price is set to 0.0'

Creating guided rule

  • Expand the 'show options' and add:
    • check NO-LOOP box
    • RULEFLOW-GROUP: promo-cart-rules

Creating guided rule

  • This completes the guided rule, looking like this:

Don't forget to save

  • Click SAVE and again on confirm pop-up SAVE:

Lab Completed

What you should see...

  • Click on retail-web shop project (use bread crumb menu at the top) for assets view, this ends lab 5:
Eric D. Schabell
Portfolio Architect Director
@ericschabell
http://schabell.org
More Red Hat Decision Manager Workshops

Red Hat Decision Manager Articles

Red Hat Decision Manager Demos

Decision Manager Workshop

Up next...

Lab 6 - Create Technical Rules (DRL)