[jboss-jira] [JBoss JIRA] Closed: (JBRULES-2404) "not contains" operator doesn't work on nested fields
Edson Tirelli (JIRA)
jira-events at lists.jboss.org
Thu May 19 16:55:01 EDT 2011
[ https://issues.jboss.org/browse/JBRULES-2404?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Edson Tirelli closed JBRULES-2404.
----------------------------------
> "not contains" operator doesn't work on nested fields
> ------------------------------------------------------
>
> Key: JBRULES-2404
> URL: https://issues.jboss.org/browse/JBRULES-2404
> Project: Drools
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Components: drools-core
> Reporter: Taras Svirskyi
> Assignee: Edson Tirelli
> Fix For: 5.2.0.CR1
>
> Attachments: test.tar.gz
>
>
> Consider following example.
> There are nodes that are connected into directed graph. Each node has
> special collection of attributes. Under some conditions attributes
> should be propagated along the edges in the graph.
> Lets model this with following code.
> /******* propagation rules **********************/
> package com.test.collection;
> rule "move child"
> when
> c : Child()
> s : CNode( children contains c)
> l : Link( src == s,
> t : target && target.children not contains c )
> then
> System.out.println("adding "+c+" from "+s+" to "+t);
> t.addChild(c);
> update(t);
> end
> /** Child.java (represent special attributes of a node) *******/
> package com.test.collection;
> public class Child {
> private String name;
> public Child(String name){
> this.name = name;
> }
> public String getName() {
> return name;
> }
> @Override
> public String toString() {
> return "child("+name+")";
> }
> }
> /********* CNode.java - nodes of a graph *************/
> package com.test.collection;
> import java.util.HashSet;
> import java.util.Set;
> public class CNode {
> private Set<Child> children;
> public CNode() {
> this.children = new HashSet<Child>();
> }
> public Set<Child> getChildren() {
> return children;
> }
>
> public void addChild(Child ch){
> children.add(ch);
> }
> @Override
> public String toString() {
> return "Node{children="+children+"}";
> }
> }
> /**** Link.java - edges of a graph *******/
> package com.test.collection;
> public class Link {
> private CNode src;
> private CNode target;
>
> public Link(CNode src, CNode target) {
> this.src = src;
> this.target = target;
> }
> public CNode getSrc() {
> return src;
> }
> public CNode getTarget() {
> return target;
> }
> }
> /********************* populate session with facts **********/
> Child c0 = new Child("x");
> Child c1 = new Child("y");
> Child c2 = new Child("z");
>
> CNode src = new CNode();
> src.addChild(c0);
> src.addChild(c1);
>
> CNode target = new CNode();
> target.addChild(c0);
>
> Link link = new Link(src,target);
>
> // populate with facts
> ksession.insert(c0);
> ksession.insert(c1);
> ksession.insert(c2);
> ksession.insert(link);
> ksession.insert(src);
> ksession.insert(target);
> /****************************************************************/
> So with all that code listed above I've got following output from rules:
> --
> adding child(x) from Node{children=[child(x), child(y)]} to
> Node{children=[child(x)]}
> --
> That means that 'not contains' operator actually works as 'contains'
> one. Still when I changed it to older operator 'excludes' everything
> goes right printing out.
> ---
> adding child(y) from Node{children=[child(y), child(x)]} to
> Node{children=[child(x)]}
> ---
> I've noticed that rewriting rule in form of simple statements also fix
> issue.
> rule "move child"
> when
> c : Child()
> s : CNode( children contains c)
> t : CNode( children not contains c )
> l : Link( src == s, target == t)
> then
> System.out.println("adding "+c+" from "+s+" to "+t);
> t.addChild(c);
> update(t);
> end
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list