[rules-users] compare date in map in rule condition

James Gu jxgu at cnsh.delphi-tech.com
Tue Mar 22 02:17:10 EDT 2011


Hi, I am trying to compare date in condition of rule. I set the date format
in system parameter.
System.setProperty("drools.dateformat", "dd/MM/yyyy");

When I get the date from the fact object directly, it works well.
	   when
	        $record: Record( startDate < "01/01/3000"  )

In my application, I need to get a map from fact objet, then use a key to
get the target object, then get "dateValue" from the target object. This
condition doesn't work. "dateValue" is a java.util.Date object.
	   when
	        $record: Record( fieldMap["STARTDATE"].dateValue < "01/01/3000"  )

Does anyone know how to make it works?

This is the error message.

org.drools.RuntimeDroolsException: Exception executing predicate
fieldMap["STARTDATE"].dateValue < "01/01/3000"
	at
org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:279)
	at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:141)
	at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:59)
	at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:190)
	at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:145)
	at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1174)
	at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1123)
	at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:917)
	at
org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:251)
	at dti.drools.test.Test.oneRecordThousandTime(Test.java:81)
	at dti.drools.test.Test.main(Test.java:52)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:110)
Caused by: [Error: uncomparable values <> and <<01/01/3000>>]
[Near : {... Unknown ....}]
             ^
[Line: 1, Column: 0]
	at
org.mvel2.math.MathProcessor.doOperationNonNumeric(MathProcessor.java:230)
	at org.mvel2.math.MathProcessor._doOperations(MathProcessor.java:175)
	at org.mvel2.math.MathProcessor.doOperations(MathProcessor.java:79)
	at
org.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:111)
	at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
	at
org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:104)
	at org.mvel2.MVEL.executeExpression(MVEL.java:1001)
	at
org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPredicateExpression.java:91)
	at
org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:272)
	... 15 more
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to
java.util.Date
	at java.util.Date.compareTo(Date.java:112)
	at
org.mvel2.math.MathProcessor.doOperationNonNumeric(MathProcessor.java:227)
	... 23 more

--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/compare-date-in-map-in-rule-condition-tp2713827p2713827.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list