[rules-users] Nested properties and memberOf

Meeraj Kunnumpurath mkunnumpurath at googlemail.com
Fri Jul 16 14:16:58 EDT 2010


Hi Dave,

I tried the null-safe navigation as below,

rule "Check debtor account number exists"
    salience 1
when
    $c : CreditTransferTransactionInformation10(dbtrAcct.?id.?othr.?id not
memberOf accountNumbers)
    eval(!accountNumbers.contains($accountNumber))
then
    System.err.println($c.getInternalInfo().getStatus());
    System.err.println("Rule 2 executed");
end

I get the error

[29,57]: [ERR 102] Line 29:57 mismatched input '?' expecting 'identifier' in
rule "Check debtor account number exists" in pattern
CreditTransferTransactionInformation10
[29,61]: [ERR 102] Line 29:61 mismatched input '?' expecting 'identifier' in
rule "Check debtor account number exists" in pattern
CreditTransferTransactionInformation10
[29,67]: [ERR 102] Line 29:67 mismatched input '?' expecting 'identifier' in
rule "Check debtor account number exists" in pattern
CreditTransferTransactionInformation10

Thanks
Meeraj

On Fri, Jul 16, 2010 at 5:04 PM, Meeraj Kunnumpurath <
mkunnumpurath at googlemail.com> wrote:

> 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 at 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 at 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 at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100716/d133908a/attachment.html 


More information about the rules-users mailing list