[jboss-jira] [JBoss JIRA] (JBRULES-1058) nested accessors with Sets - "not contains" is not a valid operator for MVEL

Rahul Vanimisetty (JIRA) issues at jboss.org
Wed Mar 28 13:50:00 EDT 2018


    [ https://issues.jboss.org/browse/JBRULES-1058?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13553115#comment-13553115 ] 

Rahul Vanimisetty commented on JBRULES-1058:
--------------------------------------------

I have a mvel expression that requires the not contains operator. The expression is

input.shipment.sHIPMENTDESC not contains 'GINGER'

I get a mvel compilation error when i try the above in a junit test. The stacktrace is as below

at org.mvel2.compiler.AbstractParser.procTypedNode(AbstractParser.java:1505)
at org.mvel2.compiler.AbstractParser.createPropertyToken(AbstractParser.java:1405)
at org.mvel2.compiler.AbstractParser.nextToken(AbstractParser.java:893)
at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:126)
at org.mvel2.compiler.ExpressionCompiler.compile(ExpressionCompiler.java:67)
at org.mvel2.MVEL.compileExpression(MVEL.java:810)
at org.mvel2.MVEL.compileExpression(MVEL.java:819)
at org.mvel2.MVEL.compileExpression(MVEL.java:723)

What is the solution to the problem? Can not contains be made a valid operator. The workaround i found is to use

!(input.shipment.sHIPMENTDESC not contains 'GINGER').

But life is easier when the not contains operator is available. Please advice.

> nested accessors with Sets - "not contains" is not a valid operator for MVEL
> ----------------------------------------------------------------------------
>
>                 Key: JBRULES-1058
>                 URL: https://issues.jboss.org/browse/JBRULES-1058
>             Project: JBRULES
>          Issue Type: Bug
>          Components: drools-compiler
>    Affects Versions:  4.0.0.GA
>            Reporter: Mark McNally
>            Assignee: Edson Tirelli
>             Fix For: 4.0.1
>
>
> Following does not work:
> 		rule StateMatch
> 			when
> 			$ca:CandidateAssociation(nurseDetails.stateLicensures excludes patientDetails.state  )			
> 			then 	
> 				retract( $ca );
> 		end
> 		
> 		
> 		public class CandidateAssociation {
> 			private PatientDetails patientDetails;
> 			private NurseDetails   nurseDetails;
> 			private int overlapHours;
> 		
> 			public CandidateAssociation( PatientDetails patientDetails, NurseDetails nurseDetails) {
> 				super();
> 				this.patientDetails = patientDetails;
> 				this.nurseDetails = nurseDetails;
> 				overlapHours = participantDetails.getNumberOverlapHourCnt(nurseDetails);
> 			}
> 		    [...]
> 		}
> 		
> 		public class NurseDetails {
> 			private Set stateLicensures = new HashSet();
> 			[...]
> 		}
> 		public class PatientDetails {
> 			private String state;
> 			[...]
> 		}
> Edson suggested that the problem is that "not contains" is not a valid operator for MVEL. 
> Also Noticed that the following workaround did not work:
> 		rule State
> 		    dialect "mvel"
> 			when
> 		            $ca:CandidateAssociation( eval ( ! nurseDetails.stateLicensures.contains( patientDetails.state ) ) )
> 			then 	
> 		  	    retract( $ca );
> 		end
> 		
> 		This produced this Exception:
> 		org.drools.rule.InvalidRulePackage: Unable to determine the used declarations : [Rule name=State, agendaGroup=MAIN, salience=0, no-loop=false]
> 	        at org.drools.rule.Package.checkValidity(Package.java:408)
> 	        at org.drools.common.AbstractRuleBase.addPackage(AbstractRuleBase.java:288)
> 	        at [...]



--
This message was sent by Atlassian JIRA
(v7.5.0#75005)


More information about the jboss-jira mailing list