<br> Mark,<br><br> Sorry for not answering before. I was doing some research. <br> What you found is a bug. Contains and not contains are supported operations in Drools, but the case you are facing is that you are using these operators with accessors expressions (
e.g. nurseDetails.stateLicensures ). When an accessor expression is used, the engine converts the whole expression in an inline-eval. So what you are doing will be interpreted by the engine as:<br><br> $ca:CandidateAssociation( eval (
nurseDetails.stateLicensures not contains patientDetails.state ) )<br><br> Problem is that "not contains" is not a valid operator for MVEL. May I ask you please to open a JIRA for that? I will fix it asap.<br>
<br> Meanwhile, to work around the problem you can either avoid the accessor path expression when using "contains/memberOf/matches" and their corresponding negations, or write the inline eval yourself, avoid a mistranslation by the engine. So, if you are using mvel dialect for your rule, you could write:
<br><br>rule XXX<br> dialect "mvel"<br>when<br> $ca:CandidateAssociation( eval ( ! nurseDetails.stateLicensures.contains( patientDetails.state ) ) )<br>then<br> // do something<br>end<br> <br> Please not that as you are explicitly declaring the mvel dialect for your rule, your consequence will also be an MVEL block.
<br><br> Sorry for the inconvenience. I will fix that for 4.0.1.<br><br> Thanks,<br> Edson<br><br><div><span class="gmail_quote">2007/8/1, <a href="mailto:mark.mcnally@comcast.net">mark.mcnally@comcast.net</a> <
<a href="mailto:mark.mcnally@comcast.net">mark.mcnally@comcast.net</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>Actually, it is still broken.
<br><br>This does not complain but it always executes the consequence, even when the stateLicensures includes the state that in patientDetails.state<br><br> $ca:CandidateAssociation(nurseDetails.stateLicensures not contains
patientDetails.state )<br><br><br>I also tried the following but it complains with an Exception<br><br> $ca:CandidateAssignment(participantDetails.state not memberof nurseDetails.stateLicensures )<br><br><br>org.drools.rule.InvalidRulePackage
: [13,50]: unknown:13:50 Unexpected token 'not'[13,93]: unknown:13:93 mismatched token: [@98,574:574=')',<13>,13:93]; expecting type LEFT_PAREN<br> at org.drools.rule.Package.checkValidity(Package.java
:408)<br> at org.drools.common.AbstractRuleBase.addPackage(AbstractRuleBase.java:288)<br><br><br>Is what I am trying to do supported by Drools?<br><br>Thank you,<br>Mark<br><br><br> -------------- Original message ----------------------
<br>From: <a href="mailto:mark.mcnally@comcast.net">mark.mcnally@comcast.net</a><br>> My rule now appears to be working after switching from the "excludes" operator<br>> to the newer "not contains".
<br>><br>> This works:<br>> $ca:CandidateAssociation(nurseDetails.stateLicensures not contains<br>> patientDetails.state )<br>><br>> This does not:<br>> $ca:CandidateAssociation(nurseDetails.stateLicensures
excludes<br>> patientDetails.state )<br>><br>><br>> Mark<br>><br>> -------------- Original message ----------------------<br>> From: <a href="mailto:mark.mcnally@comcast.net">mark.mcnally@comcast.net
</a><br>> > Hello,<br>> ><br>> > Please excuse me if I have double posted - my first did not seem to appear.<br>> ><br>> > I am wondering if the following is valid rule syntax. I am getting a
<br>> stacktrace<br>> > when the rules fire that points to a ClassCastException on a HashSet<br>> ><br>> > I am using v4.0 GA.<br>> ><br>> > Thank you, Mark<br>> ><br>> ><br>> > rule StateMatch
<br>> > when<br>> > $ca:CandidateAssociation(nurseDetails.stateLicensures excludes<br>> > patientDetails.state )<br>> > then<br>> > retract( $ca );<br>> > end<br>
> ><br>> ><br>> > public class CandidateAssociation {<br>> > private PatientDetails patientDetails;<br>> > private NurseDetails nurseDetails;<br>> > private int overlapHours;
<br>> ><br>> > public CandidateAssociation( PatientDetails patientDetails, NurseDetails<br>> > nurseDetails) {<br>> > super();<br>> > this.patientDetails = patientDetails;
<br>> > this.nurseDetails = nurseDetails;<br>> > overlapHours =<br>> > participantDetails.getNumberOverlapHourCnt(nurseDetails);<br>> > }<br>> > [...]<br>> > }
<br>> ><br>> > public class NurseDetails {<br>> > private Set stateLicensures = new HashSet();<br>> > [...]<br>> > }<br>> > public class PatientDetails {<br>> > private String state;
<br>> > [...]<br>> > }<br>> ><br>> > ------------------------------------------------------<br>> > Firing Rules<br>> > **********<br>> > org.drools.RuntimeDroolsException: Exception executing predicate
<br>> > org.drools.base.mvel.MVELPredicateExpression@27d6bfb<br>> > at<br>> > org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:197)<br>> > at org.drools.reteoo.AlphaNode.assertObject
(AlphaNode.java:121)<br>> > at<br>> ><br>> org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObje<br>> > ctSinkAdapter.java:317)<br>> > at<br>> > org.drools.reteoo.ObjectTypeNode.assertObject
(ObjectTypeNode.java:159)<br>> > at org.drools.reteoo.Rete.assertObject(Rete.java:175)<br>> > at<br>> > org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:190)<br>> > at<br>
> > org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:70)<br>> > at<br>> > org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:772)<br>> > at<br>
> > org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:64)<br>> > at<br>> > org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:58)<br>> > at<br>
> ><br>> org.drools.examples.Rule_InitializeCandidateForEachNurse_0.consequence(Rule_Init<br>> > ializeCandidateForEachNurse_0.java:13)<br>> > at<br>> ><br>> org.drools.examples.Rule_InitializeCandidateForEachNurse_0ConsequenceInvoker.eva
<br>> > luate(Rule_InitializeCandidateForEachNurse_0ConsequenceInvoker.java:25)<br>> > at<br>> > org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:503)<br>> > at org.drools.common.DefaultAgenda.fireNextItem
(DefaultAgenda.java:467)<br>> > at<br>> ><br>> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:<br>> > 403)<br>> > at<br>> ><br>> org.drools.common.AbstractWorkingMemory.fireAllRules
(AbstractWorkingMemory.java:<br>> > 384)<br>> > at<br>> > primarynursePOC.PrimaryNursePOC.selectPrimaryNurse(PrimaryNursePOC.java:136)<br>> > at primarynursePOC.PrimaryNursePOC.main(PrimaryNursePOC.java
:91)<br>> > Caused by: java.lang.ClassCastException: java.util.HashSet<br>> > at<br>> ><br>> org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPredicateExpression.ja<br>> > va:35)<br>
> > at<br>> > org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:191)<br>> > ... 17 more<br>> > org.drools.RuntimeDroolsException: Exception executing predicate<br>> >
org.drools.base.mvel.MVELPredicateExpression@27d6bfb<br>> > at<br>> > org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:197)<br>> > at org.drools.reteoo.AlphaNode.assertObject
(AlphaNode.java:121)<br>> > at<br>> ><br>> org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObje<br>> > ctSinkAdapter.java:317)<br>> > at<br>> > org.drools.reteoo.ObjectTypeNode.assertObject
(ObjectTypeNode.java:159)<br>> > at org.drools.reteoo.Rete.assertObject(Rete.java:175)<br>> > at<br>> > org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:190)<br>> > at<br>
> > org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:70)<br>> > at<br>> > org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:772)<br>> > at<br>
> > org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:64)<br>> > at<br>> > org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:58)<br>> > at<br>
> ><br>> org.drools.examples.Rule_InitializeCandidateForEachNurse_0.consequence(Rule_Init<br>> > ializeCandidateForEachNurse_0.java:13)<br>> > at<br>> ><br>> org.drools.examples.Rule_InitializeCandidateForEachNurse_0ConsequenceInvoker.eva
<br>> > luate(Rule_InitializeCandidateForEachNurse_0ConsequenceInvoker.java:25)<br>> > at<br>> > org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:503)<br>> > at org.drools.common.DefaultAgenda.fireNextItem
(DefaultAgenda.java:467)<br>> > at<br>> ><br>> org.drools.common.AbstractWorkingMemory.doOtherwise(AbstractWorkingMemory.java:4<br>> > 30)<br>> > at<br>> ><br>> org.drools.common.AbstractWorkingMemory.fireAllRules
(AbstractWorkingMemory.java:<br>> > 412)<br>> > at<br>> ><br>> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:<br>> > 384)<br>> > at<br>> > primarynursePOC.PrimaryNursePOC.selectPrimaryNurse
(PrimaryNursePOC.java:136)<br>> > at primarynursePOC.PrimaryNursePOC.main(PrimaryNursePOC.java:91)<br>> > Caused by: java.lang.ClassCastException: java.util.HashSet<br>> > at<br>> ><br>>
org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPredicateExpression.ja<br>> > va:35)<br>> > at<br>> > org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:191)<br>> > ... 18 more
<br>> > Exception in thread "main" org.drools.spi.ConsequenceException:<br>> > org.drools.RuntimeDroolsException: Exception executing predicate<br>> > org.drools.base.mvel.MVELPredicateExpression@27d6bfb
<br>> > at<br>> > org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:507)<br>> > at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:467)<br>> > at<br>> >
<br>> org.drools.common.AbstractWorkingMemory.doOtherwise(AbstractWorkingMemory.java:4<br>> > 30)<br>> > at<br>> ><br>> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java
:<br>> > 412)<br>> > at<br>> ><br>> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:<br>> > 384)<br>> > at<br>> > primarynursePOC.PrimaryNursePOC.selectPrimaryNurse
(PrimaryNursePOC.java:136)<br>> > at primarynursePOC.PrimaryNursePOC.main(PrimaryNursePOC.java:91)<br>> > Caused by: org.drools.RuntimeDroolsException: Exception executing predicate<br>> > org.drools.base.mvel.MVELPredicateExpression@27d6bfb
<br>> > at<br>> > org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:197)<br>> > at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:121)<br>> > at<br>> >
<br>> org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObje<br>> > ctSinkAdapter.java:317)<br>> > at<br>> > org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java
:159)<br>> > at org.drools.reteoo.Rete.assertObject(Rete.java:175)<br>> > at<br>> > org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:190)<br>> > at<br>> > org.drools.reteoo.ReteooWorkingMemory.doInsert
(ReteooWorkingMemory.java:70)<br>> > at<br>> > org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:772)<br>> > at<br>> > org.drools.base.DefaultKnowledgeHelper.insert(
DefaultKnowledgeHelper.java:64)<br>> > at<br>> > org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:58)<br>> > at<br>> ><br>> org.drools.examples.Rule_InitializeCandidateForEachNurse_0.consequence
(Rule_Init<br>> > ializeCandidateForEachNurse_0.java:13)<br>> > at<br>> ><br>> org.drools.examples.Rule_InitializeCandidateForEachNurse_0ConsequenceInvoker.eva<br>> > luate(Rule_InitializeCandidateForEachNurse_0ConsequenceInvoker.java:25)
<br>> > at<br>> > org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:503)<br>> > ... 6 more<br>> > Caused by: java.lang.ClassCastException: java.util.HashSet<br>> > at
<br>> ><br>> org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPredicateExpression.ja<br>> > va:35)<br>> > at<br>> > org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java
:191)<br>> > ... 18 more<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">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>><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">https://lists.jboss.org/mailman/listinfo/rules-users</a><br><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">
https://lists.jboss.org/mailman/listinfo/rules-users</a><br></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> Software Engineer - JBoss Rules Core Developer<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646
<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>