Using if else construct under when Drools Workbench

2,854 views
Skip to first unread message

Harshal Joshi

unread,
Jan 18, 2016, 5:31:38 AM1/18/16
to Drools Usage
Hi all.

I was trying to create some slightly complicated rules which essentially needed the if else construct. After fiddling around for a while, I was able to write the correct rules and check them using my Eclipse.

However, the ultimate aim is to have my user create custom "on-the-fly" rules for which we chose the Drools Workbench as the UI. However, even after repeated searching and struggling, I'm unable to get this done in the workbench. 

Is it possible to have an if-else construct in the Workbench?

What I'm looking for is somewhat similar to this example taken from the documentation.

rule "Give free parking and 10% discount to over 60 Golden customer and 5% to Silver ones"
when
    $customer : Customer( age > 60 )
    if ( type == "Golden" ) do[giveDiscount10]
    else if ( type == "Silver" ) break[giveDiscount5]
    $car : Car ( owner == $customer )
then
    modify($car) { setFreeParking( true ) };
then[giveDiscount10]
    modify($customer) { setDiscount( 0.1 ) };
then[giveDiscount5]
    modify($customer) { setDiscount( 0.05 ) };
end



Thanks and regards :)
Harshal Joshi 

Toni Rikkola

unread,
Jan 18, 2016, 6:23:54 AM1/18/16
to Drools Usage
This is not possible. The guided editors do not support this feature.
Only way to do this is to use the raw DRL editor. Same way you did it in the Eclipse.

Toni

Jeff Jensen

unread,
Jan 18, 2016, 9:05:29 AM1/18/16
to drools...@googlegroups.com
That's an interesting Drools feature but I suggest writing it as the two rules it is instead of one.  As two rules, it's easier to understand and maintain.  If more condition permutations exist, I would consider the value of writing them as a decision table instead.


--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/bffd5392-b3aa-439f-b34c-a7070b1fe1c7%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Harshal Joshi

unread,
Jan 19, 2016, 12:16:15 AM1/19/16
to Drools Usage
@Toni. I also believed that to be the case, just wanted to confirm if I've missed certain elements of Workbench. Anyways thanks a ton :) 

@Jeff.Yeah I've also tried using multiple rules for the same. However, I personally found this feature to be better and more easily interpret-able #just_a_personal_opinion :D :D . 
Decision tables are not of much use for me currently as the rule complexity varies vastly in different cases. 

Thanks a lot for your quick reply guys :)
Reply all
Reply to author
Forward
0 new messages