Drools Kie - Rule Templates

From Training Material
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
title
Drools Guvnor - Decision Table
author
Bernard Szlachta (NobleProg Ltd)

Drools Guvnor - Rule Templates


Copy existing project and tests。⌘

  1. Copy npproj2 to npproj3
  2. Remove Decision Table
  3. Keep Data Objects and Tests

Create New Rule Template 新建规则模板 。⌘

  • Create New -> New Rule Template

Drools-RulesTemplates.png

Create New Rule Template - Source 新建规则模板 - 源码 。⌘

Source should look like that:

package nppack;

rule "Progressive Discount Rule Template_3"
	dialect "mvel"
	when
		$sc : ShoppingCart( totalPrice >= 80000B , totalPrice < 99999999999B , discountRate == null )
	then
		modify( $sc ) {
				setDiscountRate( 0.15 )
		}
end

rule "Progressive Discount Rule Template_2"
	dialect "mvel"
	when
		$sc : ShoppingCart( totalPrice >= 50000B , totalPrice < 80000B , discountRate == null )
	then
		modify( $sc ) {
				setDiscountRate( 0.12 )
		}
end

rule "Progressive Discount Rule Template_1"
	dialect "mvel"
	when
		$sc : ShoppingCart( totalPrice >= 10000B , totalPrice < 50000B , discountRate == null )
	then
		modify( $sc ) {
				setDiscountRate( 0.1 )
		}
end

rule "Progressive Discount Rule Template_0"
	dialect "mvel"
	when
		$sc : ShoppingCart( totalPrice >= 0B , totalPrice < 10000B , discountRate == null )
	then
		modify( $sc ) {
				setDiscountRate( 0 )
		}
end

Testing ⌘

测试 。