I am able to enforce the order with the salience attribute. <br><br>I have a nested object graph, which in fact is a JAXB object generated from Schema. I want to check an attribute nested three levels deep exists in a collection. However, any of the intermediate levels in the graph could be a null reference.<br>
<br>Regards<br>Meeraj<br><br><div class="gmail_quote">2010/7/16 David Sinclair <span dir="ltr">&lt;<a href="mailto:dsinclair@chariotsolutions.com">dsinclair@chariotsolutions.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Ah, sorry, didn&#39;t realize that syntax wasn&#39;t supported in Drools. That being said, your rules may not fire in the order they are defined. (I forget what the default behavior as far as which rule would be activated first if all conditions were satisfied).<br>

<br>What exactly are you trying to accomplish? It may be easier to write rules if you assert more of your object model into WM as opposed to the deep nesting. You&#39;ll also get performance improvements by doing so.<div>
<div></div><div class="h5"><br><br>
dave<br><br><div class="gmail_quote">2010/7/16 Meeraj Kunnumpurath <span dir="ltr">&lt;<a href="mailto:mkunnumpurath@googlemail.com" target="_blank">mkunnumpurath@googlemail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Hi Dave,<br><br>I tried the null-safe navigation as below,<br><br>rule &quot;Check debtor account number exists&quot;<br>    salience 1<br>when<br>    $c : CreditTransferTransactionInformation10(dbtrAcct.?id.?othr.?id not memberOf accountNumbers)<br>


    eval(!accountNumbers.contains($accountNumber))<br>then<br>    System.err.println($c.getInternalInfo().getStatus());<br>    System.err.println(&quot;Rule 2 executed&quot;);<br>end<br><br>I get the error<br><br>[29,57]: [ERR 102] Line 29:57 mismatched input &#39;?&#39; expecting &#39;identifier&#39; in rule &quot;Check debtor account number exists&quot; in pattern CreditTransferTransactionInformation10<br>


[29,61]: [ERR 102] Line 29:61 mismatched input &#39;?&#39; expecting &#39;identifier&#39; in rule &quot;Check debtor account number exists&quot; in pattern CreditTransferTransactionInformation10<br>[29,67]: [ERR 102] Line 29:67 mismatched input &#39;?&#39; expecting &#39;identifier&#39; in rule &quot;Check debtor account number exists&quot; in pattern CreditTransferTransactionInformation10<br>


<br>Thanks<br>Meeraj<br><br><div class="gmail_quote">On Fri, Jul 16, 2010 at 5:04 PM, Meeraj Kunnumpurath <span dir="ltr">&lt;<a href="mailto:mkunnumpurath@googlemail.com" target="_blank">mkunnumpurath@googlemail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Thanks Dave.<br><br>I think the &#39;||&#39; on rule 1 is getting short-circuited. However, it is the &#39;&amp;&amp;&#39; on rule 2 that is not getting short circuited.<br>


<br>Kind regards<br>Meeraj<br><br><div class="gmail_quote">
2010/7/16 David Sinclair <span dir="ltr">&lt;<a href="mailto:dsinclair@chariotsolutions.com" target="_blank">dsinclair@chariotsolutions.com</a>&gt;</span><div><div></div><div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">



Drools doesn&#39;t use short circuit evaluation, so all of those ORs are going to be evaluated. You may want to consider re-writing your rules or you can use MVEL&#39;s null safe navigation for this. dbtrAcct.?id == null, dbtrAcct.?id.?othr == nulll, etc.<br>




<br>dave<br><br><br><br><div class="gmail_quote">2010/7/16 Meeraj Kunnumpurath <span dir="ltr">&lt;<a href="mailto:mkunnumpurath@googlemail.com" target="_blank">mkunnumpurath@googlemail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">



<div><div></div><div>
Hi,<br><br>I have the following rules,<br><br>global java.util.Set accountNumbers;<br><br>rule &quot;rule 1&quot;<br>when<br>    $d : Document()<br>    $c : CreditTransferTransactionInformation (dbtrAcct == null || dbtrAcct.id == null || dbtrAcct.id.othr == null || <a href="http://dbtrAcct.id.othr.id" target="_blank">dbtrAcct.id.othr.id</a> == null) from $d.cstmrCdtTrfInitn.cdtTrfTxInf<br>





    $i : InternalInfo() from $c.internalInfo<br>then<br>    $i.setStatus(PaymentStatus.INVALID);<br>    $i.setErrorCode(&quot;PR002&quot;);<br>    $i.setAdditionalInfo(&quot;Account number is null&quot;);<br>end<br><br>rule &quot;rule 2&quot;<br>





when<br>    $d : Document()<br>    $c : CreditTransferTransactionInformation(internalInfo.status != PaymentStatus.INVALID &amp;&amp; <a href="http://dbtrAcct.id.othr.id" target="_blank">dbtrAcct.id.othr.id</a> not memberOf accountNumbers) from $d.cstmrCdtTrfInitn.cdtTrfTxInf<br>





    $i : InternalInfo() from $c.internalInfo<br>then<br>    $i.setStatus(PaymentStatus.INVALID);<br>    $i.setErrorCode(&quot;PR002&quot;);<br>    $i.setAdditionalInfo(&quot;Account number not available in the routing table&quot;);<br>





end<br><br>My assumption is rule 1 and rule 2 will be executed in the order they appear. Rule 1 checks all the nested attributes are not null and set the status as invalid if any of them is null. Rule 2 uses the and operator and checks the nested attribute is in the collection defined by the global, only if the object is valid. I assume the LHS of rule 2 will be short circuited if the object is invalid. However, if any of the nested property is null I get the following exception from MVEL.<br>





<br>Caused by: [Error: unable to access property (null parent): id]<br>[Near : {... Unknown ....}]<br>             ^<br>[Line: 1, Column: 0]<br>    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:861)<br>





<br>Regards<br><font color="#888888">Meeraj<br>
</font><br></div></div>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div></div></div><br>
</blockquote></div><br>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>
</div></div><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>