-
1. Re: Combining human and automated tasks
eaa Dec 12, 2011 3:45 AM (in response to twizansk)Human Task server and jBPM process engine does not use the same DB. You can use the Human Task client API in your external system to complete a Human Task:
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-human-task</artifactId>
<version>5.2.0-SNAPSHOT</version>
</dependency>
-
2. Re: Combining human and automated tasks
twizansk Dec 12, 2011 4:00 AM (in response to eaa)Thanks for the quick reply. I am using the human task API and I can complete the human task successfully. The problem is that I can't restart the process afterwards so that the script task will be invoked.
Thanks
-
3. Re: Combining human and automated tasks
eaa Dec 12, 2011 4:09 AM (in response to twizansk)The process should automatically continue after you complete the Human Task. The session where you started the process must be up and running.
-
4. Re: Combining human and automated tasks
twizansk Dec 12, 2011 4:12 AM (in response to eaa)"The session where you started the process must be up and running."
Yes, that is the problem. I want to continue the process at a later time, after the human task is completed. The original session that created the process will be closed by then. Is there any way to do this?
-
5. Re: Combining human and automated tasks
calca Dec 12, 2011 10:42 AM (in response to twizansk)Tommer,
you should keep the session id where you created the process, and then load it like this:
attach the work item handlers,
and after using it disposing it.
Demian
-
6. Re: Combining human and automated tasks
twizansk Dec 12, 2011 11:14 AM (in response to calca)Thanks but how do I restart the session from the stopped position. If I do
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession( sessionId, kbase, null, env );
ksession.startProcess(...);
the entire process is executed from the beginning. I can't seem to tell jBPM to resume the process from the node immediately after the human task. I'd expect there to exist some method of the form:
ksession.resumeProcess()
but I can't find one.
Thanks again for the replies.
Tommer
-
7. Re: Combining human and automated tasks
calca Dec 12, 2011 11:26 AM (in response to twizansk)In fact, the resume is made automatically when you complete the task.
For example,
CommandBasedWSHumanTaskHandler handler = new CommandBasedWSHumanTaskHandler(ksession)
...
handler.connect()
..
session.registerWorkItemHandler("Human Task", handler);
This will make that:
1) The human task listeners for task completion are registered.
2) When task is registered, the listener has the session to continue the process.
Now, you can make
client.complete(taskId,...)
Now the listener (you can check it, GetResultContentResponseHandler) will be notified about task completion and process continued.
Hope this helps,
Demian
-
8. Re: Combining human and automated tasks
twizansk Dec 13, 2011 2:02 AM (in response to calca)Yes! That works! Registering the task handler when invoking the human task client was the part I was missing. Thank you.
As it turns out, I don't even need to load the original session. I can register the task handler with a new stateful session and it still works:
// Create a new session
KnowledgeBase kbase = readKnowledgeBase(CREATE_INSTALLER_PROCESS);
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
env.set(EnvironmentName.TRANSACTION_MANAGER, transactionManager);
StatefulKnowledgeSession ksession = JPAKnowledgeService
.newStatefulKnowledgeSession(kbase, null, env);
// Register a handler
CommandBasedWSHumanTaskHandler handler = new CommandBasedWSHumanTaskHandler(ksession);
handler.connect();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
// Create a human task client
TaskClient client = new TaskClient(new MinaTaskClientConnector(
"MinaConnector", new MinaTaskClientHandler(
SystemEventListenerFactory.getSystemEventListener())));
client.connect("127.0.0.1", 9123);
Thread.sleep(1000);
BlockingTaskSummaryResponseHandler taskSummaryResponseHandler = new BlockingTaskSummaryResponseHandler();
client.getTasksAssignedAsPotentialOwner("krisv", "en-UK",
taskSummaryResponseHandler);
List<TaskSummary> tasks = taskSummaryResponseHandler.getResults();
TaskSummary taskSummary = tasks.get(0);
long taskId = taskSummary.getId();
BlockingTaskOperationResponseHandler responseHandler = new BlockingTaskOperationResponseHandler();
client.start(taskId, "krisv", responseHandler);
// Complete the task
long taskId = taskSummary.getId();
BlockingTaskOperationResponseHandler responseHandler = new BlockingTaskOperationResponseHandler();
client.start(taskId, "krisv", responseHandler);
client.complete(taskId, "krisv", null, responseHandler);
I'd like to understand the details. When is it necessary to load an existing session and when can you use a new one? But, in the meantime, it works.
Thanks again.
Tommer
-
9. Re: Combining human and automated tasks
calca Dec 13, 2011 7:51 AM (in response to twizansk)Well, I was not clear about this too :S.
Krisv kindly explained it to me in jbpm irc.
Session contains data that you inserted in working memory when using bussiness rules (using session.insert to insert facts), rule state and timers. Process instances are almost independent units.
So If you don't have anything like this in the session, you can create another one and it will load your process data. If not (I mean, if process state and session state are linked), you have to load the correct session.
Demian
-
10. Re: Combining human and automated tasks
twizansk Dec 13, 2011 8:43 AM (in response to calca)Yes, that does clarify things a bit.
Thanks