Search code examples
drools

Property access problems


I tried to use this rule:

rule "conformSyncConstraint"
    when
    $syn_con : SyncConstraint(
        $left_stp_period  : leftSTP.period,
        $right_stp_period : rightSTP.period)
    eval( ($left_stp_period.dayOfWeek == $right_stp_period.dayOfWeek &&
        $left_stp_period.dayOrder == $right_stp_period.dayOrder) == false) 

    then
    insertLogical(new IntConstraintOccurrence("conformSyncConstraint", 
        ConstraintType.NEGATIVE_HARD,
        1,
                $syn_con));
end

But I face this error, which seemed a blackbox:

Rule Compilation error : [Rule name='conformSyncConstraint']
    in/co/technovia/timetabler/domain/Rule_conformSyncConstraint_4401252830cd4ee7bc49416ead3da86c.java (8:1459) : The field Period.dayOfWeek is not visible
    in/co/technovia/timetabler/domain/Rule_conformSyncConstraint_4401252830cd4ee7bc49416ead3da86c.java (8:1490) : The field Period.dayOfWeek is not visible


    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)

What is going wrong here?


Solution

  • Anytime you use eval, you fallback to the dialect being used. In your case, you are using java dialect, so you have to write the expression with java syntax: .getDayOfWeek() instead of .dayOfWeek.

    If you don't use evals, or if you switch the dialect to mvel, you can use the simplified syntax.

    E.g.:

    when
        $syn_con : SyncConstraint(
            leftSTP.period.dayOfWeek != rightSTP.period.dayOfWeek ||
            leftSTP.period.dayOrder != rightSTP.period.dayOrder
        )
    then