So the fact referred in the query is a declared fact type which is in another DRL? Queries are the same as rules underneath, just with no traditional RHS - so it should work if it can see the declared type. You can check that by changing it to a rule, and having the RHS add the results to a global list (that is a common pattern for returning results as well).
On Sun, Oct 18, 2009 at 7:49 AM, Michael Neale <[email protected]> wrote: > Yes there is a FactType class which represents the class (like a dynabean) > and it has helper method to get at values etc. > > Sent from my phone. > > On 17/10/2009, at 9:28 AM, leif hanack <[email protected]> wrote: > >> Hi, >> since Drools 5 it is possible to define a dynamic variable holder by >> using the declare notation. This feature is really cool. >> I can create easily helper rules, that calculate temporary values: >> >> File: calculate_total_amount.drl >> >> declare TotalAmount >> amount : Money >> end >> >> rule "calculate total amount" >> when >> .. >> then >> TotalAmount totalAmount = new TotalAmount(); >> totalAmount.setAmount($calculatedAmount); >> insert(totalAmount); >> end >> >> Inside another file I use this helper. >> >> File: another_rule.drl >> >> rule "another rule" >> when >> TotalAmount( amount > 1000) >> then >> // do s.th. >> end >> >> I unit test my rule by querying a fact and verify my assertions. This >> works fine, as long as the fact is a class of my factmodel. >> Now my question: Is there a way to query a declared class (in this >> case TotalAmount) >> >> I tried it with some variations but without success: >> >> import my.package.of.the.rule; >> query "get total amount" >> amount : TotalAmount() >> end >> >> I thought that a declare is compiled to a class, but I can not find it >> in the generated classes. >> Did you have any help? >> >> An alternative might be to create a holder class. S.th. like that >> >> rule "calculate total amount" >> .. >> then >> TotalAmount totalAmount = new TotalAmount(); >> totalAmount.setAmount($calculatedAmount); >> insert(totalAmount); >> Holder holder = new Holder(); >> holder.setObject(totalAmount); >> insert(holder); >> end >> >> >> import my.package.holder; >> query "get holder" >> holder : Holder() >> end >> >> Thanks in advance, Leif >> _______________________________________________ >> rules-dev mailing list >> [email protected] >> https://lists.jboss.org/mailman/listinfo/rules-dev > -- Michael D Neale home: www.michaelneale.net blog: michaelneale.blogspot.com _______________________________________________ rules-dev mailing list [email protected] https://lists.jboss.org/mailman/listinfo/rules-dev
