[rules-users] Nested properties and memberOf

Meeraj Kunnumpurath mkunnumpurath at googlemail.com
Fri Jul 16 10:56:15 EDT 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100716/3d085f58/attachment.html 


More information about the rules-users mailing list