Drools:规则编译错误-无法解析为变量

时间:2019-07-16 10:04:16

标签: java drools

我无法在流口水中编写一条简单的规则。我已经分析了代码,无法找出问题所在。它可能与条件“或”有关。

rule "Generic AC1" 
    when 
        $product : Product(canonicalId == "Product AC1") from listOfCompatibleProducts 
        or DateRangeValidator($verifyDate : validationDate, ($verifyDate.compareTo(DateUtils.parseDate("1970-01-01 01:00:00.000")) < 1) || ($verifyDate.compareTo(DateUtils.parseDate("4892-10-07 22:52:48.547")) > 0)) 
    then 
        System.out.println("DEBUG: ENGINE has fired Generic AC1"); 
        listOfCompatibleProducts.remove($product); 
end; 

我收到以下错误:

One or more rules are invalid: 
ERROR - Rule Compilation error $product cannot be resolved to a variable

1 个答案:

答案 0 :(得分:0)

问题是Drools会将您的or分成2条单独的规则:

rule "Generic AC1 1" 
    when 
        $product : Product(canonicalId == "Product AC1") from listOfCompatibleProducts         
    then 
        System.out.println("DEBUG: ENGINE has fired Generic AC1"); 
        listOfCompatibleProducts.remove($product); 
end

rule "Generic AC1 2" 
    when 
        DateRangeValidator($verifyDate : validationDate, ($verifyDate.compareTo(DateUtils.parseDate("1970-01-01 01:00:00.000")) < 1) || ($verifyDate.compareTo(DateUtils.parseDate("4892-10-07 22:52:48.547")) > 0)) 
    then 
        System.out.println("DEBUG: ENGINE has fired Generic AC1"); 
        listOfCompatibleProducts.remove($product); 
end; 

如您所见,在第二条规则的RHS中,您正在尝试使用LHS中未定义的$product变量。

希望有帮助,