9 Replies Latest reply on Sep 8, 2011 4:22 AM by d.y.

    obsolete id

    d.y.

      Greetings,

       

      i get a Nullpointer exception due to an obsolete workitem id. I created a process with the eclipse bpmn2 process editor so the ids of the tasks are automatically incremented. then i deleted some tasks and replaced them. so in my case the task with id 10 got deleted and replaced with a task with the id 34. but when i start my process and it comes to my custom task and custom task handler i get 10 as the id instead of 34

       

      public void executeWorkItem(WorkItem wi, WorkItemManager wim) {

              this.workItemId = wi.getId(); // ==10 instead of 34

              this.wi = wi;     // wi.name is also wrong

              this.workItemManager = wim;

       

      I could run my process when i used ((RuleFlowProcess) process).getNode(34).getOutgoingConnections().values() instead of

      ((RuleFlowProcess) process).getNode(workItemId).getOutgoingConnections().values()

       

      but that is not a satisfying solution ;-) Is this bug known or do you have any advices how to solve this issue?

       

      I'm using jbpm 5.1

        • 1. Re: obsolete id
          eaa

          One thing are the ids used in the process definition (xml) and another thing are the runtime ids.

          I'm a little bit confused about the sentence "I could run my process when...". Could you please explain what are you trying to do?

          • 2. Re: obsolete id
            d.y.

            I want to access the outgoing connections of the current node / workitem. when i try it this way:

            ((RuleFlowProcess) process).getNode(workItemId).getOutgoingConnections().values() i get a NullPointer exception because the workitemId is 10 and there is no more node with id 10 in my bpmn file.

            • 3. Re: obsolete id
              eaa

              Ok, but I just want to make sure that you are not trying to continue the execution of the process using its outgoing connections. Right?

              • 4. Re: obsolete id
                d.y.

                nono, i know that this works automatic

                • 5. Re: obsolete id
                  eaa

                  It is not automatic. You have to use workItemManager.completeWorkItem(...);

                   

                  But, regarding to the work item Id, what you get when you do wi.getId() is something like a runtime id. Is an id that is only valid for the pocess instance where the work item handler got invoked. It has nothing to do with the id attribute of the Task node in your bpmn2 file.

                  AFAIK, there is no way to know that information inside a work item handler. I think you may need to preprocess this before the node and pass it as a parameter.

                   

                  Best Regards,

                  • 6. Re: obsolete id
                    francesco.pietrobelli

                    You can use this method:

                     

                    /**
                               * Get the node instance corresponding to a work item identified with
                               * <code>workItemId</code>
                               * 
                               * @param workItemId
                               *            identification of work item id
                               * @param container
                               *            the container that contains the node instance, in most case
                               *            the process instance
                               * @return null if no node instance is found, the correspond node instance
                               *         otherwise
                               */
                              public static WorkItemNodeInstance findNodeInstance(long workItemId,
                                                  NodeInstanceContainer container) {
                                        for (NodeInstance nodeInstance : container.getNodeInstances()) {
                                                  if (nodeInstance instanceof WorkItemNodeInstance) {
                                                            WorkItemNodeInstance workItemNodeInstance = (WorkItemNodeInstance) nodeInstance;
                                                            if (workItemNodeInstance.getWorkItem().getId() == workItemId) {
                                                                      return workItemNodeInstance;
                                                            }
                                                  }
                                                  if (nodeInstance instanceof NodeInstanceContainer) {
                                                            WorkItemNodeInstance result = findNodeInstance(workItemId,
                                                                                ((NodeInstanceContainer) nodeInstance));
                                                            if (result != null) {
                                                                      return result;
                                                            }
                                                  }
                                        }
                                        return null;
                              }
                    
                    

                     

                    and then invoke the method getNodeId() on returned object.

                     

                    Of course your WorkItemHandler needs a reference to StatefulKnowledgeSession, but you can pass it when you register your WorkItemHandler on your session.

                     

                    I hope this is useful.

                    1 of 1 people found this helpful
                    • 7. Re: obsolete id
                      d.y.

                      Well that could help but I'm having trouble casting the process to a processInstance:

                       

                      WorkflowProcessInstance wfpI = (WorkflowProcessInstance) (process);

                      or

                      RuleFlowProcessInstance rfpI = (RuleFlowProcessInstance) (process);

                       

                      doesn't work. how do you do that?

                      • 8. Re: obsolete id
                        francesco.pietrobelli

                        yep... this is very strange!!!

                         

                        are you sure to use org.jbpm.workflow.instance.WorkflowProcessInstance? because the code for  HumanTaskHandler that i'am actually using with jBPM5.1 is:

                         

                         

                        public void executeWorkItem(WorkItem item, WorkItemManager manager) {
                                WorkflowProcessInstance currentProcess = (WorkflowProcessInstance) ksession
                                        .getProcessInstance(item.getProcessInstanceId());
                                if (currentProcess == null) {
                                    log.error("Can't find current process instance relative to " + item);
                                    manager.abortWorkItem(item.getId());
                                    return;
                                }
                        
                                HumanTaskNodeInstance currentNode = (HumanTaskNodeInstance) JbpmUtility
                                        .findNodeInstance(item.getId(), currentProcess);
                                if (currentNode == null) {
                                    log.error("Can't find current node instance relative to " + item);
                                    manager.abortWorkItem(item.getId());
                                    return;
                                }
                             ...     
                             ...
                        }
                        
                        1 of 1 people found this helpful
                        • 9. Re: obsolete id
                          d.y.

                          you are right, i used the wrong package. casting works now, thank you.:-) strangely my session is null. i gotta check out why. nvm, everything works :-)