-
1. Re: Rules Accessing ArrayList as Process Parameters
cross.cy Dec 15, 2011 11:41 PM (in response to zoikks)You may instead insert the objects in the arraylist into the knowledge session to be evaluated by rules.
Cheers
Yu
-
2. Re: Rules Accessing ArrayList as Process Parameters
zoikks Dec 16, 2011 11:17 AM (in response to cross.cy)Hi Yu,
Thanks for the comment. It is possible to write the objects into working memory and iterate over them. The real intent of the question was why can't the ArrayList be accessed directly from the process as a parameter while other objects types can be?
- Darin
-
3. Re: Rules Accessing ArrayList as Process Parameters
zoikks Dec 19, 2011 1:00 PM (in response to zoikks)After a little more thought about this, I'm beginning to think it has to do with the method naming. For instance, the code I've written calls the size() method. This isn't a typical property accessor (no "get"). Therefore, it might be the code is executing before the rule fires and checking for size() of an ArrayList (Collection) may simply not be possible. Can anyone confirm this theory?
Thanks.
-
4. Re: Rules Accessing ArrayList as Process Parameters
swiderski.maciej Dec 19, 2011 1:42 PM (in response to zoikks)Darin, after spending some time on this issue I came up with following (that seems to be working fine):
package org.zoikks.drools import java.util.ArrayList; import java.util.List; import org.drools.runtime.process.WorkflowProcessInstance; rule "Sample Rule" ruleflow-group "testgroup" when $process : WorkflowProcessInstance() $a: ArrayList() from collect( String() from $process.getVariable("arrayList")) then System.out.println("Sample Rule run successfully."); System.out.println("Count: " + $a.size()); end
Somehow $process.getVariable() returns strings instead of entire array list.
HTH
-
5. Re: Rules Accessing ArrayList as Process Parameters
zoikks Dec 19, 2011 2:09 PM (in response to swiderski.maciej)Many thanks - seemed to work great. I find it strange that $process.getVariable("arrayList") returns strings instead - I assume it would return the data type contained by the ArrayList?
I would think the $process.getVariable("xxx") would return an instance of the data type matching the variable. Is this "working as designed" or is this a bug?
Thanks.
-
6. Re: Rules Accessing ArrayList as Process Parameters
swiderski.maciej Dec 20, 2011 3:20 PM (in response to zoikks)I do believe it works as designed. "from clause" is to reason over collection elements so it returns data type that is inside the collection.
Alternatively you could try to just check if such process variable exists, for instance with "eval" and in consequence section access the array list (I think that works properly).
Cheers
-
7. Re: Rules Accessing ArrayList as Process Parameters
zoikks Dec 21, 2011 11:29 AM (in response to swiderski.maciej)Thanks again for the info. I found it very helpful.