[jboss-user] [jBPM] - How to complete a workitem after session load in jbpm 5.0.0.

Feki Ahmed do-not-reply at jboss.com
Tue Mar 5 02:53:38 EST 2013


Feki Ahmed [https://community.jboss.org/people/bardelman] created the discussion

"How to complete a workitem after session load in jbpm 5.0.0."

To view the discussion, visit: https://community.jboss.org/message/800742#800742

--------------------------------------------------------------
Hi, 
i ve worked with the version 5.4 and have resolved this problem but i have an unfinished project with the version 5.0.0 which must be completed with that version.

To complete a workitem in version 5.4 i had to write : 

ksession.getWorkItemManager().completeWorkItem(client.getTask(Task.getId()).getTaskData().getWorkItemId(), null);

For the version 5.0.0 i 've written a test case like with a java class which is the following : 



public class Jbpm500MainTest {



          private static Log log = LogFactory.getLog(Jbpm500MainTest.class);


    static StatefulKnowledgeSession ksession =null;
    public static ProcessInstance processInstance=null; 




          public static void main( String[] args) {


                  ///////////////part 1 : creating session ///////////////////////



                              try {         
                            UserTransaction ut = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );
                      ut.begin();
                      ksession = JbpmAPIUtil.getSession("modele1.bpmn");

                            /*Create the knowledge base  */

 KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "testlog", 1000);
 CommandBasedWSHumanTaskHandler taskHandler = new CommandBasedWSHumanTaskHandler(ksession);
 ksession.getWorkItemManager().registerWorkItemHandler("Human Task", taskHandler);
 taskHandler.connect();
 ut.commit();

 logger.close();
                              } catch (Throwable t) {
                                        //log.error(t.getMessage(), t.getCause());
                                        throw new RuntimeException("error while creating session",t);
                              }                  


                              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();
                              } 


                              System.out.println("Starting process...");
                              processInstance = ksession.startProcess("modele1");



                              ksession.fireAllRules();
                              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();
                              }



                              ////Looking for tasks 1
                              java.util.List<TaskSummary> tasks = null;
                              boolean reservedtaskfound=false;


                              while(!reservedtaskfound){

                                        tasks = JbpmAPIUtil.getAssignedTasks("user1");

                                        if(tasks != null && tasks.size()!=0){

                                        System.out.println("-----------------------------------------");
                                        System.out.println("Looking for tasks 1 :  tasks : "+tasks);

                                                                                //////Completing the gotten task
                                                                                try {
                                                                                          if(tasks!=null && tasks.size()!=0)
                                                                                          for(TaskSummary ts : tasks){ 
                                                                                                    if(ts!=null && ts.getStatus().toString()=="Reserved"){
                                                                                          System.out.println(""+ts.getId()); 
                                                                                          if(!reservedtaskfound)
                                                                                                    JbpmAPIUtil.completeTask(ts.getId(), null, "user1");
                                                                                                    reservedtaskfound=true;
                                                                                          break;

                                                                                                    }
                                                                                          }
                                                                                } catch (InterruptedException e) {
                                                                                          // TODO Auto-generated catch block
                                                                                          e.printStackTrace();
                                                                                }


                                        }else{
                                                  System.out.println("tasks 1 is still null  ");
                                                  System.out.println("-----------------------------------------");
                                        }


                                        }
                              ///////////////////////////////////disposing session : must wait until the next task is generated with the status "Reserved" ///////////////////////////////////

                              tasks = null;
                              reservedtaskfound=false;
                              int idsession=1;

                              while(!reservedtaskfound){

                                        tasks = JbpmAPIUtil.getAssignedTasks("user1");

                                        if(tasks != null && tasks.size()!=0){

                                        System.out.println("-----------------------------------------");
                                        System.out.println("Looking for tasks 2 :  tasks : "+tasks);



                                                                                          if(tasks!=null && tasks.size()!=0)
                                                                                          for(TaskSummary ts : tasks){ 
                                                                                                    if(ts!=null && ts.getStatus().toString()=="Reserved"){
                                                                                          System.out.println(""+ts.getId()); 

                                                                                          if(!reservedtaskfound){
                                                                                                    System.out.println("Disposing Session..  ");
                                                                                                    idsession = ksession.getId();
                                                                                                    ksession.dispose();
                                                                                          }
                                                                                          reservedtaskfound=true;
                                                                                          break;

                                                                                                    }
                                                                                          }



                                        }else{
                                                  System.out.println("tasks 2 is still null  ");
                                                  System.out.println("-----------------------------------------");
                                        }


                                        }



        //Loading the session 
                              KnowledgeBase kbase = null;
                              try {
                                        kbase = JbpmAPIUtil.readKnowledgeBase("modele1.bpmn");
                              } catch (Exception e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                              }
                              EntityManagerFactory emf = Persistence.createEntityManagerFactory( "org.jbpm.persistence.jpa" );
                              Environment env = KnowledgeBaseFactory.newEnvironment();
                              env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );
                              env.set( EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager() );
                              env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );

                              Properties properties = new Properties();
                              properties.put("drools.processInstanceManagerFactory", "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");
                              properties.put("drools.processSignalManagerFactory", "org.jbpm.persistence.processinstance.JPASignalManagerFactory");
                              KnowledgeSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);

                              System.out.println("loading Session..  ");
                              StatefulKnowledgeSession loadedksession  = JPAKnowledgeService.loadStatefulKnowledgeSession(idsession, kbase, null, env);


                              KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(loadedksession, "testlog", 1000);
                              CommandBasedWSHumanTaskHandler taskHandler2 = new CommandBasedWSHumanTaskHandler(loadedksession);
                              loadedksession.getWorkItemManager().registerWorkItemHandler("Human Task", taskHandler2);
                              taskHandler2.connect();




                              tasks = null;
                              reservedtaskfound=false;
                              Long completedtaskId =0L;





                              while(!reservedtaskfound){

                                        tasks = JbpmAPIUtil.getAssignedTasks("user1");

                                        if(tasks != null && tasks.size()!=0){

                                        System.out.println("-----------------------------------------");
                                        System.out.println("Looking for tasks 2 :  tasks : "+tasks);

                                                                                //////Complleting the gotten task
                                                                                try {
                                                                                          if(tasks!=null && tasks.size()!=0)
                                                                                          for(TaskSummary ts : tasks){ 
                                                                                                    if(ts!=null && ts.getStatus().toString()=="Reserved"){
                                                                                          System.out.println(""+ts.getId()); 

                                                                                          if(!reservedtaskfound)
                                                                                          JbpmAPIUtil.completeTask(ts.getId(), null, "user1");
                                                                                          completedtaskId = ts.getId();
                                                                                          reservedtaskfound=true;
                                                                                          break;

                                                                                                    }
                                                                                          }
                                                                                } catch (InterruptedException e) {
                                                                                          // TODO Auto-generated catch block
                                                                                          e.printStackTrace();
                                                                                }


                                        }else{
                                                  System.out.println("tasks 2 is still null  ");
                                                  System.out.println("-----------------------------------------");
                                        }


                                        }

