<!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;">
Process instance execution do not continue to the next task after completing a previous task.
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/bardelman">Feki Ahmed</a> in <i>jBPM Development</i> - <a href="https://community.jboss.org/message/799100#799100">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Hi, </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>i m using jbpm 5.4 embeded on a web application and i ve a problem after completing a task, getting the next task with the "getTasksAssignedAsPotentialOwner" do not return anything.</p><p><span style="font-size: 10pt;">When i created  the session which contain the process i registered a "LocalHTWorkItemHandler", so i don't think i need to complete it in order to the process to be continued.</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-size: 10pt;">After the task is completed , i checked on the database and found its status "completed" so i think nothing wrong have happened in completing/persisting operations.</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-size: 10pt;">i also don't have any exception and nothing happen in the application , i just can't get the next task.<br/></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h6>The following is the service java class which contain methods used for creating the session and completing the task.</h6><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>public class JbpmAPIUtil {</p><p>  </p><p>  </p><p>          public static StatefulKnowledgeSession ksession=null;</p><p>          public static ProcessInstance processInstance;</p><p>  </p><p>          public static List<LunchedProc> lunchedprocs = new ArrayList<LunchedProc>();</p><p>          public static List<ProcessInstanceInfo> procsListfrmdb = new ArrayList<ProcessInstanceInfo>();</p><p>          private static TaskService client;</p><p>  </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>  </p><p>     /*</p><p>           * Complete a task with a taskid and data for a user </p><p>           */</p><p>  </p><p>          public static void completeTask(long taskId, Map<String,String> data, String userId){</p><p>  </p><p>  </p><p>                    UserTransaction ut=null;</p><p>  </p><p>                    try {</p><p>                              ut = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );</p><p>                    } catch (NamingException e1) { </p><p>                              e1.printStackTrace();</p><p>                    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    try {</p><p>                              ut.begin();</p><p>                    } catch (NotSupportedException e) { </p><p>                              e.printStackTrace();</p><p>                    } catch (SystemException e) { </p><p>                              e.printStackTrace();</p><p>                    } </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                      client.start(taskId, userId);</p><p>  </p><p>                    try {</p><p>                              ut.commit();</p><p>                    } catch (IllegalStateException e) { </p><p>                              e.printStackTrace();</p><p>                    } catch (SecurityException e) { </p><p>                              e.printStackTrace();</p><p>                    } catch (HeuristicMixedException e) { </p><p>                              e.printStackTrace();</p><p>                    } catch (HeuristicRollbackException e) { </p><p>                              e.printStackTrace();</p><p>                    } catch (RollbackException e) { </p><p>                              e.printStackTrace();</p><p>                    } catch (SystemException e) { </p><p>                              e.printStackTrace();</p><p>                    }</p><p>  </p><p>                    ContentData contentData = null;</p><p>                    if (data != null) {</p><p>                              ByteArrayOutputStream bos = new ByteArrayOutputStream();</p><p>                              ObjectOutputStream out;</p><p>                              try {</p><p>                                        out = new ObjectOutputStream(bos);</p><p>                                        out.writeObject(data);</p><p>                                        out.close();</p><p>                                        contentData = new ContentData();</p><p>                                        contentData.setContent(bos.toByteArray());</p><p>                                        contentData.setAccessType(AccessType.Inline);</p><p>                              } catch (IOException e) {</p><p>                                        e.printStackTrace();</p><p>                              }</p><p>                    }</p><p>  </p><p>  </p><p>                    try {</p><p>                              ut.begin();</p><p>                    } catch (NotSupportedException e) { </p><p>                              e.printStackTrace();</p><p>                    } catch (SystemException e) { </p><p>                              e.printStackTrace();</p><p>                    }</p><p>  </p><p>                    client.complete(taskId, userId, contentData);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    try {</p><p>                              ut.commit();</p><p>                    } catch (IllegalStateException e) { </p><p>                              e.printStackTrace();</p><p>                    } catch (SecurityException e) { </p><p>                              e.printStackTrace();</p><p>                    } catch (HeuristicMixedException e) { </p><p>                              e.printStackTrace();</p><p>                    } catch (HeuristicRollbackException e) { </p><p>                              e.printStackTrace();</p><p>                    } catch (RollbackException e) { </p><p>                              e.printStackTrace();</p><p>                    } catch (SystemException e) { </p><p>                              e.printStackTrace();</p><p>                    }</p><p>  </p><p>    }</p><p>  </p><p>           </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>private static StatefulKnowledgeSession CreateSession(String process){</p><p>  </p><p>    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();</p><p>    kbuilder.add(new ClassPathResource(process), ResourceType.BPMN2);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    if (kbuilder.hasErrors()) {</p><p>        for (KnowledgeBuilderError error : kbuilder.getErrors()) {</p><p>            System.out.println(">>> Error:" + error.getMessage());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        }</p><p>        System.out.println(">>> Knowledge couldn't be parsed! ");</p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());</p><p>    Environment env = EnvironmentFactory.newEnvironment();</p><p>    EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.runtime.ht");</p><p>    env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);</p><p>    env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    </p><p>    //  creating a Persistence Knowledge Session</p><p>    System.out.println(" >>> Let's create a Persistent Knowledge Session");</p><p>    final StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);</p><p>    </p><p>    </p><p>    </p><p>    int sessionId = ksession.getId();</p><p>    System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");</p><p>    System.out.println("sessionId : "+sessionId);</p><p>    </p><p>    // We need to register the WorkItems and Listeners that the session will use</p><p>    createTaskService(emf);</p><p>    LocalHTWorkItemHandler localHTWorkItemHandler = new LocalHTWorkItemHandler(client, ksession);</p><p>    </p><p>    </p><p>    </p><p>    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", localHTWorkItemHandler);</p><p>    </p><p>    KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);    </p><p>    </p><p>          return ksession;</p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>private static void createTaskService(EntityManagerFactory emf) {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    org.jbpm.task.service.TaskService taskService = new org.jbpm.task.service.TaskService(emf, SystemEventListenerFactory.getSystemEventListener());</p><p>    Map<String, User> users = new HashMap<String, User>();</p><p>    users.put("Administrator", new User("Administrator"));</p><p>    users.put("user1", new User("user1"));</p><p>    users.put("user2", new User("user2"));</p><p>    </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    Map<String, Group> groups = new HashMap<String, Group>();</p><p>    taskService.addUsersAndGroups(users, groups);</p><p>    client = new LocalTaskService(taskService);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    </p><p>  }</p><p>   </p><p>  </p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Please , can someone guess what is wrong ??</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/799100#799100">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM Development at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2035">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>