Lab 04 - Create a Domain Specific Language (DSL)

Lab Goal

To create a DSL and a guided rule based on this DSL to

calculate free shipping threshold for online retail web shop

Create a new DSL

  • Domain Specific Language (DSL) is for:
    • analysts to create English language based rules
    • targets specific domain terminology
    • business users to design rules in a limited domain

Create a new DSL

  • For online retail web shop you'll need to:
    • create a language for Promotion rules
    • create a DSL allowing businsess user to determine threshold for free shipping:
      • If customer spends X amount, then apply free shipping
    • Let's see this works on the next slide...

Open projects view

  • Open retail web shop project:
    • DESIGN -> PROJECT

Open retail web shop project

  • Select the RETAIL-WEBSHOP project

Add new asset

  • Open new assets view:
    • click on ADD ASSET button

Add a new DSL

  • Select new dsl definition from list:
    • click on DSL DEFINITION

Add a new DSL

  • Create new DSL:
    • Fill out Create new DSL definition pop-up as follows:
    • Click on +OK to complete

Create the DSL

  • You now have an empty text field to enter your DSL
  • Let's first examine a DSL before we create ours:
    • A DSL is a definition divided into a WHEN and a THEN section
    • WHEN - here we decide what has to happen
    • If customer spends X
    • THEN - this is the results applied if WHEN happens
    • apply free shipping, which is a formula we supply
  • In the next slide you'll create your DSL

Create the DSL

  • Either type these two lines in the DSL editor, or copy and paste:
    • [when]If customer spends ${var}=$sc : ShoppingCart( cartItemTotal >= {var} )
    • [then]Apply Free Shipping=$sc.setShippingPromoSavings( $sc.shippingTotal * -1 ); $sc.setShippingTotal( 0 ); update ($sc);

Don't forget to save

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

Create new guided rule

  • Now let's create an asset (guided rule) using our DSL
  • To add a guided rule, first have to return to Asset view
  • Click on retail-webshop project in bread crumb menu at top
  • (Returning to Asset view can be done at any time)

Create new guided rule

  • Click on ADD ASSET -> GUIDED RULE to open pop-up and create 'Free Shipping Promotion DSL' rule as shown (include checked box for DSL sentences):
  • PACKAGE: Default
  • Click on +OK to create rule

Guided rule with DSL

  • The guided rule editor is now open before you
  • Note the green `+` signs on the right, these open lists of options

Guided rule with DSL

  • Top green `+` is for the WHEN (condition) section of our rule
  • Click on this top green `+` to open pop-up:

Guided rule with DSL

  • pop-up shows all possibilities, but we want DSL conditions
  • check the `Only display DSL conditions` box

Guided rule with DSL

  • Let's create a condition (WHEN) that is as follows:
    • If custoemr spends $75
  • Select the single rule shown from the DSL
  • Click on +OK to insert in the DSL editor

Guided rule with DSL

  • The added DSL line has a VAR field
  • This field is where you add the dollar value
  • Change the VAR field to 75

Don't forget to save

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

Guided rule with DSL

  • Next use the bottom green `+` to add the THEN (action) section of our rule
  • In pop-up select Apply Free Shipping and click on +OK:

Guided rule with DSL

  • Now click to expand the (show options...)
  • To add options, click on green `+` on far right and add:
    • NO-LOOP
    • Don't forget to check the no-loop box

Guided rule with DSL

  • Add another option by clicking on green `+` on far right:
    • RULEFLOW-GROUP
    • ruleflow-group: promo-rules

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 4:
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 5 - Create guided rules