[rules-users] Find out order of insert in RHS

Sandjaja, Dominik dominik.sandjaja at it-motive.de
Fri Feb 8 05:10:24 EST 2013


Hello Wolfgang,

thank you for the hint. I introduced a new Class "Counter" with just an int property and a method "getAndIncrease". This class is referenced in a base rule which all the other rules extend.

On the RHS of all rule "insert"s I set a field to the value of c.getAndIncrease() which gives me the correct order. The hint with the static counter was the right one!

Regards
Dominik

-----Ursprüngliche Nachricht-----
Von: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] Im Auftrag von Wolfgang Laun
Gesendet: Donnerstag, 7. Februar 2013 18:59
An: Rules Users List
Betreff: Re: [rules-users] Find out order of insert in RHS

If object creation is done in the same order as the insertion: surely a simple static counter in the class would give you the required monotonous value.

Otherwise, a listener could be set, which will "see" the actual order of insertion, and it can set the order-of-insertion property.

-W


On 07/02/2013, Sandjaja, Dominik <dominik.sandjaja at it-motive.de> wrote:
> Hi everybody,
>
> short: is there a way to have an automatic counter for the RHS of a
> rule when inserting several objects in one rule?
>
> Long:
> I use drools with a DSL to insert items for a frontend dropdown box.
> The generated rule is e.g. like the following one:
>
>     rule "testRule_H"
>         dialect "mvel"
>             when
>                 SomePartOfMyModel( someField == "H" )
>                     then
>                         DropDownItem fact1 = new DropDownItem();
> fact1.setLabel( "My Label 1" ); fact1.setValue( "B" );
>
> insert (fact1);
>                         DropDownItem fact1 = new DropDownItem();
> fact1.setLabel( "My Label 2" ); fact1.setValue( "A" );
>
> insert (fact1);
>
> This works nicely and I get all the items. The problem I have is with
> the sorting. Users use Guvnor to edit the available items for the
> dropdown box, so they add and remove items from the RHS. Since I
> retrieve those objects from the knowledge base in my java code like this:
>
> Collection<FactHandle> handles =
> statefulKnowledgeSession.getFactHandles(new
> ClassObjectFilter(DropDownItem.class));
>         for (FactHandle handle : handles) {
>             DropDownItem selectItem = (DropDownItem)
> statefulKnowledgeSession.getObject(handle);
>             ...
>
> I think I cannot be sure about the order the objects are retrieved
> (it's a collection, no guaranteed sorting!). So, I sort the
> DropDownItems alphabetically by their value.
>
> My question now is, as stated above: How can I implement a counter
> which I can use in the facts being inserted to keep my inserted facts
> (DropDownItems) in the same order as they are inserted?
>
> Thanks in advance
> Dominik
>
> …………………………………………………………………
> mit freundlichen Grüßen / kind regards Dominik Sandjaja
> Fon: +49 (0) 203 60878 183
> Fax: +49 (0) 203 60878 222
> e-mail: dominik.sandjaja at it-motive.de
>
> it-motive AG
> Zum Walkmüller 10-12
> 47269 Duisburg
> info at it-motive.de
> http://www.it-motive.de
> ……………………………………………………………………
> Vorsitzender des Aufsichtsrats: Dipl.-Ing. Klaus Straub
> Vorstand: Horst-Dieter Deelmann (Vors.),  Matthias Heming, Christoph
> Tim Klose HRB 9207, Amtsgericht Duisburg
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users

_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

…………………………………………………………………
mit freundlichen Grüßen / kind regards
Dominik Sandjaja
Fon: +49 (0) 203 60878 183
Fax: +49 (0) 203 60878 222
e-mail: dominik.sandjaja at it-motive.de

it-motive AG
Zum Walkmüller 10-12
47269 Duisburg
info at it-motive.de
http://www.it-motive.de
……………………………………………………………………
Vorsitzender des Aufsichtsrats: Dipl.-Ing. Klaus Straub
Vorstand: Horst-Dieter Deelmann (Vors.),  Matthias Heming, Christoph Tim Klose
HRB 9207, Amtsgericht Duisburg



More information about the rules-users mailing list