Lab 06 - Create Technical Rules (DRL)
Lab Goal
To create a technical rule (DRL) to total up the shopping cart items for Cool Store
Creating rules (DRL)
- Technical rules generally not created here:
- developer teams tend authors technical rules
- they are then uploaded to the repository
- they appear here in a free form editor
- there is no syntax help in editor (caution...)
- business users advised to stick with guided rule editors
- for completeness we create one technical rule here...
Creating rules (DRL)
- First we will create a new rule:
AUTHORING -> PROJECT AUTHORING -> NEW ITEM -> DRL FILE
DRL File: Total Shopping Cart Items
Package: DEFAULT
Creating rules (DRL)
- Presented with an empty free text editor for our rule (DRL)
- add package name:
package com.redhat.demos.coolstore
Creating rules (DRL)
- Add basic rule outline, noting indentation:
rule "Total Shopping Cart Items"
ruleflow-group "pricing-rules"
no-loop true
, when
, then
, end
Creating rules (DRL)
- Now lets look at the core of this rule, the condition (WHEN):
'There is a ShoppingCart'
- assign a variable name to this ShoppingCart
'$sc'
'There is a ShoppingCartItem with field shoppingCart equal to $sc'
- assign a variable name to this ShoppingCartItem
'$sci'
- Can use Fact Types in right column, just remove package names
Creating rules (DRL)
- The action (THEN) has four parts
- Modify value of $sc field cartItemTotal using formula
'$sc.setCartItemTotal( $sc.getCartItemTotal() + ($sci.getPrice() * $sci.getQuantity()));'
- Modify value of cartItemPromoSavings field using formula
'$sc.setCartItemPromoSavings($sc.getCartItemPromoSavings() + ($sci.getPromoSavings() * $sci.getQuantity()));'
- update ShoppingCart:
'update( $sc );'
- retract ShoppingCartItem:
'retract( $sci );'
Creating rules (DRL)
- Save the rule and ensure your package builds:
OPEN PROJECT EDITOR -> BUILD & DEPLOY
(should see green pop-up 'Build Successful')
Lab results...
- JBoss BRMS & BPM Suite Articles
- JBoss BPM Suite Demos
- JBoss bpmPaaS Demos