1 Reply Latest reply on Dec 23, 2008 10:22 AM by kukeltje

    Error in executing jbpm code

    ajaykamath7

      i am runing below code code for Jbpm

      package com.sample.action;
      import java.util.ArrayList;
      import java.util.Collection;
      import java.util.Iterator;
      import java.util.List;

      import org.jbpm.graph.def.ProcessDefinition;
      import org.jbpm.graph.exe.ProcessInstance;
      import org.jbpm.graph.exe.Token;
      import org.jbpm.taskmgmt.def.Task;
      import org.jbpm.taskmgmt.exe.TaskInstance;

      public class TestWorkflow {

      public static void main(String args[])throws Exception {
      new TestWorkflow().execute();
      }

      public void execute() throws Exception {
      // Extract process from the processdefinition.xml file.
      ProcessDefinition processDefinition =ProcessDefinition.parseXmlResource("NewSample/processdefinition.xml");
      ProcessInstance instance =new ProcessInstance(processDefinition);


      displayStatus(instance);
      instance.signal();

      displayStatus(instance);
      executeTask(instance);


      displayStatus(instance);
      executeTask(instance);

      displayStatus(instance);


      }

      private void displayStatus(ProcessInstance instance) {


      String nodeName = instance.getRootToken().getNode().getName();
      System.out.println("task node executed: "+nodeName);

      }

      private void executeTask(ProcessInstance instance) {

      // Get the Task Instance List
      ArrayList taskList = new ArrayList(instance.getTaskMgmtInstance().getTaskInstances());
      System.out.println("length" +taskList.size());
      Iterator iter = taskList.iterator();

      while (iter.hasNext()) {

      TaskInstance taskInstance = (TaskInstance)iter.next();

      System.out.println("Found Task "+taskInstance.getName());
      System.out.println("Found Actor "+taskInstance.getActorId());

      taskInstance.end();
      System.out.println("Task completed");
      }

      }



      }
      i am getting the following error
      Exception in thread "main" java.lang.IllegalStateException: task instance '0' is already ended

      pls help...

        • 1. Re: Error in executing jbpm code
          kukeltje

          taskList contains ALL tasks for a process, also the ended ones... so add an additional check to see if it is not already ended.

          Only when you provide an actor, you get a list of unfinished tasks (but that method is on the JbpmContext