无法使用严格模式解决方法

时间:2022-05-14 04:43:47

I'm newbie with java and drools and I have to build a java RESTful Web Services / rules engine. We already have Genesys Rule Authoring (GRAT) and Genesys Rule Engine (GRE) (version 8.1.2) who run drools version 5.2. We have the need to take the source of GRAT packages and use them in a "lite rule engine" for our development environments. For my POC, I have install drools 5.2 and create a project who can digest my package and fire rules just like I want. But for some package I have this kind of error :

我是java和drools的新手,我必须构建一个java RESTful Web服务/规则引擎。我们已经有运行drools版本5.2的Genesys Rule Authoring(GRAT)和Genesys Rule Engine(GRE)(版本8.1.2)。我们需要获取GRAT包的来源,并将它们用于我们开发环境的“lite规则引擎”中。对于我的POC,我已经安装了drools 5.2并创建了一个项目,可以像我想要的那样消化我的包和解雇规则。但对于某些包我有这种错误:

BuildError: Unable to Analyse Expression $routingparams.priority = obtenirValeurParametre($routingparams.priority,"100");
$routingparams.target1 = obtenirValeurParametre($routingparams.target1, "AVGRP_GPAP_AEP_TA_MDP_E");:
[Error: unable to resolve method using strict-mode: com.desjardins.gtd.dpsccc.routage.gpap.routingparams.ObtenirValeurParametre.obtenirValeurParametre(java.lang.Integer, java.lang.String)]
[Near : {... ngparams.priority = obtenirValeurParametre($routin ....}]

If you look at package at the end, you'll see that the function obtenirValeurParametre(String, String). You'll also see this function call with (Integer, String) and the error is on this line. In drools package I can't have the same function with different params. I have try to use "drools.dialect.mvel.strict" = false, but it doesn't change anything.

如果你看一下最后的包,你会看到函数obtenirValeurParametre(String,String)。您还将看到此函数调用(Integer,String),错误在此行上。在drools包中,我不能使用不同的参数具有相同的功能。我试着使用“drools.dialect.mvel.strict”= false,但它没有改变任何东西。

KnowledgeBuilderConfiguration kbConfig =KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
kbConfig.setProperty("drools.dialect.mvel.strict", "false");
System.setProperty("drools.dialect.mvel.strict", "false");
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( kbConfig );

As GRE run drools 5.2 like me and it work for GRE, I think that it must exist a solution other then add .toString() or something like this. Considering that we have a lot of package and some of them have thousand of rules, I don't want to make adjustments on each rule.

由于GRE像我一样drools 5.2它适用于GRE,我认为它必须存在一个解决方案,然后添加.toString()或类似的东西。考虑到我们有很多包,其中一些包含数千条规则,我不想对每条规则进行调整。

Someone have an idea to solve that issues? He/She will be my hero!

有人有想法解决这个问题吗?他/她将成为我的英雄!

package com.desjardins.gtd.dpsccc.routage.gpap.routingparams

import java.util.*;

function String obtenirValeurParametre(String valeurActuelle, String parametre){
    if(parametreEstVide(parametre)) return "";  
    if("*".equals(parametre)) return valeurActuelle;
    else return parametre;
}

function boolean parametreEstVide(String parametre){
    if(parametre.startsWith("{") && parametre.endsWith("}")) return true;
    else return false;
}

declare RoutingParams
    target1: String
    priority: Integer
end 

declare ContexteInteraction
    destination: String
end 

#from row number: 1
rule "Row 1 DT-6249 UNIT_Test Alain"
salience 99000 
    agenda-group "level1"
    dialect "mvel"
    when
        ContexteInteraction( destination == 'GPAP_AEP_TA_MDP')
        $routingparams:RoutingParams(); 
        $contexteInteraction:ContexteInteraction();
    then
        $routingparams.priority = obtenirValeurParametre($routingparams.priority,'100')
        $routingparams.target1 = obtenirValeurParametre($routingparams.target1, 'AVGRP_GPAP_AEP_TA_MDP_E')
end

Thanks

Alain

1 个解决方案

#1


Overloading a DRL function isn't possible in any Drools version.

在任何Drools版本中都不能重载DRL功能。

The usual workaround for problems with functions (there are more restrictions) is to use and import static Java methods from a class such as:

函数问题的常用解决方法(有更多限制)是从类中使用和导入静态Java方法,例如:

public class Utils {
    public static String 
    obtenirValeurParametre(String valeurActuelle, String parametre){
        if(parametreEstVide(parametre)) return "";  
        return "*".equals(parametre) ? valeurActuelle : parametre;
    }

    public static String 
    obtenirValeurParametre(Integer valeurActuelle, String parametre){
        if(parametreEstVide(parametre)) return "";  
        return "*".equals(parametre) ?
               valeurActuelle.toString() : parametre;
    }

    public static boolean
    parametreEstVide(String parametre){
        return parametre.startsWith("{") && parametre.endsWith("}");
    }
}

You need one change per DRL file:

每个DRL文件需要更改一次:

import static the.package.name.Utils.*;

That was the good news.

这是个好消息。

I have tested this using versions 5.3, and it fails with dialect MVEL, and it's safe to assume that it won't work with 5.2 (which is too old for me to have around). MVEL was full of bugs when being integrated into Drools during the 5.x-development. Plenty of hard work has improved matters, though.

我已经使用版本5.3对它进行了测试,并且它使用方言MVEL失败了,并且可以安全地假设它不适用于5.2(这对我来说太老了)。当在5.x开发期间集成到Drools中时,MVEL充满了错误。尽管如此,大量艰苦的工作改善了问题。

And so it works, even with dialect MVEL in versions 5.5 and 6.2. You'll have to upgrade to 5.5, 5.6 or 6.2. The latter will mean some changes to the Java code for compiling and executing.

所以它的工作原理,即使是版本5.5和6.2中的方言MVEL也是如此。您必须升级到5.5,5.6或6.2。后者将意味着对Java代码进行一些更改以进行编译和执行。

#1


Overloading a DRL function isn't possible in any Drools version.

在任何Drools版本中都不能重载DRL功能。

The usual workaround for problems with functions (there are more restrictions) is to use and import static Java methods from a class such as:

函数问题的常用解决方法(有更多限制)是从类中使用和导入静态Java方法,例如:

public class Utils {
    public static String 
    obtenirValeurParametre(String valeurActuelle, String parametre){
        if(parametreEstVide(parametre)) return "";  
        return "*".equals(parametre) ? valeurActuelle : parametre;
    }

    public static String 
    obtenirValeurParametre(Integer valeurActuelle, String parametre){
        if(parametreEstVide(parametre)) return "";  
        return "*".equals(parametre) ?
               valeurActuelle.toString() : parametre;
    }

    public static boolean
    parametreEstVide(String parametre){
        return parametre.startsWith("{") && parametre.endsWith("}");
    }
}

You need one change per DRL file:

每个DRL文件需要更改一次:

import static the.package.name.Utils.*;

That was the good news.

这是个好消息。

I have tested this using versions 5.3, and it fails with dialect MVEL, and it's safe to assume that it won't work with 5.2 (which is too old for me to have around). MVEL was full of bugs when being integrated into Drools during the 5.x-development. Plenty of hard work has improved matters, though.

我已经使用版本5.3对它进行了测试,并且它使用方言MVEL失败了,并且可以安全地假设它不适用于5.2(这对我来说太老了)。当在5.x开发期间集成到Drools中时,MVEL充满了错误。尽管如此,大量艰苦的工作改善了问题。

And so it works, even with dialect MVEL in versions 5.5 and 6.2. You'll have to upgrade to 5.5, 5.6 or 6.2. The latter will mean some changes to the Java code for compiling and executing.

所以它的工作原理,即使是版本5.5和6.2中的方言MVEL也是如此。您必须升级到5.5,5.6或6.2。后者将意味着对Java代码进行一些更改以进行编译和执行。