How to call a Java function in drools?

╄→гoц情女王★ 提交于 2019-12-12 03:55:28

问题


I want to call a Java function from a Utils class which calls a JPA Repository method for retrieving a custom object.

I want to call this function from a Drools decision table. Now, this simple function is giving Null Pointer Exception and I have already lost several hours on this.

I have a Functions field declared under "Import" section of the decision table, and there I have declared a simple function which calls this particular Java function with the repository method.

Can you provide me with a solution?


回答1:


Here is an example of calling java method from drools. setLocalTax() method is available from ItemCity class. Using the '$item' object we can invoke.

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


来源:https://stackoverflow.com/questions/35458990/how-to-call-a-java-function-in-drools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!