Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drools get facts from database at runtime

Tags:

drools

I need a little help with Drools eval and variable assigning.

rule "check that no previously submitted requests exist"
when
    $user : UserFormField( name == 'employeeId', value != null )
    $repository : Repository(  )
    $activeRequests : List( ) from $repository.findActiveRequestsByEmployee( $user.getValue() ) # call to repository
    eval( $activeRequests.size() > 0 )
then
    System.err.println(' You have active requests: ' + ((Request)$activeRequests.get(0)).getTitle);
    insert(Boolean.TRUE);
end

In this rule I try to access repository and get active requests for current user. Rule compiles and executes without any exceptions or warnings. In debug mode it can be seen that repository returns non empty list and I expect to see console message 'You have active requests' but this doesn't happen. I think the problem is in this line

$activeRequests : List( ) from $repository.findActiveRequestsByEmployee( $user.getValue() )

because this rule works fine

rule "check that no previously submitted requests exist"
when
    $user : UserFormField( name == 'employeeId', value != null )
    $repository : Repository(  )
    eval( $repository.findActiveRequestsByEmployee($user.getValue()).size() > 0 )
then
    System.err.println(' You have active requests !' );
    insert(Boolean.TRUE);
end

So could someone point me how to solve this problem?

Thanks!

like image 964
ATMTA Avatar asked May 24 '13 15:05

ATMTA


1 Answers

I was helped to find a solution. I should use from collect expression instead simple from to bundle facts into collection :

$activeRequests : ArrayList() from collect ( Request() from $repository.findActiveRequestsByEmployee( $user.getValue() ) )
like image 195
ATMTA Avatar answered Nov 16 '22 09:11

ATMTA