Discussion:
Drools Decision Table, multiple actions accumulation
chsekhar
2012-06-01 19:19:47 UTC
Permalink
I am doing a similar example as described in this example in the link from
jboss website and go the section "6.1.3. How Decision Tables Work". (I have
attached the image as well)
Loading Image...

http://docs.jboss.org/drools/release/5.2.0.Final/drools-expert-docs/html/ch06.html
Drools documentation

In the example they are populating a "list" in the ACTION. So if a fact
matches couple of rows in the decision table, the list would contain those
two items.

My requirement is I need to have key value pair(Map) as my rule
consequence(ACTION). I was able to do one action which has "key,value" in a
single column and I was able to work with that. I am trying to find out if i
can have these values in two columns separately in the excel. (My key
actually contains 3 values and combining this with value looks messy. ex:
k1,k2,k3,value. So if can put the value in a separate column it would be
great)

I tried to create a global variable and called setter methods on separate
columns, but the problem is the setters in both the columns(ACTION) run
independently whereas I had to put both of them in a map which would mean I
should be able to pass the value present in both the columns in one method
call.


--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Decision-Table-multiple-actions-accumulation-tp4017733.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
Vincent LEGENDRE
2012-06-01 19:35:43 UTC
Permalink
... which would mean I should be able to pass the value present in both the columns in one method call.
Or create a Pojo for your keys (you should have already one as java maps only have one key ...),
instanciate it in the first column in a local (to RHS) variable,
use setters to set internal keys,
then use this KeyPojo to add your value in the last column.

In DRL this could be :
...
then
KeyPojo keys = new KeyPojo();
keys.setKey1(...);
...
keys.setKeyk(...);
...
keys.setKeyN(...);
$myMap.put(keys, value);
end

basically, the fist action column will contains the 2 first DRL statements.
The last action column will contains the 2 last DRL statement.
Intermediate columns only use the setters.

Of course, this works only if you are sure that your first and last action columns are always set ...
Otherwise, hope this help !
chsekhar
2012-06-01 20:18:23 UTC
Permalink
In the example you had given, how would I be able to pass "keys" from one
ACTION to another in "decision table"? It cant be a global variable because
this(keys) has to be a new instance per row. Is there some mechanism in
decision table which would let me refer the values from column into another?

KeyPojo keys = new KeyPojo();
keys.setKey1(...);
...
keys.setKeyk(...);
...
keys.setKeyN(...);
$myMap.put(keys, value);

--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Decision-Table-multiple-actions-accumulation-tp4017733p4017736.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
Michael Anstis
2012-06-01 21:14:02 UTC
Permalink
You cannot merge multiple ACTION columns into a single DRL statement.

If your individual key components can be bound as individual CONDITION
Colum constraints the ACTION need only contain the value.

sent on the move
Post by chsekhar
In the example you had given, how would I be able to pass "keys" from one
ACTION to another in "decision table"? It cant be a global variable because
this(keys) has to be a new instance per row. Is there some mechanism in
decision table which would let me refer the values from column into another?
KeyPojo keys = new KeyPojo();
keys.setKey1(...);
...
keys.setKeyk(...);
...
keys.setKeyN(...);
$myMap.put(keys, value);
--
http://drools.46999.n3.nabble.com/Drools-Decision-Table-multiple-actions-accumulation-tp4017733p4017736.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
chsekhar
2012-06-02 00:46:46 UTC
Permalink
I was able to merge data from multiple ACTION columns in decision table.

First ACTION column:
(kept all keys as comma separated in single column. we can have it in
individual columns)
KeyPojo keys = new KeyPojo($1,$2,$3);

Second ACTION column:
$myMap.put(keys, $param);

This worked great. Thanks Vincent for your answer.

--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Decision-Table-multiple-actions-accumulation-tp4017733p4017740.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
Michael Anstis
2012-06-02 05:58:40 UTC
Permalink
But each column became a separate DRL fragment ;) but glad to read you got
it working :)

One for me to remember. Thanks Vincent

sent on the move
Post by chsekhar
I was able to merge data from multiple ACTION columns in decision table.
(kept all keys as comma separated in single column. we can have it in
individual columns)
KeyPojo keys = new KeyPojo($1,$2,$3);
$myMap.put(keys, $param);
This worked great. Thanks Vincent for your answer.
--
http://drools.46999.n3.nabble.com/Drools-Decision-Table-multiple-actions-accumulation-tp4017733p4017740.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
FrankVhh
2012-06-04 06:54:19 UTC
Permalink
Hi all,

