KIE Drools 6.2.0 Guided Decision table aggregating action column result for multiple rules are fired

579 views
Skip to first unread message

SK

unread,
Mar 14, 2017, 11:25:34 PM3/14/17
to Drools Usage
Hi ,

I have a requiremnt, when multiples fired for input fact . I have to aggregate the action columns out put into another action column when last rule got fired.

I attached my guided decision table and test scenario where it fired 3 rules. would like to aggregate output1 field data in aggregateOutput field. Is there any way i can achieve this ? Your help is appreciated.

For below input XML :
<batch-execution lookup="defaultKieSession">
    <insert out-identifier="f1" return-object="true" entry-point="DEFAULT">
            <demo.testlib.TestAggBean>
            <input1>v1</input1>
            <input2>v2</input2>
            <input3>v3</input3>
        </demo.testlib.TestAggBean>
    </insert>
    <fire-all-rules out-identifier="myFireCommand" />
</batch-execution>

I received response as below :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<response type="SUCCESS" msg="Container testlibcontainer successfully called.">
    <results
<execution-results>
    <result identifier="f1">
        <demo.testlib.TestAggBean>
            <input1>v1</input1>
            <input2>v2</input2>
            <input3>v3</input3>
            <output1>out13</output1>
            <output2>out2</output2>

        </demo.testlib.TestAggBean>
    </result>
    <result identifier="myFireCommand">
        <int>3</int>
    </result>
    <fact-handle identifier="f1"
        external-form="0:1:1631639158:1631639158:4:DEFAULT:NON_TRAIT" />
</execution-results>
</results>
</response>

****
Let me know if you need anymore information to understand my requirement.



TestAggTable.PNG
testScenario.PNG

Michael Anstis

unread,
Mar 15, 2017, 5:19:33 AM3/15/17
to Drools Usage
You'd probably need to add a "BRL Action Column" for "Aggregate" but to advise further I'd need to understand what type of Fact/Field "Agg Output" represents.

Is it a field on the same Fact used in the conditions? Is it a new instance of something? Is it a list? Is it numeric and "aggregate" means "sum"? etc

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/a6aebe4c-a8a4-4f8a-b97a-aa79dd6967a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

SK

unread,
Mar 15, 2017, 9:59:13 AM3/15/17
to Drools Usage
Hi Michael,

aggoutput Field is String List.

For the below input Fact, I am expecting  response as
 aggoutput field as List of Strings [  out1,out12,out13 ]
 output1 value as out13 and
output2 value as empty.



<batch-execution lookup="defaultKieSession">
    <insert out-identifier="f1" return-object="true" entry-point="DEFAULT">
            <demo.testlib.TestAggBean>
            <input1>v1</input1>
            <input2>v2</input2>
            <input3>v3</input3>
        </demo.testlib.TestAggBean>
    </insert>
    <fire-all-rules out-identifier="myFireCommand" />
</batch-execution>



Please help with example to achieve this.

Thanks in advance.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
DataObject.PNG

Michael Anstis

unread,
Mar 15, 2017, 10:05:28 AM3/15/17
to Drools Usage
Are all the fields on the same class used it the conditions?

To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

SK

unread,
Mar 15, 2017, 10:51:18 AM3/15/17
to Drools Usage
yes all belong to same Data Object class.

Michael Anstis

unread,
Mar 16, 2017, 6:30:34 AM3/16/17
to Drools Usage
OK, you should be able authoring something that generates the following:

rule "example"
when
  $t : TestAggBean( $i1 : input1 == "X1", $i1 : input2 = "X2", $i3 : input3, $agg : aggoutput != null )
then
  modify( $t ) {
    output1( $i1 )
  }
  $agg.add( $i1 );
end

I've shown as DRL but hopefully you will be able to translate this to Guided Decision Table columns.

Red is normal Condition columns that you probably already have; with the exception of the new column for "$agg : aggoutput != null" this simply binds your aggregate column to a variable for use in the THEN part.

Green is a "Modify field" action.

Blue is a BRL Action column; where you call a method on $agg. I forget if this will only allow literal values; if it does then use a "Free Form Line" and unfortunately paste the text.

I hope this is of help.

Mike




To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

SK

unread,
Mar 16, 2017, 2:30:00 PM3/16/17
to Drools Usage
Thanks a lot for your reply.

