Question

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?

Was it helpful?

Solution

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,

OTHER TIPS

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top