5 Replies Latest reply on Sep 11, 2014 8:15 AM by cyu021

    [Need Help] Unable to complete a process with intermediate catch event

    cyu021

      Hi all,

       

      I am experiencing a problem with intermediate catch event.

      If I add a intermediate catch event (say signal event) to a process,

      the process will process to the task following the signal event (eg. Close Up).
      my process

       

      The associated work item handler runs all right, but the process just won't complete (I did invoke completeWorkItem() in work item handler).

      What I mean by "it won't complete" is that process's status is still 1 (active) and the session is not deleted when I look at processinstancelog and sessionifo table in database.

      processinstancelog table

      sessioninfo table

        • 1. Re: [Need Help] Unable to complete a process with intermediate catch event
          swiderski.maciej

          see the other post of yours, most likely same issue that logger is not registered on ksession and thus processinstancelog is not updated while processinstanceinfo is emptied. sessioninfo is not removed by default unless you use runtime manager with per request or per process instance strategies.

           

          HTH

          • 2. Re: Re: [Need Help] Unable to complete a process with intermediate catch event
            cyu021

            Hi Maciej,

             

            After adding JPAWorkingMemoryDbLogger logger = new JPAWorkingMemoryDbLogger(ksession); into the code, I can see two records in processinstancelog.

            One with status =1, and the other with status =2.

            It looks like the process is now complete.

            However, when I try to print out the status by invoking getState(), it still shows 1. Also, the returnObject is not really returned from work item handler.

            From debug log, I can see the print out message I put before completeWorkItem(), but completeWorkItem() doesn't seem to finish its job.

             

            Code snippet for signalEvent()

                public ReturnObject signalProcess(String signal, String data, int sessionId, long pid) throws UnsupportedEncodingException {

                    ksession = kstore.loadKieSession(sessionId, kbase, ksconf, environment);

                    ksession.getWorkItemManager().registerWorkItemHandler("Close Up", new CloseUpWorkItemHandler());      

                    JPAWorkingMemoryDbLogger logger = new JPAWorkingMemoryDbLogger(ksession);      

                    ProcessInstance processInstance = ksession.getProcessInstance(pid);      

                    ksession.signalEvent(signal, data, pid);      

                    WorkflowProcessInstance p = (WorkflowProcessInstance) processInstance;

                    System.out.println(processInstance.getState());

                    ReturnObject output = (ReturnObject) p.getVariable("returnObject");

                    System.out.println(output);

                    logger.dispose();

                    return output;

                }

             

            Code snippet for completeWorkItem()

                @Override

                public void executeWorkItem(WorkItem arg0, WorkItemManager arg1) {

                    // TODO Auto-generated method stub

                    System.out.println(arg0.getName());

                    ReturnObject ro = new ReturnObject((String)arg0.getParameter("returnCode"), (String)arg0.getParameter("description"));

                    Map<String, Object> params = new HashMap<String, Object>();

                    params.put("nodeId", arg0.getName());       

                   params.put("returnObject", ro);

                    System.out.println("ro = " + ro);

                    arg1.completeWorkItem(arg0.getId(), params);

                }

            • 3. Re: [Need Help] Unable to complete a process with intermediate catch event
              swiderski.maciej

              after you signal the process instance to get an up to date information you need to perform

              processInstance = ksession.getProcessInstance(pid);

              please note that when process instance is completed it will return null as runtime data is removed on instance completion. To find more you can query history tables using AuditService.

               

              HTH

              • 4. Re: Re: [Need Help] Unable to complete a process with intermediate catch event
                cyu021

                Thank you Maciej,

                 

                I try to use the following code snippet to get AuditService, but I got this error:

                2014-09-11 16:06:24,856 [main] ERROR Error when executing deadlines

                java.lang.IllegalArgumentException: Named query not found: UnescalatedStartDeadlines

                    at org.hibernate.ejb.AbstractEntityManagerImpl.createNamedQuery(AbstractEntityManagerImpl.java:601) ~[hibernate-entitymanager-4.2.3.Final.jar:4.2.3.Final]

                    at org.jbpm.services.task.persistence.JPATaskPersistenceContext.queryInTransaction(JPATaskPersistenceContext.java:367) ~[jbpm-human-task-jpa-6.1.0.Final.jar:6.1.0.Final]

                    at org.jbpm.services.task.commands.InitDeadlinesCommand.execute(InitDeadlinesCommand.java:37) [jbpm-human-task-core-6.1.0.Final.jar:6.1.0.Final]

                    at org.jbpm.services.task.commands.InitDeadlinesCommand.execute(InitDeadlinesCommand.java:18) [jbpm-human-task-core-6.1.0.Final.jar:6.1.0.Final]

                    at org.jbpm.services.task.commands.TaskCommandExecutorImpl$SelfExecutionCommandService.execute(TaskCommandExecutorImpl.java:65) [jbpm-human-task-core-6.1.0.Final.jar:6.1.0.Final]

                    at org.drools.core.command.impl.AbstractInterceptor.executeNext(AbstractInterceptor.java:41) [drools-core-6.1.0.Final.jar:6.1.0.Final]

                    at org.jbpm.services.task.persistence.TaskTransactionInterceptor.execute(TaskTransactionInterceptor.java:54) [jbpm-human-task-jpa-6.1.0.Final.jar:6.1.0.Final]

                    at org.jbpm.services.task.commands.TaskCommandExecutorImpl.execute(TaskCommandExecutorImpl.java:40) [jbpm-human-task-core-6.1.0.Final.jar:6.1.0.Final]

                    at org.jbpm.services.task.impl.TaskDeadlinesServiceImpl.initialize(TaskDeadlinesServiceImpl.java:367) [jbpm-human-task-core-6.1.0.Final.jar:6.1.0.Final]

                    at org.jbpm.services.task.HumanTaskConfigurator.getTaskService(HumanTaskConfigurator.java:153) [jbpm-human-task-core-6.1.0.Final.jar:6.1.0.Final]

                    at org.jbpm.runtime.manager.impl.factory.LocalTaskServiceFactory.newTaskService(LocalTaskServiceFactory.java:65) [jbpm-runtime-manager-6.1.0.Final.jar:6.1.0.Final]

                    at org.jbpm.runtime.manager.impl.SingletonRuntimeManager.init(SingletonRuntimeManager.java:82) [jbpm-runtime-manager-6.1.0.Final.jar:6.1.0.Final]

                    at org.jbpm.runtime.manager.impl.RuntimeManagerFactoryImpl.newSingletonRuntimeManager(RuntimeManagerFactoryImpl.java:71) [jbpm-runtime-manager-6.1.0.Final.jar:6.1.0.Final]

                    at org.jbpm.runtime.manager.impl.RuntimeManagerFactoryImpl.newSingletonRuntimeManager(RuntimeManagerFactoryImpl.java:62) [jbpm-runtime-manager-6.1.0.Final.jar:6.1.0.Final]

                    at com.fet.sdp.poc.bpm.BPMService01.testProcess(BPMService01.java:179) [classes/:na]

                    at com.fet.sdp.poc.bpm.PTest01.main(PTest01.java:40) [classes/:na]

                Exception in thread "main" javax.persistence.NonUniqueResultException: result returns more than one elements

                    at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:295)

                    at org.jbpm.process.audit.JPAAuditLogService.findProcessInstance(JPAAuditLogService.java:158)

                    at org.jbpm.process.audit.JPAAuditLogService.findProcessInstance(JPAAuditLogService.java:53)

                    at com.fet.sdp.poc.bpm.BPMService01.testProcess(BPMService01.java:182)

                    at com.fet.sdp.poc.bpm.PTest01.main(PTest01.java:40)

                 

                This is the code I use:

                Why does it "result returns more than one elements"?

                ...

                ksession = kstore.newKieSession(kbase, ksconf, environment);

                ...

                ProcessInstance processInstance = ksession.startProcess("npg.cc_deduct_2", params);

                ...

                ksession.signalEvent("Signal_1", null, processInstance.getId());

                ...

                RuntimeEnvironmentBuilder builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).knowledgeBase(kbase);

                RuntimeManager manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(builder.get());

                RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());

                AuditService logService = runtime.getAuditLogService();

                ProcessInstanceLog log = logService.findProcessInstance(processInstance.getId());

                System.out.println("log status = " + log.getStatus());

                • 5. Re: Re: Re: [Need Help] Unable to complete a process with intermediate catch event
                  cyu021

                  OK, I finally figure out the way to get AuditService by using the following code snippet:

                  AuditService logService = new JPAAuditLogService(ksession.getEnvironment());

                  and how I can get the correct status for the signalled process

                  ProcessInstanceLog log = logService.findProcessInstance(processInstance.getId());

                  System.out.println("log status = " + log.getStatus()); // <-- shows "2" now

                  and exam variables with

                  List<? extends VariableInstanceLog> varInstanceLogList = logService.findVariableInstances(processInstance.getId());

                   

                  Thanks for your support, Maciej !