There is a small remark/comment that pops into my head when reading this.
Giving the effort that has already been spent on the issue, this might come
a bit late to you, but whatever...

Wouldn't it also be possible to keep your excel decision table exactly the
way it originally was (everything in one column) and then exploit the excel
capabilities?

I.e.
1) Insert two extra columns (one for the key, one for the value).
2) Do not annotate them with CONDIITION!
3) Create a function in your initial column that would compose the value of
the two new columns.
4) Hide the real condition column.

I have not yet tried this myself, but it might work.

regards,
Frank
Post by Michael Anstis
But each column became a separate DRL fragment ;) but glad to read you got
it working :)
One for me to remember. Thanks Vincent
sent on the move
Post by chsekhar
I was able to merge data from multiple ACTION columns in decision table.
(kept all keys as comma separated in single column. we can have it in
individual columns)
KeyPojo keys = new KeyPojo($1,$2,$3);
$myMap.put(keys, $param);
This worked great. Thanks Vincent for your answer.
--
http://drools.46999.n3.nabble.com/Drools-Decision-Table-multiple-actions-accumulation-tp4017733p4017740.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Decision-Table-multiple-actions-accumulation-tp4017733p4017742.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
Wolfgang Laun
2012-06-04 07:11:19 UTC
Permalink
Post by FrankVhh
Hi all,
There is a small remark/comment that pops into my head when reading this.
Giving the effort that has already been spent on the issue, this might come
a bit late to you, but whatever...
Wouldn't it also be possible to keep your excel decision table exactly the
way it originally was (everything in one column) and then exploit the excel
capabilities?
I.e.
1) Insert two extra columns (one for the key, one for the value).
2) Do not annotate them with CONDIITION!
I guess you mean ACTION.
Post by FrankVhh
3) Create a function in your initial column that would compose the value of
the two new columns.
I haven't tried it either, but I'd think that the API accessing the
spreadsheet would have to return the formula rather than the value
computed from it.

And, IIRC, if the additional columns aren't headed with one of
CONDITION, ACTION,... they'd stop access by the spreadsheet parser. So
they would have to be the rightmost columns, which might not be
convenient in general.

-W
Post by FrankVhh
4) Hide the real condition column.
I have not yet tried this myself, but it might work.
regards,
Frank
Post by Michael Anstis
But each column became a separate DRL fragment ;) but glad to read you got
it working :)
One for me to remember. Thanks Vincent
sent on the move
Post by chsekhar
I was able to merge data from multiple ACTION columns in decision table.
(kept all keys as comma separated in single column. we can have it in
individual columns)
KeyPojo keys = new KeyPojo($1,$2,$3);
$myMap.put(keys, $param);
This worked great. Thanks Vincent for your answer.
--
http://drools.46999.n3.nabble.com/Drools-Decision-Table-multiple-actions-accumulation-tp4017733p4017740.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
--
http://drools.46999.n3.nabble.com/Drools-Decision-Table-multiple-actions-accumulation-tp4017733p4017742.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
FrankVhh
2012-06-04 07:32:06 UTC
Permalink
Sorry for the confusion, of course I mean ACTION.

Although I still did not try it, I also get from the documentation that you
would need a column header. The way I see it, there are multiple workarounds
for that. One more ugly than the other, so it's up to you to decide if it's
worth it.

1) As you said, append all helper columns to the right of the actual
decision table.
2) Hide all of the real decision table and create a complete "helper table"
that will feed the real decision table.
3) Mark your helper action column as ACTION as well, if the column is filled
in, it will generate a colon ";".

I seem to remember having an excel function in the decision table without
any problems.

Regards,
Frank
Post by Wolfgang Laun
I guess you mean ACTION.
I haven't tried it either, but I'd think that the API accessing the
spreadsheet would have to return the formula rather than the value
computed from it.
And, IIRC, if the additional columns aren't headed with one of
CONDITION, ACTION,... they'd stop access by the spreadsheet parser. So
they would have to be the rightmost columns, which might not be
convenient in general.
-W
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Decision-Table-multiple-actions-accumulation-tp4017733p4017744.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
Vincent LEGENDRE
2012-06-04 07:56:55 UTC
Permalink
The formula trick works : POI (api used inside drools) is reading values by default for cells (at least the last time I used that in 5.1 version).
The main problem of this is when users adds new rows : you must ensure that formula are copied too .... and this lead to other dirtier tricks (like using VB ...) or strict user manual (to force users to COPY row instead of adding brand new one ...)


