Drools rule not true, how to use 'and'?

147 views Asked by At

I'm trying to have the following working:

rule "userCount"
    when
        $user : User()
        $minutes : Integer()
            from accumulate(
                            MinutesPerUser( user == $user, $time : time) 
                            and Time(this == $time),
                            sum(1)
                           )
    then
        System.out.println( $minutes );
end

but it seems the and Time(this == $user) part is never true. If I remove that part I get some println output.

What's wrong with the above code?

1

There are 1 answers

2
laune On BEST ANSWER

Not knowing the relation of the Java classes, it's a little difficult to state definite facts. But from

 $user : User()
 //...
 and Time(this == $user),

it is quite evident that Time must be a superclass of User or vice versa: otherwise there's no way this constraint can be fulfilled.

I don't know what you should write instead, as there's no specification of what should be done.

BTW, sum(1) looks rather fishy, because that would be better expressed by count(1), producing the same result.