//HERE the workitem must be completed in order to make the process continue its execution to the next task  
  ???????????????????????


// looking for the next task and completing it .

                              tasks = null;
                              reservedtaskfound=false;


                              while(!reservedtaskfound){

                                        tasks = JbpmAPIUtil.getAssignedTasks("user1");

                                        if(tasks != null && tasks.size()!=0){

                                        System.out.println("-----------------------------------------");
                                        System.out.println("Looking for tasks 3 :  tasks : "+tasks);

                                                                                //////Complleting the gotten task
                                                                                try {
                                                                                          if(tasks!=null && tasks.size()!=0)
                                                                                          for(TaskSummary ts : tasks){ 
                                                                                                    if(ts!=null && ts.getStatus().toString()=="Reserved"){
                                                                                          System.out.println(""+ts.getId()); 

                                                                                          if(!reservedtaskfound)
                                                                                          JbpmAPIUtil.completeTask(ts.getId(), null, "user1");
                                                                                          reservedtaskfound=true;
                                                                                          break;

                                                                                                    }
                                                                                          }
                                                                                } catch (InterruptedException e) {
                                                                                          // TODO Auto-generated catch block
                                                                                          e.printStackTrace();
                                                                                }


                                        }else{
                                                  System.out.println("tasks 3 is still null  ");
                                                  System.out.println("-----------------------------------------");
                                        }

  }
}

}


Both 5.0 and 5.4  API's are very different and i coudn't follow the same  5.4 syntaxe for the 5.0. 
for example : in the method getTask(long, TaskClientHandler.GetTaskResponseHandler), i dont know what to put as second parameter, my taskHandler2 does't have a method GetTaskResponseHandler. and the getTask itself doesn't have the getTaskData()...

Thanks for help !
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800742#800742]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130305/afd5b864/attachment-0001.html 


More information about the jboss-user mailing list