我需要一些Drools eval和变量赋值的帮助.
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
在此规则中,我尝试访问存储库并获取当前用户的活动请求.规则编译和执行,没有任何例外或警告.在调试模式下,可以看到存储库返回非空列表,我希望看到控制台消息“您有活动请求”,但这不会发生.我认为问题出在这一行
$activeRequests : List( ) from $repository.findActiveRequestsByEmployee( $user.getValue() )
因为这条规则很好
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
有人能指出我如何解决这个问题吗?
谢谢!
解决方法
我帮助找到了解决方案.我应该使用collect表达式来简单地将事实捆绑到集合中:
$activeRequests : ArrayList() from collect ( Request() from $repository.findActiveRequestsByEmployee( $user.getValue() ) )