I have been working with drools rules for a while and just recently started on a dsl to make the rule authoring easier for end users. While I have been able to get a simple dsl defined and correctly compiling into drl as expected, i cannot get the dsl feature of 'adding constraints to previous expression' to work. I am even trying the simplest of examples from the drools dsl guide and this will not compile the Conditions i have defined beginning with '-' into the previous expression. I keep getting a 'mismatched input 'price' in rule "Rule1Sample_0" error on compiling it. as i said I have this working for straightforward Condition expressions and Consequence expressions. but adding contraints following the docs is just not working at all. I am using drools version 7.0.0.Final, is this something thats not supported until a later version?
in the simple example i am testing, my dsl file just contains:
[condition][]There is a {ShoppingCart} that=${ShoppingCart!lc} : ${ShoppingCart!ucfirst}()
[condition][]- total price is greater than 1000 =totalPrice > 1000
[consequence]Update {ShoppingCart}=System.out.println("{ShoppingCart}" + " test")
Here is the Condition
"There is a ShoppingCart that total price is greater than 1000"
and Action which i am specifying for the when and then part of my template:
"Action" "Update ShoppingCart"
Here is the compiled drl before I pass it to the DrlParser:
rule "Test1"
dialect "mvel"
when
"There is a ShoppingCart that total price is greater than 1000"
then
"Update ShoppingCart"
end
This is what expandedDrl string contains after above code snippet runs:
package com.sample.test
rule "Test1"
dialect "mvel"
when
$shoppingcart : $Shoppingcart() total price is greater than 1000
then
System.out.println("ShoppingCart" + " test")
end
And here is the generated drl for this when i parse it using the DRLParser:
(code snippet here, some omitted)
DrlParser parser = new DrlParser();
DefaultExpanderResolver resolver = new DefaultExpanderResolver(new StringReader(dsl));
String expandedDrl = parser.getExpandedDRL(dslr, resolver);
This is what expandedDrl string contains after above code snippet runs:
package com.sample.test
rule "Test1"
dialect "mvel"
when
$shoppingcart : $Shoppingcart() total price is greater than 1000
then
System.out.println("ShoppingCart" + " test")
end
And the compiler error i see in the console:
[[13,43]: [ERR 102] Line 13:43 mismatched input 'price' in rule "Test1" ....
Could you try condition
Could you try following dsl
this should be able to process rules like
If you want to reuse conditions in other conditions you want them to be atomic. Good rule of the thumb to embrace RHS with braces () not to break atomicy of the record
test
domain
rdslr
business.dsl
keywords.dsl
test output