guolei
guolei

Reputation: 99

How to use drools to fit complex condition?

Recently I am leaning drools,I think it is a great software.Drools‘s core idea is drl file.We should write the rule file,For example:

 rule "name"
   when
   then
 end

And the when section depend on the entity's property.For example:Now I have a User class which is ready to use in my rule.

 public  class User {
        private int money; 
        private Date time;
            //getter and setter.....   
        }

Now I need to know a user's money between 2012-09-11 and 2013-01-01,and if his money>100 then do my logic,How drools do?

Upvotes: 0

Views: 2040

Answers (2)

Jaydeep Rajput
Jaydeep Rajput

Reputation: 3673

You can write a function in DRL file which will return true if user's money between 2012-09-11 and 2013-01-01 is greater than 100. You can call this function from when part of your rule using eval and write your logic in then part.Writing functions is not good idea in DRL files though!

Upvotes: 0

Esteban Aliverti
Esteban Aliverti

Reputation: 6322

That could be easily been achieved using the following rule:

rule 'Some Rule'
    $u: User( time > '11-sep-2009', time < '01-jan-2013', money > 100)
then
    //do your logic here. $u references the User object
end

Hope it helps,

Upvotes: 2

Related Questions