JBoss Community

Process instance execution do not continue to the next task after completing a previous task.

created by Feki Ahmed in jBPM Development - View the full discussion

Hi,

 

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.

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.

 

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.

 

i also don't have any exception and nothing happen in the application , i just can't get the next task.

 

 

 

The following is the service java class which contain methods used for creating the session and completing the task.

 

public class JbpmAPIUtil {

 

 

          public static StatefulKnowledgeSession ksession=null;

          public static ProcessInstance processInstance;

 

          public static List<LunchedProc> lunchedprocs = new ArrayList<LunchedProc>();

          public static List<ProcessInstanceInfo> procsListfrmdb = new ArrayList<ProcessInstanceInfo>();

          private static TaskService client;

 

 

 

 

     /*

           * Complete a task with a taskid and data for a user

           */

 

          public static void completeTask(long taskId, Map<String,String> data, String userId){

 

 

                    UserTransaction ut=null;

 

                    try {

                              ut = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );

                    } catch (NamingException e1) {

                              e1.printStackTrace();

                    }

 

 

                    try {

                              ut.begin();

                    } catch (NotSupportedException e) {

                              e.printStackTrace();

                    } catch (SystemException e) {

                              e.printStackTrace();

                    }

 

                      client.start(taskId, userId);

 

                    try {

                              ut.commit();

                    } catch (IllegalStateException e) {

                              e.printStackTrace();

                    } catch (SecurityException e) {

                              e.printStackTrace();

                    } catch (HeuristicMixedException e) {

                              e.printStackTrace();

                    } catch (HeuristicRollbackException e) {

                              e.printStackTrace();

                    } catch (RollbackException e) {

                              e.printStackTrace();

                    } catch (SystemException e) {

                              e.printStackTrace();

                    }

 

                    ContentData contentData = null;

                    if (data != null) {

                              ByteArrayOutputStream bos = new ByteArrayOutputStream();

                              ObjectOutputStream out;

                              try {

                                        out = new ObjectOutputStream(bos);

                                        out.writeObject(data);

                                        out.close();

                                        contentData = new ContentData();

                                        contentData.setContent(bos.toByteArray());

                                        contentData.setAccessType(AccessType.Inline);

                              } catch (IOException e) {

                                        e.printStackTrace();

                              }

                    }

 

 

                    try {

                              ut.begin();

                    } catch (NotSupportedException e) {

                              e.printStackTrace();

                    } catch (SystemException e) {

                              e.printStackTrace();

                    }

 

                    client.complete(taskId, userId, contentData);

 

                    try {

                              ut.commit();

                    } catch (IllegalStateException e) {

                              e.printStackTrace();

                    } catch (SecurityException e) {

                              e.printStackTrace();

                    } catch (HeuristicMixedException e) {

                              e.printStackTrace();

                    } catch (HeuristicRollbackException e) {

                              e.printStackTrace();

                    } catch (RollbackException e) {

                              e.printStackTrace();

                    } catch (SystemException e) {

                              e.printStackTrace();

                    }

 

    }

 

          

 

 

private static StatefulKnowledgeSession CreateSession(String process){

 

    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

    kbuilder.add(new ClassPathResource(process), ResourceType.BPMN2);

 

 

    if (kbuilder.hasErrors()) {

        for (KnowledgeBuilderError error : kbuilder.getErrors()) {

            System.out.println(">>> Error:" + error.getMessage());

 

 

        }

        System.out.println(">>> Knowledge couldn't be parsed! ");

    }

 

 

    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();

 

 

    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());

    Environment env = EnvironmentFactory.newEnvironment();

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.runtime.ht");

    env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);

    env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());

 

 

   

    //  creating a Persistence Knowledge Session

    System.out.println(" >>> Let's create a Persistent Knowledge Session");

    final StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);

   

   

   

    int sessionId = ksession.getId();

    System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

    System.out.println("sessionId : "+sessionId);

   

    // We need to register the WorkItems and Listeners that the session will use

    createTaskService(emf);

    LocalHTWorkItemHandler localHTWorkItemHandler = new LocalHTWorkItemHandler(client, ksession);

   

   

   

    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", localHTWorkItemHandler);

   

    KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);   

   

          return ksession;

}

 

 

private static void createTaskService(EntityManagerFactory emf) {

 

    org.jbpm.task.service.TaskService taskService = new org.jbpm.task.service.TaskService(emf, SystemEventListenerFactory.getSystemEventListener());

    Map<String, User> users = new HashMap<String, User>();

    users.put("Administrator", new User("Administrator"));

    users.put("user1", new User("user1"));

    users.put("user2", new User("user2"));

   

 

    Map<String, Group> groups = new HashMap<String, Group>();

    taskService.addUsersAndGroups(users, groups);

    client = new LocalTaskService(taskService);

 

 

   

  }

  

 

}

 

 

Please , can someone guess what is wrong ??

Reply to this message by going to Community

Start a new discussion in jBPM Development at Community