What's a Domain Specific Language (DSL)?
A DSL is used for:
- analysts to create English language based rules
- targeting specific domain terminology
- business users to design rules in a limited domain
The retail web shop DSL
For retail web shop DSL you'll be doing the following:
- creating a language for
Promotion rules
- creating 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...
Open the retail project
Select the RETAIL-WEBSHOP project:
Add a new asset
Open new assets view and click ADD ASSET
button:
Add a new DSL
Select by clicking on new DSL DEFINITION
from the list:
Create Promotions DSL
Create new DSL by filling out the pop-up as follows and clicking on +OK
button:
Promotions DLS - An explaination
You now have an empty text field to enter your DSL
Promoations DSL has a WHEN and a THEN section as follows:
WHEN
- here we test if the WHEN needs to be executed
If customer spends X
THEN
- this is the results applied if WHEN applies
apply free shipping
, which is a formula we supply
Promotions DLS - Enter into editor
Enter 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);
Saving your work
- Be sure to SAVE your work by clicking button top right
- Optionally add a comment and click SAVE WITH COMMENTS drop-down in menu
- This completes the
Promotions DLS
Returning to Asset view
To add our first guided rule, first we have to return to Asset view by clicking on
retail-webshop
project in bread crumb menu at top. (Returning to
Asset view can be done at any time)
Free Shipping Promotion - Create 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 and click on +OK to complete):
Free Shipping Promotion - The editor
The guided rule editor is now open before you, note the green `+` signs on the
right, these open lists of options:
Free Shipping Promotion - The WHEN section
Top green `+` is for the WHEN (condition) section of our rule, click on this top
green `+` to open pop-up:
Free Shipping Promotion - Select DSL
Pop-up shows all possibilities, but we want only DSL conditions. Check
'Only display DSL conditions' box near bottom as shown:
Free Shipping Promotion - Set WHEN condition
Let's create a condition (WHEN) that is as follows:
Select displayed rule from the DSL and click +OK:
Free Shipping Promotion - Set VAR field
The added DSL line has a VAR
field, this field is where you add the
dollar value. Change the VAR
field to 75
:
Saving your work
- Be sure to SAVE your work by clicking button top right
- Optionally add a comment and click SAVE WITH COMMENTS drop-down in menu
- This completes the
WHEN
section of your rule
Free Shipping Promotion - Select THEN action
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:
Free Shipping Promotion - Set no-loop option
Now click to expand the
(show options...)
. To add options, click on
green `+` on far right and add:
NO-LOOP
from drop-down list
- Don't forget to check the no-loop box
Free Shipping Promotion - Set ruleflow-group
Add another option by clicking on green `+` on far right:
RULEFLOW-GROUP
from drop down list
ruleflow-group: promo-rules
Saving your work
- Be sure to SAVE your work by clicking button top right
- Optionally add a comment and click SAVE WITH COMMENTS drop-down in menu
- This completes the
Free Shipping Promotion DSL
guided rule
Returning to Asset view
Finally, we return to Asset view by clicking on retail-webshop
project
in bread crumb menu at top. (Returning to Asset view can be done at any time):
More Red Hat Decision Manager Workshops:
Red Hat Decision Manager Articles:
Red Hat Decision Manager Demos: