Drools - default rule
I am trying to create a Drools template to generate rules from a spreadsheet. We want the user to be able to create "default rules" by leaving a field blank. To make a simplified example: We want to add a surcharge to the price of an item based on a certain code. There is a default surch开发者_如何转开发arge if none of the codes apply to this item. Like:
Code Surcharge
103 $50
297 $40
334 $30
$20
So basically I want rules that say
when
$u : Unit(code=103)
then
$u.setSurcharge(50)
etc.
Then if none of the surcharges match, I want to set the surcharge to $20.
If I was handwriting these rules, I'd give the default surcharge a lower salience and put them in an activation group or some such so the default wouldn't fire unless none of the explicit values fired.
But I'm trying to generate this with a template. I don't see how to how to make the template say "if @{code}=blank then salience=10 else salience=20" or some such. There's just no way to say that.
(Note: I can't just hardcode the default rule because really there are other fields examined in conjunction with the field that might be blank. That is, there can be many rules with blank code that apply depending on matching with other fields.)
精彩评论