drools

Java - Generic Drools rule

折月煮酒 提交于 2020-07-10 10:28:04
问题 I would like to create my rule more Generic format which mean it should be validate the fields and values. Following my POJO structure. public class RulesModel private String field; private List<String> values; // other stuff And my rule rule "sample" when $rule : RulesModel( field == "source", values contains "facebook", values contains "youtube", value not contains "instagram" ) then // actions end It's working fine to validate single field, but i want to validate the multiple fields of

Drools accumulate is updating an irrelevant fact

自作多情 提交于 2020-07-07 07:09:19
问题 When using an accumulate in Drools, a rule is evaluated and triggered for a fact that wasn’t updated. Here is the rule: rule "WidgetsPerUser" when $user : User() accumulate( Widget ( checkIsUser($user) ); $widgetCount : sum(1) ) then System.out.println($user + " has " + $widgetCount + " widgets"); end The idea is simple: count the number of Widget objects per User . checkIsUser() is a simple equality check, but represents a check that cannot use indexing. Here is sample output from Drools 7.0

Drools decision table, “mismatched input '>' in rule ”

好久不见. 提交于 2020-07-06 20:37:27
问题 I'm creating an decision table using Drools and having trouble with the greater than character ('>'). I saw on the drools documentation that you could use '>' and '<' but I seem to get something wrong. The column is (I don't have enough reputation yet to post images): |CONDITION| | | (empty cell) |duration >| |Duration| |50| |200| The thing is that the architecture doesn't allow me to get the full object. I can only have some fields from the RemoteObject . So the thing I can do is: Integer

Drools - Repeated Events and Temporal Relations

一笑奈何 提交于 2020-06-24 13:43:48
问题 In general I am writing rules for events which equal (by attributes values) events can occur any time in consecutive manner (every second). I want to fire rules for matched events only on an hourly bases. In more details: I want to fire a rule when an event is inserted for the first time (not exist yet) OR when an event is inserted and if and only if equal events are already inserted to the working memory BUT the newest of them is at least one hour ago old. What is a reasonable way of writing

Drools - Repeated Events and Temporal Relations

余生长醉 提交于 2020-06-24 13:43:06
问题 In general I am writing rules for events which equal (by attributes values) events can occur any time in consecutive manner (every second). I want to fire rules for matched events only on an hourly bases. In more details: I want to fire a rule when an event is inserted for the first time (not exist yet) OR when an event is inserted and if and only if equal events are already inserted to the working memory BUT the newest of them is at least one hour ago old. What is a reasonable way of writing

EqualsIgnoreCase on Drools

狂风中的少年 提交于 2020-06-18 11:16:08
问题 I am trying to rewrite my drl from using regex to equalsIgnoreCase as I think its faster. I am not sure its faster though. However, drools doesn't like it for some reason and I get unknown error. The one on top works, but the one using equalsIgnoreCase doesn't rule "name" salience 0 activation-group "flow" dialect "mvel" no-loop true when $vurderinger: Vurderinger(vurdering1909 != null && vurdering1909.verdi matches "(?i)^FOO$") then modify( $vurderinger ) { setVurdering1913(new DroolsType(

Drools collect list from object property

旧巷老猫 提交于 2020-06-17 15:51:03
问题 I have a student, who have list of courses. Also I have a lectures and I need to check that student courses list and list of courses of lectures that he visits are same I added rule for case, when student visits lecture, that he doesn't have in courses list: when $student:Student ($courses:courses) LectureAssignment(student == $student, course not memberOf $courses) then scoreHolder.addHardConstraintMatch(kcontext, -1); But I also need to check, that student visits all lecture, that he have

How to load rules from a string in Drools 6.5

ε祈祈猫儿з 提交于 2020-06-08 13:11:13
问题 I have a set of rules in the form of a String that are passed as an argument to my function, which is not stored in any file. From what I read so far, there are many solutions to this for versions before 6, where I am guessing APIs were very different. (They suggest using KnowledgeBase, which is deprecated in 6.5) This is my solution so far: KieFileSystem kfs = kService.newKieFileSystem(); Resource drlResource = ResourceFactory.newByteArrayResource(rules.getBytes()); drlResource

How to load rules from a string in Drools 6.5

我是研究僧i 提交于 2020-06-08 13:10:28
问题 I have a set of rules in the form of a String that are passed as an argument to my function, which is not stored in any file. From what I read so far, there are many solutions to this for versions before 6, where I am guessing APIs were very different. (They suggest using KnowledgeBase, which is deprecated in 6.5) This is my solution so far: KieFileSystem kfs = kService.newKieFileSystem(); Resource drlResource = ResourceFactory.newByteArrayResource(rules.getBytes()); drlResource

How to load rules from a string in Drools 6.5

拥有回忆 提交于 2020-06-08 13:10:10
问题 I have a set of rules in the form of a String that are passed as an argument to my function, which is not stored in any file. From what I read so far, there are many solutions to this for versions before 6, where I am guessing APIs were very different. (They suggest using KnowledgeBase, which is deprecated in 6.5) This is my solution so far: KieFileSystem kfs = kService.newKieFileSystem(); Resource drlResource = ResourceFactory.newByteArrayResource(rules.getBytes()); drlResource