无法使用严格模式解析方法 [英] unable to resolve method using strict-mode

查看:494
本文介绍了无法使用严格模式解析方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java和Drools的新手,我必须构建一个Java RESTful Web服务/规则引擎.我们已经拥有运行drools 5.2版的Genesys规则创作(GRAT)和Genesys规则引擎(GRE)(版本8.1.2).我们需要获取GRAT软件包的来源,并在我们的开发环境的精简规则引擎"中使用它们.对于我的POC,我已经安装了drools 5.2并创建了一个项目,该项目可以按我的意愿消化我的程序包并启动规则.但是对于某些软件包,我会出现这种错误:

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 :

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 ....}]

如果您在末尾查看包,则会看到函数obtenirValeurParametre(String,String).您还将看到使用(Integer,String)进行此函数调用,并且错误在此行上.在drools包中,我不能在不同的参数上具有相同的功能.我尝试使用"drools.dialect.mvel.strict" = false,但不会改变任何内容.

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.

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

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

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.

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

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

谢谢

阿兰

推荐答案

any Drools版本中,无法重载DRL函数.

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

函数问题(存在更多限制)的通常解决方法是使用和导入诸如此类的类的静态Java方法:

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

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("}");
    }
}

您需要对每个DRL文件进行一次更改:

You need one change per DRL file:

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

那是个好消息.

我已经使用5.3版进行了测试,但使用方言MVEL失败了,可以安全地假定它无法在5.2版下使用(对于我来说,这太旧了,无法使用).在5.x开发期间将MVEL集成到Drools中时,MVEL充满了错误.不过,大量的努力改善了情况.

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.5和6.2版本的方言MVEL,它也可以正常工作.您必须升级到5.5、5.6或6.2.后者将意味着对Java代码进行一些更改以进行编译和执行.

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.

这篇关于无法使用严格模式解析方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