4 Replies Latest reply on Jun 16, 2010 5:04 AM by janashanmug

    Tasks with assignment handlers in Fork doest not work

    janashanmug

      Hi

       

      Tasks with assignment-handlers inside a fork does not end in join, It seems the control does not goes beyond the task.

       

      Following is my jpdl. The control stops at "parallel Queue"

       

      Is this the correct method to handle tasks inside a fork? Can anyone help me?

       

       

      -------------------------------------------------------------------------------

      hello_world.assignee.jpdl.xml

      -------------------------------------------------------------------------------

       

      <?xml version="1.0" encoding="UTF-8"?>
      <process name="helloWorld" xmlns="http://jbpm.org/4.3/jpdl">
      <start g="27,248,80,40">
      <transition to="fork1"/>
      </start>
         <fork g="158,247,91,65" name="fork1">
            <on continue="exclusive" event="printHelloEnd"/>
            <transition g="182,486:" to="Parallel Queue"/>
            <transition g="182,61:121,-15" name="world" to="printHelloWorld"/>
         </fork>
         <join g="513,267,61,49" name="join1" continue="exclusive">
            <transition to="printHelloEnd"/>
         </join>
         <task g="224,457,211,57" name="Parallel Queue">
         <assignment-handler class="cos.workflow.helloworld.HelloWorldAssignmentHandler"/>
            <transition g="537,487:" to="join1"/>
         </task>
      <java class="cos.workflow.helloworld.Printer" g="468,42,138,40" method="printHelloWorld" name="printHelloWorld">
            <transition g="13,-27" name="join" to="join1"/>
      </java>
         <java class="cos.workflow.helloworld.Printer" g="664,268,116,48" method="printHelloEnd" name="printHelloEnd">
      <transition to="theEnd"/>
         </java>
      <end g="893,269,80,40" name="theEnd"/>
      </process>

       

      -------------------------------------------------------------------------------

      cos.workflow.helloworld.Main

      -------------------------------------------------------------------------------

       

       

      public class Main {

      public static void main(String[] args) {

       

      // Build jBPM services

      ProcessEngine processEngine = new Configuration().setResource("workflow.jbpm.cfg.xml").buildProcessEngine();

      RepositoryService repositoryService = processEngine.getRepositoryService();

      ExecutionService executionService = processEngine.getExecutionService();

       

      // Deploy helloWorld process definition and start a process instance

      repositoryService.createDeployment().addResourceFromClasspath("hello_world.assignee.jpdl.xml").deploy();

      ProcessInstance processInstance = executionService.startProcessInstanceByKey("helloWorld");

      TaskService taskService = processEngine.getTaskService();

      String pid = processInstance.getId();

       

      List < Task > taskList = taskService.findPersonalTasks("admin");

              Task task = taskList.get(0);

              taskService.completeTask(task.getId());

              processInstance = executionService.findProcessInstanceById(pid);

       

      }

      }

       

       

       

       

      -------------------------------------------------------------------------------

      cos.workflow.helloworld.HelloWorldAssignmentHandler

      -------------------------------------------------------------------------------

       

       

      public class HelloWorldAssignmentHandler implements COSAssignmentHandler {

       

      /**

      *

      */

      private static final long serialVersionUID = 1L;

      String userId;

       

      /* (non-Javadoc)

      * @see org.jbpm.api.task.AssignmentHandler#assign(org.jbpm.api.task.Assignable, org.jbpm.api.model.OpenExecution)

      */

      public void assign(Assignable assignable, OpenExecution execution)

      throws Exception {

      userId = "admin";

      System.out.println("cos.workflow.helloworld.HelloWorldAssignmentHandler");

      assignable.setAssignee(userId);

       

      }

       

      }

       

       

      -------------------------------------------------------------------------------

      cos.workflow.helloworld.Printer

      -------------------------------------------------------------------------------

       

       

      public class Printer {

      public void printHelloWorld() {

      System.out.println("<---------------->");

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

      System.out.println("<---------------->");

      }

      public void printHelloEnd() {

      System.out.println("<---------------->");

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

      System.out.println("<---------------->");

      }

      }

       

       

      Thanks

      Jana.

       

        • 1. Re: Tasks with assignment handlers in Fork doest not work
          rebody

          Hi Janarthanan,

           

          If you remove continue="exclusive" attribute from join activity, the process instance will end directly.

           

          Or, if you didn't want to delete continue="exclusive", please use managementService to execute job by handle,  Just like this:

           

           

          import java.util.List;
          
          import org.jbpm.api.ProcessInstance;
          import org.jbpm.api.history.HistoryTask;
          import org.jbpm.api.job.Job;
          import org.jbpm.api.task.Task;
          import org.jbpm.test.JbpmTestCase;
          
          public class MainTest extends JbpmTestCase {
          
           String deploymentId;
          
            protected void setUp() throws Exception {
              super.setUp();
          
              deploymentId = repositoryService.createDeployment()
                  .addResourceFromClasspath("hello_world.assignee.jpdl.xml")
                  .deploy();
            }
          
            protected void tearDown() throws Exception {
              repositoryService.deleteDeploymentCascade(deploymentId);
          
              super.tearDown();
            }
          
            public void testTask() {
                  ProcessInstance processInstance = executionService.startProcessInstanceByKey("helloWorld");
          
                  String pid = processInstance.getId();
          
                  List < Task > taskList = taskService.findPersonalTasks("admin");
          
                  Task task = taskList.get(0);
          
                  taskService.completeTask(task.getId());
          
                  processInstance = executionService.findProcessInstanceById(pid);
          
                  assertNotNull(processInstance);
          
          
                  List<Job> jobs = managementService.createJobQuery().list();
                  managementService.executeJob(jobs.get(0).getId());
                  jobs = managementService.createJobQuery().list();
                  managementService.executeJob(jobs.get(0).getId());
          
                  processInstance = executionService.findProcessInstanceById(pid);
          
                  assertNull(processInstance);
            }
          }
          
          1 of 1 people found this helpful
          • 2. Re: Tasks with assignment handlers in Fork doest not work
            janashanmug

            Hi HuiSheng

             

            Thanks a lot. That worked like a charm.

             

            Have another query. I get a null pointer exception if there is task or decision after the join.

             

            Have attached the test case.

            • 3. Re: Tasks with assignment handlers in Fork doest not work
              rebody

              Hi Janarthanan,

               

              This is an already fixed issue.  please refer here:

               

              https://jira.jboss.org/browse/JBPM-2758

              • 4. Re: Tasks with assignment handlers in Fork doest not work
                janashanmug

                Hi HuiSheng

                 

                I modified the ExecutionImpl and it worked like a magic.

                 

                Thank you once again for the help.