Lab 04 - Create a Domain Specific Language (DSL)

Lab Goal

To create a DSL and a guided rule based on this DSL to calculate the free shipping threshold for Cool Store

Create a new Domain Specific Language

  • First we will start with a Domain Specific Language (DSL)
    • we will create an English DSL for our analysts
    • this allows you to target the domain terms
    • business users can then easily design rules

Create a new DSL

  • We need to create a language for Promotion rules
  • Create a DSL that allows business to determine threshold for free shipping:
    • If customer spends X amount, then apply free shipping
  • Go on to next slide to see how we design our DSL

Create a new DSL

  • Head over to the project authoring perspective
    • AUTHORING -> PROJECT AUTHORING

Create a new DSL

  • Create our new DSL:
    • New Item -> DSL DEFINITION
    • DSL DEFINITION: Promotions DSL
    • PACKAGE: default
    • click on +OK

Create a new DSL

  • You now have an empty text field to enter your DSL
  • It is a definition divided into a WHEN and 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
  • below view of editor and sources (see tabs at bottom)
  • SAVE, your DSL when finished

If you want to skip the typing, paste this instead:

  • [when]If customer spends ${var}=$sc : ShoppingCart( cartItemTotal >= {var} )
  • [then]Apply Free Shipping=$sc.setShippingPromoSavings( $sc.shippingTotal * -1 ); $sc.setShippingTotal( 0 ); update ($sc);

Guided Rule with DSL

  • We next will create a rule using the DSL we created
    • NEW ITEM -> GUIDED RULE
    • RESOURCE NAME: Free Shipping Promotion DSL
    • check 'Use Domain Specific Language (DSL)'

Guided Rule with DSL

  • The guided rule editor is now before you, but empty
  • Note the `+` signs on the right, it opens a list of options
  • Top `+` is for the WHEN (condition) section of our rule
    • pop-up shows all possibilities, but we want DSL conditions
    • check the `Only display DSL conditions` box

Guided Rule with DSL

  • Now let us create our condition (WHEN):
    • If customer spends $75

Guided Rule with DSL

  • Note that the added DSL line has a `VAR` field
    • this marks a field where we can add a dollar value
  • next we need to add an action (THEN)
    • use the + at the THEN level of the designer to add:
    • Apply Free Shipping

Guided Rule with DSL

  • Expand the (show options...) and add items
  • To add items click on green '+' on far right to add:
    • NO-LOOP
    • be sure to check the box too

Guided Rule with DSL

  • Add another item by clicking on green '+' on far right:
    • RULEFLOW-GROUP: promo-rules
  • Save the rule

Ensure project builds

  • right pane -> OPEN PROJECT EDITOR -> BUILD (top right) -> BUILD & DEPLOY
  • will have build ERRORS around ShoppingCart, see next slide...

Guided Rule with DSL

  • Errors could be due to ShoppingCart not on rule path, to add:
    • click in Message panel on File entry 'Free Shipping Promotion DSL'
    • click on CONFIG tab on the bottom of rule
    • +NEW ITEM button at top, select ShoppingCart from Import list

Guided Rule with DSL

  • Save the Free Shipping Promotion DSL and errors will vanish:

Ensure project builds

  • right pane -> OPEN PROJECT EDITOR -> BUILD (top right) -> 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 05 - Create Guided Rules