0

Yesterday I post a question on strict-mode when passing different types of parameter to a function an laune find a solution. As recommend, I now use drools version 5.6.

Now, I still have the strict-mode error but for another case. Unfortunately, I can't apply the same solution. Function creerAction() return different type of object. Someone have an idea for that case?

Here is the error

Unable to Analyse Expression $noeud = creerAction($action,"EvaluerMessageActivable",drools); $action.noeud = $noeud;
    $noeud.prochaineActionSiBlocage = obtenirValeurParametre($noeud.prochaineActionSiBlocage, "CN_Raccrocher");
    $noeud.message = obtenirValeurParametre($noeud.message, '$MessageUrgenceGlobal'):
[Error: unable to resolve method using strict-mode: java.lang.Object.prochaineActionSiBlocage()]
[Near : {... $noeud.prochaineActionSiBlocage = obt ....}]
[Line: 34, Column: 0] : [Rule name='Row 1 DT-625 Evaluer blocage general']

Here is my drool file.

package com.desjardins.gtd.dpsccc.routage.vpa.actionsdialogue

import org.drools.spi.KnowledgeHelper;

function Object creerAction(Action actionCourante, String type, KnowledgeHelper drools) {
    if(actionCourante.getNoeud()!=null){
        String nomActionCourante = actionCourante.getNoeud().getClass().getSimpleName(); 
        if(!nomActionCourante .equals(type)) 
            throw new RuntimeException("Ne peut pas redéfinir le type de " + actionCourante.getNom() + ". Le type était: " + nomActionCourante + " spécifié: " + type);
        return actionCourante.getNoeud();
    }
    else if("EvaluerMessageActivable".equals(type)) return new EvaluerMessageActivable();
    else if("Terminer".equals(type)) return new Terminer();

    return null;
}

declare Action
    nom: String
    noeud: java.lang.Object
    compteur: Integer
end 

declare EvaluerMessageActivable
    message: String
    prochaineActionSiBlocage: String
end 

declare Terminer
    nom: String
end 

rule "Row 1 DT-625 Evaluer blocage general"
salience 100079 
    agenda-group "level0"
    dialect "mvel"
    when
        $action:Action(nom =='EM_UrgenceGlobal')
    then
        $noeud = creerAction($action,'EvaluerMessageActivable',drools); $action.noeud = $noeud
        $noeud.prochaineActionSiBlocage = obtenirValeurParametre($noeud.prochaineActionSiBlocage, 'CN_Raccrocher')
        $noeud.message = obtenirValeurParametre($noeud.message, '$MessageUrgenceGlobal')
end

Thank for you help.

Community
  • 1
  • 1
Alain Tanguay
  • 43
  • 1
  • 2
  • 5

2 Answers2

0

This line of code

$noeud = creerAction(...);

assigns the return value of creerAction to an undeclared variable. Since the function returns java.lang.Object, use

Object $noeud = creerAction(...);

to fix this. Of course, subsequent uses of $noeud may have to use casts to permit the compiler to find the correct method or whatever.

Don't think that Drools or MVEL abolish all of Java's type system. (Dieu merci!)

laune
  • 31,114
  • 3
  • 29
  • 42
  • I don't have problem with the $noeud = creerAction(). The problem is when I try to use a property of that object (ex : $noeud.prochaineActionSiBlocage). I have try `Object $noeud = creerAction()` and `EvaluerMessageActivable $noeud = creerAction()` , same result. (a t'on le droit de parler français ici?) – Alain Tanguay May 07 '15 at 11:57
  • The point is that Object (explicit or implied) cuts off all type information, and no compiler will permit the use of fields or methods of some class with an object that is a mere Object type. (On a le droit de parler Français mais les réponses seront rares.) – laune May 07 '15 at 19:07
  • Ce qui m'embête, c'est que notre système qui est présentement en production fonctionne avec ces règles là. Les règles sont géréré par Genesys Rule Authoring et sont exécuté par Genesys Rule Engine. Tout deux roule drools version 5.2. Par contre, je ne sais pas si le déploiement de GRAT vers GRE modifie d'une façon quelqu'onque les règles... – Alain Tanguay May 08 '15 at 13:38
0

For my tests I was using Jetty Version 6.1.26 and that version have problems with drools. I have try with version 8.1.2 and it work fine.

I also disabled the strict mode : System.setProperty("drools.dialect.mvel.strict", "false");

Alain Tanguay
  • 43
  • 1
  • 2
  • 5