Hi Edson,
Just as a matter of interest ... How come the grammar recognizes the
null-safe accessors below
CreditTransferTransactionInformation10( eval( !( accountNumbers contains
dbtrAcct.?id.?othr.?id ) ) )
and not
CreditTransferTransactionInformation10(dbtrAcct.?id.?othr.?id not memberOf
accountNumbers )
Kind regards
Meeraj
On Fri, Jul 16, 2010 at 7:57 PM, Meeraj Kunnumpurath <
mkunnumpurath(a)googlemail.com> wrote:
Thanks Edson.
That worked like a treat
CreditTransferTransactionInformation10( eval( !( accountNumbers contains
dbtrAcct.?id.?othr.?id ) ) )
Regards
Meeraj
2010/7/16 Edson Tirelli <tirelli(a)post.com>
It does short circuit on "constraints". Not on patterns.
>
> The problem is your assumption that rules are executed in order. They
> are not. Check the manual for "Conflict Resolution".
>
> Also, the LHS of rules are executed at "insert"/"modify" time,
so the
> LHS of both rules will be executed before any of them is fired.
>
> The shortest syntax for your case is to use an mvel inline eval using
> the null-safe navigation:
>
> rule X
> dialect "mvel"
> when
> ...
> CreditTransferTransactionInformation10( eval( !( accountNumbers
> contains dbtrAcct.?id.?othr.?id ) ) )
> ...
>
> Of course, you can do all the null checks in the pattern itself,
> avoiding the need to use the mvel syntax.
>
> Edson
>
>
> 2010/7/16 Meeraj Kunnumpurath <mkunnumpurath(a)googlemail.com>
>
>> Thanks Dave.
>>
>> I think the '||' on rule 1 is getting short-circuited. However, it is
the
>> '&&' on rule 2 that is not getting short circuited.
>>
>> Kind regards
>> Meeraj
>>
>> 2010/7/16 David Sinclair <dsinclair(a)chariotsolutions.com>
>>
>> Drools doesn'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's null safe navigation for this. dbtrAcct.?id == null,
>>> dbtrAcct.?id.?othr == nulll, etc.
>>>
>>> dave
>>>
>>>
>>>
>>> 2010/7/16 Meeraj Kunnumpurath <mkunnumpurath(a)googlemail.com>
>>>
>>>> Hi,
>>>>
>>>> I have the following rules,
>>>>
>>>> global java.util.Set accountNumbers;
>>>>
>>>> rule "rule 1"
>>>> when
>>>> $d : Document()
>>>> $c : CreditTransferTransactionInformation (dbtrAcct == null ||
>>>> dbtrAcct.id == null || dbtrAcct.id.othr == null || dbtrAcct.id.othr.id==
null) from $d.cstmrCdtTrfInitn.cdtTrfTxInf
>>>> $i : InternalInfo() from $c.internalInfo
>>>> then
>>>> $i.setStatus(PaymentStatus.INVALID);
>>>> $i.setErrorCode("PR002");
>>>> $i.setAdditionalInfo("Account number is null");
>>>> end
>>>>
>>>> rule "rule 2"
>>>> when
>>>> $d : Document()
>>>> $c : CreditTransferTransactionInformation(internalInfo.status !=
>>>> PaymentStatus.INVALID && dbtrAcct.id.othr.id not memberOf
>>>> accountNumbers) from $d.cstmrCdtTrfInitn.cdtTrfTxInf
>>>> $i : InternalInfo() from $c.internalInfo
>>>> then
>>>> $i.setStatus(PaymentStatus.INVALID);
>>>> $i.setErrorCode("PR002");
>>>> $i.setAdditionalInfo("Account number not available in the
routing
>>>> table");
>>>> end
>>>>
>>>> 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.
>>>>
>>>> Caused by: [Error: unable to access property (null parent): id]
>>>> [Near : {... Unknown ....}]
>>>> ^
>>>> [Line: 1, Column: 0]
>>>> at
>>>>
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:861)
>>>>
>>>> Regards
>>>> Meeraj
>>>>
>>>> _______________________________________________
>>>> rules-users mailing list
>>>> rules-users(a)lists.jboss.org
>>>>
https://lists.jboss.org/mailman/listinfo/rules-users
>>>>
>>>>
>>>
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users(a)lists.jboss.org
>>>
https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users(a)lists.jboss.org
>>
https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
>
> --
> Edson Tirelli
> JBoss Drools Core Development
> JBoss by Red Hat @
www.jboss.com
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
>