-
1. Re: How to get WorkItemHandler results
eaa Feb 24, 2012 11:36 AM (in response to out_sider)You have to map them to process variables.
-
2. Re: How to get WorkItemHandler results
out_sider Feb 24, 2012 11:47 AM (in response to eaa)Sorry but didn't quite understand
Map them how ? it's not enought to do manager.completeWorkItem(workItem.getId(), resultMap);?
If not why pass the resultMap? What happens?
what method can I use in what object to get them?
The documentation simply says
But no example is given or exaplanation to how.
-
3. Re: How to get WorkItemHandler results
eaa Feb 24, 2012 11:52 AM (in response to out_sider)Let's say you have a "Calculate Random Number" Work Item. The WI Handler will calculate a random value, put it into a Map using some key:
Map<String, Object> result = new HashMap<String,Object>();
result.put("rndNumber", randomNumber);
manager.completeWorkItem(workItem.getId(), result);
In the process designer you will need to map the "rndNumber" result to some variable in your process. If you are using the web designer you have to add in the "associations" attribute of the Task:
rndNumber->processVariableThatWillHoldTheNumber
This is similar to what you have to do if you want to pass parameters to the Work Item.
Best Regards,
-
4. Re: How to get WorkItemHandler results
out_sider Feb 24, 2012 11:58 AM (in response to eaa)Process deisgner?
I'm simply doing:
KnowledgeBase kbase = readKnowledgeBase(pack, title);
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
LoginWorkItemHandler loginHandler = new LoginWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Login", loginHandler);
ProcessInstance process = ksession.startProcess("mg.login");
I create the knowledge base and session and register the WorkItemHandler with the manager.
Then I start the process.
After ksession.startProcess I want to acess the result of the LoginWorkItemHandler that I added to the map....how can I do that?
I just want to run a process with a WorkItemHandler and acess after its executation to the result...nothing more.
-
5. Re: How to get WorkItemHandler results
eaa Feb 24, 2012 12:11 PM (in response to out_sider)The results of a WorkItem Handler are usually used INSIDE the process. If you need them outside of the process you can basically follow 2 mechanisms:
- Create your external mechanism that the WorkItem Handler will use: i.e. pass a List to the constructor of the WorkItem Handler, the handler then will populate the list (no need to put the results in the resulting map since you are not going to use the value in the process) and then retrieve the value from your app.
- Put the result in the map and pass it to the process (this is automatically done when you complete the WI), in the process definition you have to map the result to a process' variable. Then, when the process is completed, you can get the value of that variable using something like:
((WorkFlowProcessInstance) process).getVariable("nameOfTheProcessVariable")
Best Regards,
-
6. Re: How to get WorkItemHandler results
out_sider Feb 24, 2012 12:21 PM (in response to eaa)Many thanks for the help.
If I can just two other questions:
The application I'm making makes the interaction with the user through the web designer. Therefore I'll need to run the process definition in a Servlet. As such I'm startin the process within the Servlet and the WorkItemHandler will be returning information to be sent to the user. As such isn't this the only way to do it? Because executeWorkItem is void I can't send it to the Servlet...right?
My other one is the web app is running in jBoss and although there shoudln't e problems mixing jBpm and jBoss web I'm having some troubles. I get:
java.lang.ClassNotFoundException: org.drools.runtime.process.WorkItemHandler
When deploying the application. What can I do?
-
7. Re: How to get WorkItemHandler results
eaa Feb 27, 2012 3:34 AM (in response to out_sider)The application I'm making makes the interaction with the user through the web designer. Therefore I'll need to run the process definition in a Servlet. As such I'm startin the process within the Servlet and the WorkItemHandler will be returning information to be sent to the user. As such isn't this the only way to do it? Because executeWorkItem is void I can't send it to the Servlet...right?
The WorkItemHanlder always returns information to the process. If you map the return of your Handler to a process variable, you can get the value of that variable right after you do session.startProcess() (assuming there is no intermediate wait-state before your Work Item). So, the process will start, it will exectue the WI Handler, the Handler will create the result and complete the WI (passing the result) the result will be map to a process variable (because you explicitly defined this mapping) and then, the process will continue until it reaches a wait-state or an End Event Node. At this point, the control will be returned to your servlet where you can read the pocess variable value.
There are possibly more than 100 other ways to do this same thing. Pass some listener to the WI Handler that will be invoked when the result is ready, use JMS to communicate the Handler and your code, etc.
My other one is the web app is running in jBoss and although there shoudln't e problems mixing jBpm and jBoss web I'm having some troubles. I get:
java.lang.ClassNotFoundException: org.drools.runtime.process.WorkItemHandler
When deploying the application. What can I do?
Which dependencies are you defining in your app? You should also include some of the drools dependencies:
<dependency>
<groupId>org.drools</groupId>
<artifactId>knowledge-api</artifactId>
<version>5.4.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>5.4.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>5.4.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-bpmn2</artifactId>
<version>5.3.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-flow</artifactId>
<version>5.3.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-flow-builder</artifactId>
<version>5.3.0-SNAPSHOT</version>
</dependency>
Best Regards,