I agree - my mistake, Because of tests I've forgotten to delete 'X'... So it's not the case... Sorry...<br>But did another try and when I've used<br><br>rule "Check Object A and Set Default"<br>
dialect "mvel"<br><br>It was not working correctly. Then I moved to:<br><br>
rule "Check Object A and Set Default"<br>
dialect "java"<br><br>and it works fine. So it is ok if we will change Mike's 'NOT WORKING' example to:<br><br>--------------------------------------------------<br>package com.sample<br><br>import com.sample.ObjectA<br>
import org.drools.WorkingMemory<br><br>function void insertDefault(WorkingMemory workingMemory) {<br> SomeDefault someDefault = new SomeDefault();<br> someDefault.setMinValueA(100);<br> someDefault.setMinValueB(20.0);<br>
someDefault.setMaxValueB(20000.0);<br> workingMemory.insert(someDefault);<br>}<br><br>declare SomeDefault<br> minValueA : Integer<br> minValueB : Double<br> maxValueB : Double<br>end<br><br>rule "Check Object A and Set Default"<br>
dialect "java"<br> agenda-group "Foo"<br> salience 100<br> when<br> $a : ObjectA()<br> then<br> insertDefault(drools.getWorkingMemory());<br>end<br><br>rule "Use the defaults"<br>
dialect "mvel"<br> agenda-group "Foo"<br> salience 90<br> when<br> $default : SomeDefault()<br> then<br> System.out.println("Default minA=" + $default.minValueA)<br>end<br>--------------------------------------------------<br>
<br>Any ideas why?<br><br><div class="gmail_quote">2011/12/30 Mauricio Salatino <span dir="ltr"><<a href="mailto:salaboy@gmail.com" target="_blank">salaboy@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
One is SomeDefault and the other one is SomeDefaultX.<br>
The Declared type, as far as I remember overrides the to string with<br>
the representation that you are seeing there:<br>
<div>SomeDefault( minValueA=100, minValueB=20.0, maxValueB=20000.0 )<br>
</div>What is SomeDefaultX??<br>
Cheers<br>
2011/12/29 Maciej Gowin <<a href="mailto:maciej.abacus.gowin@gmail.com" target="_blank">maciej.abacus.gowin@gmail.com</a>>:<br>
<div><div>> I did some debbuging with 'declare SomeDefault'. This is what I found:<br>
><br>
> CASE1: RHS = drools.getWorkingMemory().insert(new SomeDefaultX())<br>
> Working memory objects:<br>
> Object[fact<br>
> 0:2:<a href="tel:2082419441" value="+12082419441" target="_blank">2082419441</a>:<a href="tel:2082419441" value="+12082419441" target="_blank">2082419441</a>:2:DEFAULT:com.sample.SomeDefaultX@7c1f32f1]<br>
> Object[fact 0:1:140683595:140683595:1:DEFAULT:com.sample.ObjectA@862a94b]<br>
><br>
> CASE2: RHS = insertDefault(drools.getWorkingMemory())<br>
> Working memory objects:<br>
> Object[fact 0:2:176338845:1:2:DEFAULT:SomeDefault( minValueA=100,<br>
> minValueB=20.0, maxValueB=20000.0 )]<br>
> Object[fact 0:1:1125048577:1125048577:1:DEFAULT:com.sample.ObjectA@430ee101]<br>
><br>
> Please note the difference between DEFAULT:com.sample.SomeDefault and<br>
> DEFAULT:SomeDefault.<br>
> So when inserting an object to WorkingMemory inside function insertDefault<br>
> which is declared in DRL file<br>
> something strange is going on... It seems like it is a bug. It is worth<br>
> mentioning that I get following result<br>
> inside insertDefault:<br>
> System.out.println(SomeDefault.class.getName());<br>
> ---> com.sample.SomeDefault<br>
><br>
> Hope it will help :)<br>
><br>
><br>
><br>
><br>
> 2011/12/30 Maciej Gowin <<a href="mailto:maciej.abacus.gowin@gmail.com" target="_blank">maciej.abacus.gowin@gmail.com</a>><br>
>><br>
>> Of course it's only my guess. I'm not an expert. Please correct me if I'm<br>
>> wrong :)<br>
>><br>
>><br>
>> 2011/12/30 Maciej Gowin <<a href="mailto:maciej.abacus.gowin@gmail.com" target="_blank">maciej.abacus.gowin@gmail.com</a>><br>
>>><br>
>>> It's not the different WorkingMemory. It's all about class name<br>
>>> confusion. It looks like the class type does not match.<br>
>>> Please try to create SomeDefault in standard way, not with 'declare'<br>
>>> statement. It works ok.<br>
>>><br>
>>><br>
>>> 2011/12/30 Mike Key <<a href="mailto:mikey@zenbitz.com" target="_blank">mikey@zenbitz.com</a>><br>
>>>><br>
>>>> I guess that is exactly my confusion :) Why would it be that doing the<br>
>>>> exact same thing, one inserting into working memory from a function and the<br>
>>>> other simply doing it within the RHS of the rule cause downstream rules not<br>
>>>> to fire in the function call case? The rules are both in the same<br>
>>>> agenda-group, both the function example and the insert from the RHS of the<br>
>>>> rule example are simply inserting a new fact into working memory.<br>
>>>><br>
>>>> It makes it seem like the function call is somehow inserting into a<br>
>>>> *different* working memory, which I'm sure is not the case, but the<br>
>>>> downstream rule does not fire none-the-less.<br>
>>>><br>
>>>> Thanks for any clarity.<br>
>>>><br>
>>>><br>
>>>> On Thu, Dec 29, 2011 at 3:59 PM, Mauricio Salatino <<a href="mailto:salaboy@gmail.com" target="_blank">salaboy@gmail.com</a>><br>
>>>> wrote:<br>
>>>>><br>
>>>>> Agenda-groups segment the agenda and not the working memory :)<br>
>>>>> Probably that is part of your confusion.<br>
>>>>><br>
>>>>><br>
>>>>> 2011/12/29 Mike Key <<a href="mailto:mikey@zenbitz.com" target="_blank">mikey@zenbitz.com</a>>:<br>
>>>>> > I am a fairly new Drools user and am trying to understand how working<br>
>>>>> > memory<br>
>>>>> > is segmented when using agenda groups. I have an agenda-group that<br>
>>>>> > has<br>
>>>>> > focus set immediately from the session as follows with a few objects<br>
>>>>> > being<br>
>>>>> > inserted:<br>
>>>>> ><br>
>>>>> > ksession.insert(objectA);<br>
>>>>> > ksession.insert(objectB);<br>
>>>>> > ksession.getAgenda().getAgendaGroup("Foo").setFocus();<br>
>>>>> ><br>
>>>>> > I have 2 rules simplified down to illustrate my confusion. The first<br>
>>>>> > rule<br>
>>>>> > simply sets some default values evaluated in the second rule if<br>
>>>>> > objectA<br>
>>>>> > exists. In the example that works I set the defaults in the RHS<br>
>>>>> > explicitly.<br>
>>>>> > However I want to use these defaults from different agenda-groups,<br>
>>>>> > so when<br>
>>>>> > I put them in a function, the second rule never fires, the activation<br>
>>>>> > is<br>
>>>>> > created for the first rule but never the second. Can someone tell me<br>
>>>>> > why<br>
>>>>> > the use of a function seems to alter the truth of the rule?<br>
>>>>> ><br>
>>>>> > THIS WORKS:<br>
>>>>> ><br>
>>>>> > declare SomeDefault<br>
>>>>> > minValueA : Integer<br>
>>>>> > minValueB : Double<br>
>>>>> > maxValueB : Double<br>
>>>>> > end<br>
>>>>> ><br>
>>>>> > rule "Check Object A and Set Default"<br>
>>>>> > agenda-group "Foo"<br>
>>>>> > salience 100<br>
>>>>> > when<br>
>>>>> > $a : ObjectA()<br>
>>>>> > then<br>
>>>>> > default = new SomeDefault()<br>
>>>>> > default.minValueA = 100<br>
>>>>> > default.minValueB = 20.0<br>
>>>>> > default.maxValueB = 20000.0<br>
>>>>> > insert(default)<br>
>>>>> > end<br>
>>>>> ><br>
>>>>> > rule "Use the defaults"<br>
>>>>> > agenda-group "Foo"<br>
>>>>> > salience 100<br>
>>>>> > when<br>
>>>>> > $default : SomeDefault()<br>
>>>>> > then<br>
>>>>> > System.out.println("Default minA=" + $default.minValueA)<br>
>>>>> > end<br>
>>>>> ><br>
>>>>> > THIS DOES NOT WORK:<br>
>>>>> ><br>
>>>>> > declare SomeDefault<br>
>>>>> > minValueA : Integer<br>
>>>>> > minValueB : Double<br>
>>>>> > maxValueB : Double<br>
>>>>> > end<br>
>>>>> ><br>
>>>>> > rule "Check Object A and Set Default"<br>
>>>>> > agenda-group "Foo"<br>
>>>>> > salience 100<br>
>>>>> > when<br>
>>>>> > $a : ObjectA()<br>
>>>>> > then<br>
>>>>> > insertDefault(drools.getWorkingMemory())<br>
>>>>> > end<br>
>>>>> ><br>
>>>>> > rule "Use the defaults"<br>
>>>>> > agenda-group "Foo"<br>
>>>>> > salience 90<br>
>>>>> > when<br>
>>>>> > $default : SomeDefault()<br>
>>>>> > then<br>
>>>>> > System.out.println("Default minA=" + $default.minValueA)<br>
>>>>> > end<br>
>>>>> ><br>
>>>>> > function void insertDefault(WorkingMemory workingMemory) {<br>
>>>>> > SomeDefault default = new SomeDefault();<br>
>>>>> > default.setMinValueA(100);<br>
>>>>> > default.setMinValueB(20.0);<br>
>>>>> > default.setMaxValueB(20000.0);<br>
>>>>> > workingMemory.insert(default);<br>
>>>>> > }<br>
>>>>> ><br>
>>>>> > In the latter (non-working) example the first rule activates and then<br>
>>>>> > drools<br>
>>>>> > returns, it never even attempts to try to fire the second rule.<br>
>>>>> > However in<br>
>>>>> > the working example BOTH rules fire as I would expect. I am guessing<br>
>>>>> > this<br>
>>>>> > is a simple misunderstanding on my part. Any assistance in<br>
>>>>> > understanding<br>
>>>>> > why this nuance doesn't seem to work would be greatly appreciated.<br>
>>>>> ><br>
>>>>> > Thanks.<br>
>>>>> ><br>
>>>>> > MiKey<br>
>>>>> ><br>
>>>>> > _______________________________________________<br>
>>>>> > rules-users mailing list<br>
>>>>> > <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
>>>>> > <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
>>>>> ><br>
>>>>><br>
>>>>><br>
>>>>><br>
>>>>> --<br>
>>>>> - CTO @ <a href="http://www.plugtree.com" target="_blank">http://www.plugtree.com</a><br>
>>>>> - MyJourney @ <a href="http://salaboy.wordpress.com" target="_blank">http://salaboy.wordpress.com</a><br>
>>>>> - Co-Founder @ <a href="http://www.jugargentina.org" target="_blank">http://www.jugargentina.org</a><br>
>>>>> - Co-Founder @ <a href="http://www.jbug.com.ar" target="_blank">http://www.jbug.com.ar</a><br>
>>>>><br>
>>>>> - Salatino "Salaboy" Mauricio -<br>
>>>>><br>
>>>>> _______________________________________________<br>
>>>>> rules-users mailing list<br>
>>>>> <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
>>>>> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
>>>><br>
>>>><br>
>>>><br>
>>>> _______________________________________________<br>
>>>> rules-users mailing list<br>
>>>> <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
>>>> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
>>>><br>
>>><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> rules-users mailing list<br>
> <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
><br>
<br>
<br>
<br>
--<br>
- CTO @ <a href="http://www.plugtree.com" target="_blank">http://www.plugtree.com</a><br>
- MyJourney @ <a href="http://salaboy.wordpress.com" target="_blank">http://salaboy.wordpress.com</a><br>
- Co-Founder @ <a href="http://www.jugargentina.org" target="_blank">http://www.jugargentina.org</a><br>
- Co-Founder @ <a href="http://www.jbug.com.ar" target="_blank">http://www.jbug.com.ar</a><br>
<br>
- Salatino "Salaboy" Mauricio -<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br>