----- Original Message -----
From: "Wolfgang Laun" <***@gmail.com>
To: "Rules Users List" <rules-***@lists.jboss.org>
Sent: Lundi 4 Juin 2012 09:11:19
Subject: Re: [rules-users] Drools Decision Table, multiple actions accumulation
Post by FrankVhh
Hi all,
There is a small remark/comment that pops into my head when reading this.
Giving the effort that has already been spent on the issue, this might come
a bit late to you, but whatever...
Wouldn't it also be possible to keep your excel decision table exactly the
way it originally was (everything in one column) and then exploit the excel
capabilities?
I.e.
1) Insert two extra columns (one for the key, one for the value).
2) Do not annotate them with CONDIITION!
I guess you mean ACTION.
Post by FrankVhh
3) Create a function in your initial column that would compose the value of
the two new columns.
I haven't tried it either, but I'd think that the API accessing the
spreadsheet would have to return the formula rather than the value
computed from it.

And, IIRC, if the additional columns aren't headed with one of
CONDITION, ACTION,... they'd stop access by the spreadsheet parser. So
they would have to be the rightmost columns, which might not be
convenient in general.

-W
Post by FrankVhh
4) Hide the real condition column.
I have not yet tried this myself, but it might work.
regards,
Frank
Post by Michael Anstis
But each column became a separate DRL fragment ;) but glad to read you got
it working :)
One for me to remember. Thanks Vincent
sent on the move
Post by chsekhar
I was able to merge data from multiple ACTION columns in decision table.
(kept all keys as comma separated in single column. we can have it in
individual columns)
KeyPojo keys = new KeyPojo($1,$2,$3);
$myMap.put(keys, $param);
This worked great. Thanks Vincent for your answer.
--
http://drools.46999.n3.nabble.com/Drools-Decision-Table-multiple-actions-accumulation-tp4017733p4017740.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
--
http://drools.46999.n3.nabble.com/Drools-Decision-Table-multiple-actions-accumulation-tp4017733p4017742.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
Wolfgang Laun
2012-06-04 08:07:39 UTC
Permalink
Perhaps another (simpler) approach (showing columns as rows):

ACTION || myMap.put(new KeyPojo($1,$2,$3), || 1,22,333
ACTION || $param); || 122333

-W
Post by Vincent LEGENDRE
The formula trick works : POI (api used inside drools) is reading values by
default for cells (at least the last time I used that in 5.1 version).
The main problem of this is when users adds new rows : you must ensure that
formula are copied too .... and this lead to other dirtier tricks (like
using VB ...) or strict user manual (to force users to COPY row instead of
adding brand new one ...)
----- Original Message -----
Sent: Lundi 4 Juin 2012 09:11:19
Subject: Re: [rules-users] Drools Decision Table, multiple actions accumulation
Post by FrankVhh
Hi all,
There is a small remark/comment that pops into my head when reading this.
Giving the effort that has already been spent on the issue, this might come
a bit late to you, but whatever...
Wouldn't it also be possible to keep your excel decision table exactly the
way it originally was (everything in one column) and then exploit the excel
capabilities?
I.e.
1) Insert two extra columns (one for the key, one for the value).
2) Do not annotate them with CONDIITION!
I guess you mean ACTION.
Post by FrankVhh
3) Create a function in your initial column that would compose the value of
the two new columns.
I haven't tried it either, but I'd think that the API accessing the
spreadsheet would have to return the formula rather than the value
computed from it.
And, IIRC, if the additional columns aren't headed with one of
CONDITION, ACTION,... they'd stop access by the spreadsheet parser. So
they would have to be the rightmost columns, which might not be
convenient in general.
-W
Post by FrankVhh
4) Hide the real condition column.
I have not yet tried this myself, but it might work.
regards,
Frank
Post by Michael Anstis
But each column became a separate DRL fragment ;) but glad to read you got
it working :)
One for me to remember. Thanks Vincent
sent on the move
Post by chsekhar
I was able to merge data from multiple ACTION columns in decision table.
(kept all keys as comma separated in single column. we can have it in
individual columns)
KeyPojo keys = new KeyPojo($1,$2,$3);
$myMap.put(keys, $param);
This worked great. Thanks Vincent for your answer.
--
http://drools.46999.n3.nabble.com/Drools-Decision-Table-multiple-actions-accumulation-tp4017733p4017740.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
--
http://drools.46999.n3.nabble.com/Drools-Decision-Table-multiple-actions-accumulation-tp4017733p4017742.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
Loading...