drools

Drools support in IntelliJ IDEA

人盡茶涼 提交于 2020-01-21 04:50:06
问题 I'm trying to use IntelliJ IDEA with legacy project with Drools files but I'm not successful in this. I added Drools framework to the module with *.drl files and... nothing. I can't reformat *.drl files, don't have any navigation, no code completion etc. I expected to see ability to add Drools facet to my module, specify *.drl files and then work with Drools files basically as with Spring framework. So what Drools support actually IntelliJ IDEA has? 回答1: Do you have the Drools plugin enabled

How to access to the consequence (RHS) of a rule from java?

情到浓时终转凉″ 提交于 2020-01-17 12:12:50
问题 I have rules with the following structure: rule "ins b" when A() then B $b = new B(); $b.setName("hello"); insert($b); end I want to get the objects (and its attributes) that the rule adds to the working memory. I'm able to get the LHS objects with the following code: RuleImpl ri = (RuleImpl) kSession.getKieBase().getRule("com.sample", "ins b"); System.out.println("L: " + ri.getLhs()); Pattern rce = (Pattern) ri.getLhs().getChildren().get( 0 ); System.out.println("L: " + rce.getConstraints())

How to access to the consequence (RHS) of a rule from java?

故事扮演 提交于 2020-01-17 12:12:09
问题 I have rules with the following structure: rule "ins b" when A() then B $b = new B(); $b.setName("hello"); insert($b); end I want to get the objects (and its attributes) that the rule adds to the working memory. I'm able to get the LHS objects with the following code: RuleImpl ri = (RuleImpl) kSession.getKieBase().getRule("com.sample", "ins b"); System.out.println("L: " + ri.getLhs()); Pattern rce = (Pattern) ri.getLhs().getChildren().get( 0 ); System.out.println("L: " + rce.getConstraints())

List validation in drools

感情迁移 提交于 2020-01-16 18:50:08
问题 A drools newbie here, Following is the java class structure. public class Person { List<PersonAddress> personAddress; } public enum AddressType { CURRENT, PREVIOUS; } public class PersonAddress{ Address address; AddressType type Integer timeAtAddress; } public class Address { String city; String country; String street; } I have to write some code to validate PersonAddress in drools. Rule 1. if person has list of PersonAddress instances, if one of them being AddressType == CURRENT and

I need to add .drl files at runtime (From an S3 bucket) and supply it to drools rule engine

ぃ、小莉子 提交于 2020-01-16 18:25:19
问题 Unable to add rules at runtime through ResourceFactory.newURLResource() Also , KnowledgeBase is deprecated or cannot be resolved I have tried all the snippets from the documentation public class RuleRunner { public RuleRunner() { } public void runRules(String[] rules, Object[] facts) throws Exception { KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); for ( int i = 0; i < rules.length; i++ ) { String

【原创】Drools规则引擎初窥---drl和决策表实现[实例]

随声附和 提交于 2020-01-16 09:05:26
因项目需要,看了下drools规则引擎。写了一个比较简单的drools的drl规则和决策表实现的例子。 规则说明:   网络商城要举办活动(奖励额外积分),   订单原价金额在   100以下, 不加分   100-500 加100分   500-1000 加500分   1000 以上 加1000分 1.建立最基本的 Drools 项目结构并引入必须的类库。 (这里采用 junit 来执行单元测试)。 创建一个 Java Project ,建立 maven 形式的源码包。 2.定义实体类Order.java 1 import java.util.Date; 2 3 public class Order { 4 private Date bookingDate;// 下单日期 5 6 private int amout;// 订单原价金额 7 8 private User user;// 下单人 9 10 private int score;//积分 11 12 public Order(Date bookingDate,int amout, User user, int score){ 13 this.bookingDate = bookingDate; 14 this.amout = amout; 15 this.user = user; 16 this.score =

小明历险记:规则引擎drools教程一

混江龙づ霸主 提交于 2020-01-16 09:05:10
小明是一家互联网公司的软件工程师,他们公司为了吸引新用户经常会搞活动,小明常常为了做活动加班加点很烦躁,这不今天呀又来了一个活动需求,我们大家一起帮他看看。 小明的烦恼 活动规则是根据用户购买订单的金额给用户送相应的积分,购买的越多送的积分越多,用户可以使用积分来兑换相应的商品,我们这次活动的力度很大,肯定会吸引很多的用户参加,产品经理小王兴高采烈唾液横飞的对小明讲到。小明心想,又tm来这套,这次需求又要变更多少次呢?表面上还的配合,说赶紧把规则给我们吧,早点开发早点上线,小王说这次需求老简单啦,估计你们两个小时就搞定了,不信你看需求文档。 用户购买的金额和对应送多少积分的规则如下: 100元以下, 不加分 100元-500元 加100分 500元-1000元 加500分 1000元 以上 加1000分 小明一看,这需求果然简单呀,作为一个工作了两三年的程序员来讲,这不就是小case,半天搞定,送积分的心代码如下: public void execute() throws Exception { List<Order> orderList = getInitData(); for (int i=0; i<orderList.size(); i++){ Order order = orderList.get(i); if (order.getAmout() <= 100){

timer ( cron:* * 10-18 * * ? ) rule consequences output duplicated

£可爱£侵袭症+ 提交于 2020-01-16 08:03:48
问题 I want to limit the rule run in a specfic time span ,the rule i wrote is as below rule "Event3" timer ( cron:* * 10-18 * * ? ) no-loop when $m : EventTest( originNumber == "123", originNumber : originNumber ) from entry-point "ATM Stream" or $m : EventTest( originNumber == "456",originNumber : originNumber ) from entry-point "ATM Stream" then System.out.println( $m.getOriginNumber() ); end when i insert a new fact into engine,every inserted fact before will duplicated triger the rule,how can

Does JBoss Drools really execute all rules in parallel?

℡╲_俬逩灬. 提交于 2020-01-13 03:13:05
问题 I've read a lot of documentation of JBoss Drools but cannot find a definitive answer as to if all rules are executed concurrently (certainly they are fired concurrently). More specifically, for a single input and a rule set of say 1000 rules, do the "when" conditions and the "then" conditions in each rule, execute sequentially one by one, or in parallel at the same time. On the one hand the rete algorithm implies parallelism, certainly when the select nodes are collapsed. However after the

drools time based constraints and “now”

旧巷老猫 提交于 2020-01-11 12:14:18
问题 We are trying to write a drool which says something like "If the event happened in the last week, execute the consequence". We have regular java date objects representing the time the event happened, but we aren't sure how to express in the LHS of a drool that we want that date object to have taken place in the last week. Importantly, the timespan of a week is arbitrary. It could change to month or year at any time. Finally, keep in mind that our session is stateful. I found a somewhat