[rules-users] Cant check complex boolean expressions with Collections.disjoint

Wolfgang Laun wolfgang.laun at gmail.com
Tue Mar 20 09:12:47 EDT 2012


If it's a Java boolean expression you must use eval(), s.th. like this

   eval( ! Collections.disjoint($stp.getStrAttributeMap()[$attribute],
$values) )

Note that you'll have write this expression as in Java; I don't know
how the getter for attribute map works.

-W



On 20/03/2012, aitchnyu <jesvinj at technovia.co.in> wrote:
> I have a `SubjectTeacherPeriod` object which has a property
> `strAttributeMap`
> which is a map of `String` and `List<String>`. I want to check if
> `HardConstraint.strAttributeValue` and
> `SubjectTeacherPeriod.strAttributeMap[$attribute]` *intersect*. Here is the
> rule:
>
>     rule "hardConflictIsIn"
>         when
>     	$hc : HardConstraint(
>     			    $attribute  : attribute,
>     			    operator == "is in",
>     			    $values : strAttributeValue,
>     			    $period : period
>     			    )
>     	$stp : SubjectTeacherPeriod(
>     				    period == $period,
>     				    //ERROR IN FOLLOWING LINE
>     				    Collections.disjoint(strAttributeMap[$attribute], $values) ==
> false
>     				    )
>         then
>     	insertLogical(new IntConstraintOccurrence("hardConflictIsIn",
>     		ConstraintType.NEGATIVE_HARD,1,
>                     $hc,$stp));
>     end
>
> But the rule (actually two of them) throws the error:
>
> Exception in thread "main" java.lang.IllegalStateException: There are errors
> in the scoreDrl's:
> Unable to Analyse Expression
> Collections.disjoint(strAttributeMap[$attribute], $values) == false:
> sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast
> to java.lang.Class : [Rule name='hardConflictIsIn']
>
> Unable to Analyse Expression
> Collections.disjoint(strAttributeMap[$attribute], $values) == true:
> sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast
> to java.lang.Class : [Rule name='hardConflictNotIn']
>
>
> 	at
> org.drools.planner.config.solver.SolverConfig.buildRuleBase(SolverConfig.java:238)
> 	at
> org.drools.planner.config.solver.SolverConfig.buildSolver(SolverConfig.java:170)
> 	at
> org.drools.planner.config.XmlSolverConfigurer.buildSolver(XmlSolverConfigurer.java:103)
> 	at
> in.co.technovia.timetabler.TimeTableApp.createSolver(TimeTableApp.java:61)
> 	at in.co.technovia.timetabler.TimeTableApp.main(TimeTableApp.java:45)
>
> I got it from an answer from my own question at
> http://stackoverflow.com/a/9241089/604511 . Is this a bug in Drools itself?
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Cant-check-complex-boolean-expressions-with-Collections-disjoint-tp3842259p3842259.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



More information about the rules-users mailing list