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
RESOURCE NAME: Promotions DSL
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
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);
Create a new Guided Rule with DSL
- We next will create a rule using the DSL we created
- Create a new guided rule
NEW ITEM -> GUIDED RULE
RESOURCE NAME: Free Shipping Promotion DSL
CHECK 'Use Domain Specific Language (DSL)' BOX
OK
Create a new 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 overview of all possibilities, but we want DSL conditions
- check the `Only display DSL conditions` box
Create a new Guided Rule with DSL
- Now let us create our condition (WHEN):
Create a new 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
Create a new Guided Rule with DSL
- Expand the 'show options
SAVE
and add:
check NO-LOOP box
RULEFLOW-GROUP: promo-rules
- Save the rule
Create a new Guided Rule with DSL
- Ensure your package builds:
TOOLS -> PROJECT EDITOR -> BUILD & DEPLOY
(should see green pop-up 'Build Successful')
- if ERRORS around ShoppingCart, see next slide
Create a new Guided Rule with DSL
- Errors could be due to ShoppingCart not on rule path, to add:
CONFIG tab on the bottom of rule
+NEW ITEM button at top, select ShoppingCart from Import list
- Save rule, build project, should see green pop-up
Build Successful
- JBoss BRMS & BPM Suite Articles
- JBoss BPM Suite Demos
- JBoss bpmPaaS Demos