step 1: I updated Guided decision table by adding  input simple condition to check $agg : aggoutput!=null
step2: added BRL action column as below. But when i am trying to call method on $agg, its not adding method like this (

$agg.add( $i1 );




we need to set binding variable for output1 and output2 columns . I don't see binding variable option for action columns.

From above decision table my requirement is,  for the input v1, v2, v3 it fires three rules ( row1, row2, and row3)  i need to aggregate output1 column data in aggoutput column of row1.

Please it would be really appreciated if you can guide me to implement in Guided decision table of KIE drools 6.2.0.

Thanks in advance.
Auto Generated Inline Image 1
Auto Generated Inline Image 2

Michael Anstis

unread,
Mar 16, 2017, 3:51:49 PM3/16/17
to Drools Usage
You haven't chosen to "Call a method on X" but "Modify a field on X".

If the option to "Call a method on X" is not available you'll unfortunately need to add a "Free Form Line" and paste the DRL $agg.add( $i1 );

"BRL" columns use the re-use the Guided Rule Editor which is quite limited in function; hence the option to always use a "Free Form Line".


To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

SK

unread,
Mar 17, 2017, 11:44:22 AM3/17/17
to Drools Usage
Thank you for reply.

We have call method on X option it shows but by selecting that it is not doing anything.
By using Free form line , able to add List of values as shown in below figure. But It gives me check box to select list of values are not.
As highlighted in below GDT table if i would like to have different list of values for rule number 4 , how can I achieve this ?  Based on rules simple condition column data would like to have a different action column data , not same list of values. Please help me with achieving it.



Auto Generated Inline Image 1
Auto Generated Inline Image 2

Michael Anstis

unread,
Mar 17, 2017, 11:58:09 AM3/17/17
to Drools Usage
I suggest:-

1) Delete the "AggOut" column
2) Changing "output1" to be a "BRL Action Fragment" defined with 2 actions: 1 does the update "output1" and the other does the FFL $agg.add($t.getOutput1());
3) Repeat #2 for the other output columns

To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

SK

unread,
Mar 17, 2017, 1:37:42 PM3/17/17
to Drools Usage
Followed your steps and modified. ouput1 columns with two actions as below.

It fires 3 rules test scenario test . But when I am running using container end point it is not firing any rule.
See input and output xml.
InputXMl:
<batch-execution lookup="defaultKieSession">
<insert out-identifier="adRule" return-object="true" entrypoint="DEFAULT" >

    <demo.testlib.TestAggBean>
        <input1>v1</input1>
        <input2>v2</input2>
         <input3>v3</input3>
    </demo.testlib.TestAggBean>
</insert>

  <fire-all-rules out-identifier="commandsFired"/>
</batch-execution>

outputXMl :
<execution-results> <result identifier="commandsFired"> <int>0</int> </result> <result identifier="adRule"> <demo.testlib.TestAggBean> <input1>v1</input1> <input2>v2</input2> <input3>v3</input3> </demo.testlib.TestAggBean> </result> <fact-handle identifier="adRule" external-form="0:6:1078519432:1078519432:6:DEFAULT:NON_TRAIT"/> </execution-results>

With this approach also, for all rule 1 to 5 it gives same values in output1 and aggOutput fields. Becos it gives check box by defining BRL action column. It is not editable for each rule.

Please advise and help me.



Auto Generated Inline Image 1
Auto Generated Inline Image 2

Michael Anstis

unread,
Mar 17, 2017, 2:15:36 PM3/17/17
to Drools Usage
Oeeee... we're sooooooo close!

Instead of using a literal for the value of "output1" in the first part of your action; use a "template key" instead. This will become a text cell in the table to enter values.
 

To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

SK

unread,
Mar 17, 2017, 3:17:59 PM3/17/17
to Drools Usage
Thank you very much.

Yes updated to template key and it allows me to enter value for output1 field for each rule and my test scenario also. It fires rule 1 to 3.

But its not firing rules when i running using container end point.

See my input and output xml  and source code for gdt as attached.






req_response XML
sourcecode_TestAggGDT.text
Auto Generated Inline Image 1
Auto Generated Inline Image 2

Michael Anstis

unread,
Mar 17, 2017, 7:17:33 PM3/17/17
to Drools Usage

What's "container end points" and why repost the same enquiry under a different thread? Is this one not helpful enough? In my opinion you run the risk of alienating those helping.

To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

SK

unread,
Mar 20, 2017, 9:15:07 AM3/20/17
to Drools Usage
Hi Michael,
Are you talking about this post ?
This post is  regarding List of User defined objects in Action column,  not the aggregated column issue. So posted in different thread to avoid confusion with aggregation issue we are talking here.

Container End point is :
http://localhost:8080/kie-server-6.2.0.Final-ee6/services/rest/server/containers/testlibcontainer

Let me know can I delete that post Once this issue is resolved we can talk that issue also here only.

Thanks for your help.

SK

unread,
Mar 20, 2017, 9:37:49 AM3/20/17
to Drools Usage
Hi Michael,

When we create Data Object Model using DataObject from WorkBench. It creates List member variable as below.
   private java.util.List<java.lang.String> aggoutput ;
