Am creating a small rule engine and using drools for it. My design is like the developer (that's me :)) will develop dsl and a business user can create rules (dslr).
dsl file
[When]When [Pp]urchase amount is greater than "{Value}" = e : Event(EventAction.isPurchaseGreaterThan(e,{Value}))
[When]If [Cc]ustomer tier equals to "{CustomerTier}"=e1 : Event(EventAction.isCustomerTierEqualTo(e1,"{CustomerTier}")
[Then]Give "{Discount}" Percentage Discount = RewardAction.applyDiscount(e, {Discount});
[Then]Suggest Redemption = System.out.println("Redemption Suggested");
dslr file
rule "Discount For Purchase-1"
when (When purchase amount is greater than "100") && (If customer tier equals to "Silver")
then #Error is thrown in this line
Give "5" Percentage Discount
end
The rest of the java code is similar to the one given in examples. In this code am getting the following error
Error
Line 15:4 mismatched input 'then' in rule "Discount For Purchase-1"
Whereas the below dslr works fine
rule "Discount For Purchase-1"
when (When purchase amount is greater than "100")
then
Give "5" Percentage Discount
end
Generated DRL
when (e : Event(EventAction.isPurchaseGreaterThan(e,100))) && (e : Event(EventAction.isCustomerTierEqualTo(e,"Silver"))
Note on this Generated DRL - I might get duplicate variable error for 'e'. That's another problem. But just to sort out this problem i've even tried modifing the second variable to 'e1' in dsl.
And for your information i've tried the below to resolve the error, but noting helped me out
When (When purchase amount is greater than "100" && If customer tier equals to "Silver")
When (When purchase amount is greater than "100" and If customer tier equals to "Silver")
When ((When purchase amount is greater than "100") && (If customer tier equals to "Silver"))
When ((When purchase amount is greater than "100") and (If customer tier equals to "Silver"))
When ((When purchase amount is greater than "100") and (If customer tier equals to "Silver"));
When ((When purchase amount is greater than "100") && (If customer tier equals to "Silver"));
Update :
Generated drl
=== DRL xpanded from DSLR ===
1 #created on: 5 Oct, 2016
2 package com.test.loyalty.rules
3
4 #list any import classes here.
5 import com.test.loyalty.*
6 import com.test.loyalty.model.*
7 import com.test.loyalty.util.*
8
9
10
11 #declare any global variables here
12
13 rule "Discount For Purchase-1"
14 when
15 e : Event(EventAction.isPurchaseGreaterThan(e,100))
16 e1 : Event(EventAction.isCustomerTierEqualTo(e1,"Silver")
17 then
18 System.out.println("Redemption Suggested");
19 end
20
21 rule "Discount For Purchase-2"
22 when
23 e : Event(EventAction.isPurchaseGreaterThan(e,100))
24 e1 : Event(EventAction.isCustomerTierEqualTo(e1,"Gold")
25 then
26 System.out.println("Redemption Suggested");
27 end
28
=============================
[ERR 102] Line 17:4 mismatched input 'then' in rule "Discount For Purchase-1"
17
[ERR 102] Line 25:4 mismatched input 'then' in rule "Discount For Purchase-2"
25
java.lang.IllegalArgumentException: Could not parse knowledge.
at com.test.loyalty.LoyaltyTest.readKnowledgeBase(LoyaltyTest.java:124)
at com.test.loyalty.LoyaltyTest.init(LoyaltyTest.java:104)
at com.test.loyalty.LoyaltyTest.main(LoyaltyTest.java:38)
can somebody help me with this? Thanks in advance.