如何在 drools 中调用 Java 函数?
How to call a Java function in drools?
我想从 Utils class 调用一个 Java 函数,该函数调用 JPA 存储库方法来检索自定义对象。
我想根据 Drools 决定调用此函数 table。
现在,这个简单的函数给出了 Null Pointer Exception,我已经为此浪费了几个小时。
我在决定 table 的 "Import" 部分下声明了一个函数字段,并且我在那里声明了一个简单的函数,它使用存储库方法调用这个特定的 Java 函数。
你能给我一个解决方案吗?
这里是一个从 drools 调用 java 方法的例子。
ItemCity class 提供了 setLocalTax() 方法。使用我们可以调用的“$item”对象。
package droolsexample
// list any import classes here.
import com.sample.ItemCity;
import java.math.BigDecimal;
// declare any global variables here
dialect "java"
rule "Pune Medicine Item"
when
$item : ItemCity (purchaseCity == ItemCity.City.PUNE,
typeofItem == ItemCity.Type.MEDICINES)
then
BigDecimal tax = new BigDecimal(0.0);
$item.setLocalTax(tax.multiply($item.getSellPrice()));
end
我想从 Utils class 调用一个 Java 函数,该函数调用 JPA 存储库方法来检索自定义对象。
我想根据 Drools 决定调用此函数 table。 现在,这个简单的函数给出了 Null Pointer Exception,我已经为此浪费了几个小时。
我在决定 table 的 "Import" 部分下声明了一个函数字段,并且我在那里声明了一个简单的函数,它使用存储库方法调用这个特定的 Java 函数。
你能给我一个解决方案吗?
这里是一个从 drools 调用 java 方法的例子。 ItemCity class 提供了 setLocalTax() 方法。使用我们可以调用的“$item”对象。
package droolsexample
// list any import classes here.
import com.sample.ItemCity;
import java.math.BigDecimal;
// declare any global variables here
dialect "java"
rule "Pune Medicine Item"
when
$item : ItemCity (purchaseCity == ItemCity.City.PUNE,
typeofItem == ItemCity.Type.MEDICINES)
then
BigDecimal tax = new BigDecimal(0.0);
$item.setLocalTax(tax.multiply($item.getSellPrice()));
end