When I am doing add method on $agg.add('out1'), it is giving me null pointer exception so modified the above line in Data Object model as below
   private java.util.List<java.lang.String> aggoutput  = java.util.ArrayList<java.lang.String>(); 

when I am using  REST end point it is not firing the rules. Now I tried changing TestAggBean  Data Object getAggoutput() method as attached and it is firing rule. Thank you very much for all your help.
Can you confirm is it right way to modify data object ?

TestAggBean.txt
Auto Generated Inline Image 1

SK

unread,
Mar 20, 2017, 9:50:55 AM3/20/17
to Drools Usage
But one more issue here is outputl columns always gives 'out3'  as result which is row3 value. For all 3 input cases, see attached results.
for case1 : output1 value supposed to be out1
for case2 : output1 value supposed to be out2
for case3 : output1 value supposed to be out3

Please help me  on this.
case1.PNG
case3.PNG
case2.PNG

Michael Anstis

unread,
Mar 20, 2017, 9:54:32 AM3/20/17
to Drools Usage
You can modify the Java source in any way you need; but will loose "round tripping" between the source view and the more graphical table view.

Lazy initialisation, as you have done in your attachment, is fine.. as would be initialising it where declared. It's personal preference really.

What would however be good is the ability to initialise member properties via the editor. I logged https://issues.jboss.org/browse/GUVNOR-2941 for our consideration in a future release.

To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

Michael Anstis

unread,
Mar 20, 2017, 9:56:35 AM3/20/17
to Drools Usage
Can you paste the complete source of your dtable?

To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

Michael Anstis

unread,
Mar 20, 2017, 9:56:43 AM3/20/17
to Drools Usage
DRL not XML.

SK

unread,
Mar 20, 2017, 10:02:33 AM3/20/17
to Drools Usage
Hi,
Please see attached source code of decision table.

Thank you,
DRL not XML.

sourcecode_TestAggGDT.text

Michael Anstis

unread,
Mar 20, 2017, 10:05:15 AM3/20/17
to Drools Usage
Rule "rule 'Row 3 TestAggGDT'" is always being activated and setting the value of output3. This is an example of subsumption; where a "more generic" rule is activating.

You'll probably need to include constraints on the outputs; so the rules read "TestAggBean( output1 == null, output2 == null, output3 == null)"

To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

SK

unread,
Mar 20, 2017, 10:21:51 AM3/20/17
to Drools Usage
Added Constraint , see source code of decision table.
It gives right value in output1  column but not in aggOutput.
for all 3 cases aggOutput gives only one value not aggregation of all 3 rules values.

Please correct me adding constraint is wrong.

OR do I need to add constraint in output1 BRL action column. ?

Thanks in advance.
TestAggTable.PNG
sourcecode_TestAggGDT.text

Michael Anstis

unread,
Mar 20, 2017, 10:29:55 AM3/20/17
to Drools Usage
Well... now only 1 rule will activate as the checks on output1 and output2 being null fail after one rule matches....

What is it you're trying to achieve!?! You're using multiple rules to accumulate all matches; but each match sets output1 to a different value..



To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

SK

unread,
Mar 20, 2017, 10:36:31 AM3/20/17
to Drools Usage
Yes each match set output1 to different value. But i would like to accumulate all matched outputs of column output1 to aggOutput.

for example for input : v1, v2, v3 it matches 3 rules  : so 3 rules output1 data to be accumulated into aggoutput. So output1 should show its exact matching rule output but aggOutput should give all 3 rules ouput ( i.e out1, out2 ,out3)

Michael Anstis

unread,
Mar 20, 2017, 10:42:33 AM3/20/17
to Drools Usage
OK, remove the constraints on outputX then; and reorder the rules from "most generic" (i.e. just the check on input1) to "least generic" (i.e. checks on all 3 inputs).

To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

SK

unread,
Mar 20, 2017, 11:22:07 AM3/20/17
to Drools Usage
Yup this works thanks a lot.

SK

unread,
Mar 20, 2017, 11:28:09 AM3/20/17
to Drools Usage
Hi ,
One more question in Decision table :

I would like to set List of Objects in Action column of the decision Table.

Data Objects are :
Manger --> name (string), roleName (string)
Employee  -- > name(string), division(string), assigned Mangers (List <Manager>)

for input :
 Employee (Division == "hcm")  i would like to set list of mangers  in assined mangers.
