-
1. Process Instance Variable within WorkItemHandler
salaboy21 Apr 26, 2011 3:01 PM (in response to aminmc)Hi Amin,
Why are you doing that? the main idea of using work items is that you can copy information from the process scope to the work item scope using parameter mappings. If you define what pieces of information you will need inside the work item handler you can do the mappings and the engine will copy those values for you. You don't need to have the session to retrieve the process variables.
Take a look at the examples here: https://github.com/Salaboy/Drools_jBPM5-Training-Examples
inside the jBPM5 directory for more information.
Look at the processes definition to see how to move information from the process scope to the workitem scope.
Greetings.
-
2. Process Instance Variable within WorkItemHandler
aminmc Apr 26, 2011 4:05 PM (in response to salaboy21)Hi Mauricio,
Thanks for your reply. I'll give more info behind what I am trying to do. I have an object model which looks something like this:
Class A
String id
Set<ClassB> data --> ClassB String name, String value
In my flow we create Class A and a collection of ClassB but in the process variable we store the reference as opposed to the serialised version of ClassA (there is already persistence behind ClassA).
I now have a domain specific work item handler which is registered in eclipse and has a set of properties which a user can define. These properties can be statically defined or they can use an expression based approach for example
Name: ClassA(variableName defined in flow).elementName + ':' + ClassA(variableName defined in flow).reference
The idea is then to load ClassA id via variableName and then get the value of elementName and reference which are stored in ClassA object model. I have a small ANTLR program that parses the string and then looks up the data. The ANTLR parser uses session.getProcessInstance(..) to load the relevant data and I was hoping to load the process and get the value out, although it probably is possible to pass the work item parameter mapping to my parser.
Hope this made sense!
Cheers
-
3. Re: Process Instance Variable within WorkItemHandler
francesco.pietrobelli Jun 8, 2011 10:26 AM (in response to aminmc)I think that you can pass the StatefulKnowledgeSession to a constructor of your custom WorkItemHandler and then in executeWorkItem(WorkItem i,WorkItemManager m) method calls:
ksession.getProcessInstance(i.getProcessInstanceId());
Hope this is helpful.
-
4. Re: Process Instance Variable within WorkItemHandler
salaboy21 Jun 8, 2011 11:28 AM (in response to aminmc)Hi Amin,
Your procedure looks so complicated to me. You should use the Variable Persisntece Strategies to handle such situations. Are your expessions propietary? Do you need to do that kind of resolutions in runtime? or you can solve the same things with the current methods?
If you create a variable persistence strategy for handling your classes that are being persisted externally, you shouldn't use the process instance ID to restore the information. You should use your own/external persisters (the one that handles the Class A and B) to restore the information about those classes using the ID that you pass to the work item handler.
Greetings.
-
5. Re: Process Instance Variable within WorkItemHandler
aminmc Jun 8, 2011 3:13 PM (in response to salaboy21)Wow...completely forgot about this post. I have handled this differently and so longer an issue.
Cheers
-
6. Re: Process Instance Variable within WorkItemHandler
newbird Jul 31, 2012 4:57 AM (in response to aminmc)Can you share ur approach????????????
-
7. Re: Process Instance Variable within WorkItemHandler
enriquezrene Feb 1, 2013 11:54 PM (in response to aminmc)You can see my blog, I solved this and I hope it's helpful
http://moeandjava.pusku.com/index.php/jbpm5/how-to-get-process-variables-within-workitemhandler