I am able to enforce the order with the salience attribute.
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.
Regards
Meeraj
Ah, sorry, didn't realize that syntax wasn'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).
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'll also get performance improvements by doing so.
dave2010/7/16 Meeraj Kunnumpurath <mkunnumpurath@googlemail.com>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
MeerajOn Fri, Jul 16, 2010 at 5:04 PM, Meeraj Kunnumpurath <mkunnumpurath@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
Meeraj2010/7/16 David Sinclair <dsinclair@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.
dave2010/7/16 Meeraj Kunnumpurath <mkunnumpurath@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@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users