<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Re: Human task : assign the good task to the launcher of a processInstance
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/joploya">Sandra Renaud</a> in <i>jBPM</i> - <a href="https://community.jboss.org/message/775746#775746">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>I think I find a way to retrieve the good task for my Requestor, but an upstream problem appears :</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>First the way to start the good task :</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">                               <font color="darkgreen">//Now the PM_PL process his task (it is already complete in reality)</font>
                              List<String> groups = <font color="navy"><b>new</b></font> ArrayList<String>();
                              groups.add(requestor.getRole());
                              System.out.println(<font color="red">"Groups : "</font>);
                              <font color="navy"><b>for</b></font>(String grp : groups)<font color="navy">{</font>
                                        System.out.println(<font color="red">" - "</font>+grp);
                              <font color="navy">}</font>
 
                              BlockingTaskSummaryResponseHandler taskSummaryResponseHandler = <font color="navy"><b>new</b></font> BlockingTaskSummaryResponseHandler();
                              amsKnowledgeSession.getClient()
                                                                                .getTasksAssignedAsPotentialOwner(requestor.getName(), groups, <font color="red">"en-UK"</font>, taskSummaryResponseHandler);
                              List<TaskSummary> potentialTasks = taskSummaryResponseHandler.getResults();
                              TaskSummary requestorTask = <font color="navy"><b>null</b></font>;
                              <font color="navy"><b>for</b></font>(TaskSummary task : potentialTasks)<font color="navy">{</font>
                                        System.out.println(<font color="red">"PM_PL can execute task "</font> + task.getName() + <font color="red">" ("</font> + task.getId() + <font color="red">" : "</font> + task.getDescription() + <font color="red">")"</font>);
                                        <font color="navy"><b>if</b></font>(process.getId() == task.getProcessInstanceId())<font color="navy">{</font>
                                                  System.out.println(<font color="red">"The task "</font>+task.getId()+<font color="red">" "</font>+task.getName()+<font color="red">" is the one the requestor have to take"</font>);
                                                  requestorTask = task;;
                                        <font color="navy">}</font>
                              <font color="navy">}</font>
                              BlockingTaskOperationResponseHandler taskOperationResponseHandler = <font color="navy"><b>new</b></font> BlockingTaskOperationResponseHandler();
                              amsKnowledgeSession.getClient().start(requestorTask.getId(), requestor.getName(), taskOperationResponseHandler);
                              Thread.sleep(60000);
                              System.out.println(<font color="red">"The PM_PL has well finish his task : call to complete"</font>);
                              amsKnowledgeSession.getClient().complete(requestorTask.getId(), requestor.getName(), null, taskOperationResponseHandler);
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The problem now is that each task has the same processInstanceId, processSessionId and workItemId in the database. However I start a new KnowledgeSession and a new process each time :</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">            KnowledgeBase kbase = readKnowledgeBase();
            StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
            KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, <font color="red">"/log/loggerFile.log"</font>, 1000);
            HornetQHTWorkItemHandler hornetQHTWorkItemHandler = <font color="navy"><b>new</b></font> HornetQHTWorkItemHandler(ksession);
            ksession.getWorkItemManager().registerWorkItemHandler(<font color="red">"Human Task"</font>, hornetQHTWorkItemHandler);
           
            <font color="darkgreen">// start a new process instance</font>
            Map<String, Object> params = <font color="navy"><b>new</b></font> HashMap<String, Object>();
            params.put(<font color="red">"userId"</font>, requestor.getName());
            params.put(<font color="red">"userGroup"</font>, requestor.getRole());
            params.put(<font color="red">"flowId"</font>, getFlowEntity().getFlowId());
 
            ProcessInstance process = ksession.startProcess(<font color="red">"com.st.ams.flow.npl"</font>, params);
            System.out.println(<font color="red">"process = "</font>+process.getProcessId()+<font color="red">" : "</font>+process.getProcessName()+<font color="red">" : state("</font>+process.getState()+<font color="red">")"</font>);
            SystemEventListenerFactory.setSystemEventListener(<font color="navy"><b>new</b></font> SystemEventListener());
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>If you have a little clue to help me progress...</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Thanks</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/775746#775746">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>