How to use conditional logic ( or a NOT ! Operator) in a Drools Guided rule?

2,091 views
Skip to first unread message

james....@gmail.com

unread,
Oct 8, 2015, 6:48:23 PM10/8/15
to Drools Usage
All,

Am using Drools Workbench 6.2.0.Final to declaratively create Guided Rules...

My situation is something like this:

Have a Loan Data Object with the following attributes:

- state - String
- amount - double 
- interestRate - double
- message - String
- requirement - boolean

The auto-generated drl file is:

rule "Arizona"
when
loan : Loan( state == "Arizona" , amount >= 1000 , amount <= 3000 , interestRate >= 0.15 , interestRate <= 0.50 )
then
loan.setRequirement( true );
end

Question(s):

(1) How can I declaratively use the Guided Rules Editor to set the following when this rule fails:

loan.setMessage( "Allowed values for amount should be in the range of 1000 to 3000"); 

or 

loan.setMessage( "Allowed values for interest rate values should be in the range of 15% to 50%" );

(2) Is there a way to declaratively customize the response:

e.g.

either return:

<requirement>true</true>

or 

<requirement>false</requirement>
<message>Allowed values for amount should be in the range of 1000 to 3000</message>

or

<requirement>false</requirement>
<message>Allowed values for interest rate values should be in the range of 15% to 50%</message>

Thanks to all... 

Toni Rikkola

unread,
Oct 9, 2015, 3:45:32 AM10/9/15
to Drools Usage
I would split the rule into two. One rule checks the amount and reports that, then the other does the same for interest rate.

Toni

Michael Anstis

unread,
Oct 9, 2015, 3:56:27 AM10/9/15
to drools...@googlegroups.com
You could also consider using a Gudied Template or Guided Decision Table rather than a Guided Rule.

Either of the other types would allow you to use parameters in the RHS of the rule(s) such as-

Rule
when
...
then
loan.setRequired(@{1}, "@{2}" );
end

Data
true,
false, Not allowed 


On 9 October 2015 at 08:45, Toni Rikkola <toni.r...@gmail.com> wrote:
I would split the rule into two. One rule checks the amount and reports that, then the other does the same for interest rate.

Toni

--
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/60ec1171-f975-46ff-b625-d5d1a1702d17%40googlegroups.com.

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

Reply all
Reply to author
Forward
0 new messages