assigned Mangers.add(( new Manager(" san", " HR manger") ) ;
assigned Mangers.add(( new Manager(" sk", "HCM asst manger") ) ;
assigned Mangers.add(( new Manager(" ska", "HCM Divisional manger") ) ;

 Employee (Division == "GSM")  i would like to set list of mangers  in assined mangers.
assigned Mangers.add(( new Manager(" san", " HR manger") ) ;
assigned Mangers.add(( new Manager(" ska", "HCM Divisional manger") ) ;
assigned Mangers.add(( new Manager(" KS", "GSM  manger") ) ;

For different rows in guided decision table i need to set different manger list for assignemnager column,

I tried with BRL action column  but for all rules Assigned manager list would be same becos it gives check box as attached in GDT table.
I would like to have different list of managers for different rules.

Your help is really appreciated.

Thanks in advance
EmployeeDataObject.PNG
EmployeeGuidedDecisonTable.PNG
Source_codeforEmployeeGdst

Michael Anstis

unread,
Mar 20, 2017, 11:39:43 AM3/20/17
to Drools Usage
Your easiest option would be to have a condition column for each "division" and have separate action columns for each "division" assigning the list of managers; in DRL terms:-

when
  $e : Employee( division == "d1" )
then
  $e.addManager( "m1" );
  $e.addManager( "m2" );
end

when
  $e : Employee( division == "d2" )
then
  $e.addManager( "m3" );
end

etc

Or you could have columns for employees and managers; and add managers to employees:-

when
  $e : Employee( division == <cell> )
  $m : Manager( name == "m1" ) //<- BRL Condition, no template keys. This would be a checkbox in the UI
then
  $e.addManager( $m ); //BRL Action column
end

when
  $e : Employee( division == <cell> ) //You'd have rows of employee/manager combinations
  $m : Manager( name == <cell> )
then
  $e.addManager( $m );
end



To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

SK

unread,
Mar 20, 2017, 1:23:08 PM3/20/17
to Drools Usage
Tried modifying GDT as mentioned below.
But getting below Error. Please see attached GDTable and source code. Please advise.

In BRL action Column I tried using $emp got same below error, So created binding variable for Employee and i tried but same error.

Unable to Analyse Expression $e.addManger($m);: [Error: unable to resolve method using strict-mode: org.drools.core.spi.KnowledgeHelper.$e()] [Near : {... $e.addManger($m); ....}] ^ [Line: 4, Column: 0]
Unable to Analyse Expression $e.addManger($m);: [Error: unable to resolve method using strict-mode: org.drools.core.spi.KnowledgeHelper.$e()] [Near : {... $e.addManger($m); ....}] ^ [Line: 15, Column: 0]

call method or free form both giving same error. Please help me what wrong I am doing.
Source_codeforEmployeeGdst
MangerdataObject.java
EmployeeDataObject.java
EmployeeGDT.PNG
AssignedMgr_BRL action column_callMethod.PNG
AssignedMgr_BRL action column_freeForm.PNG

Michael Anstis

unread,
Mar 20, 2017, 3:38:48 PM3/20/17
to Drools Usage
This is your DRL:

15. | rule "Row 2 employee1"
16. |    no-loop true
17. |    dialect "mvel"
18. |    when
19. |        emp : Employee( division == "D2" )
20. |        Manger( name == "MGR1" , roleName == "HR Manager" )
21. |        Manger( name == "MGR2" , roleName == "HCM Manger" )
22. |    then
23. |        $e.addManger($m)
24. | end

The bindings on the LHS and RHS need to be the same.

15. | rule "Row 2 employee1"
16. |     no-loop true
17. |     dialect "mvel"
18. |     when
19. |         $e : Employee( division == "D2" )
20. |         Manger( name == "MGR1" , roleName == "HR Manager" )
21. |         Manger( name == "MGR2" , roleName == "HCM Manger" )
22. |     then
23. |         $e.addManger($m)
24. | end


To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

SK

unread,
Mar 21, 2017, 11:18:41 AM3/21/17
to Drools Usage
I have updated and now my DRL shows like below. But still get the same error.
Unable to Analyse Expression $e.addManger($m);: [Error: unable to resolve method using strict-mode: org.drools.core.spi.KnowledgeHelper.$m()] [Near : {... $e.addManger($m); ....}] ^ [Line: 4, Column: 0]


Auto Generated Inline Image 1

Michael Anstis

unread,
Mar 21, 2017, 11:22:27 AM3/21/17
to Drools Usage
Manager needs to be bound to $m

To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

SK

unread,
Mar 21, 2017, 12:07:55 PM3/21/17
to Drools Usage
I tried binding $m1 Manger1 and $m2 to Manger2. It validates now without error.
But for all rules it gives same result right, As the Assigned Mangers Column is check box. See attached source code and GDT here.


</blockquot
Source_codeforEmployeeGdst
Auto Generated Inline Image 1
Auto Generated Inline Image 2

SK

unread,
Mar 21, 2017, 3:17:47 PM3/21/17
to Drools Usage
Hi Michael,
I have another question regarding guided decision table. This thread is growing huge, So I am going to post my question in different thread.


On Tuesday, 21 March 2017 11:22:27 UTC-4, Michael Anstis wrote:
</blockquot
Reply all
Reply to author
Forward
0 new messages