5 Replies Latest reply on Jan 23, 2008 4:11 AM by kukeltje

    Re: task in start state

    debnathm

      Hi

      I have the following state definition (fragment):

      <process-definition>
      <start-state name='start'>
      <task name='StartStateTask'>
      <controller>
      <variable access='read,write,required' name='variable1' mapped-name='Var1'></variable>
      </controller>
      </task>
      <transition to='task-node1' name='to_task_node1'></transition>
      </start-state>
      ...

      I use the following code to create a process Instance:

      ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
      <xml string above>);

      ProcessInstance processInstance = new ProcessInstance(processDefinition);


      Later, I call the following code:

      TaskMgmtInstance taskmgmtInstance = processInstance.getTaskMgmtInstance();
      Token token = processInstance.getRootToken();
      if (taskmgmtInstance.hasUnfinishedTasks(token) == false)
      {
      ...
      }
      else
      {
      ...
      }

      However, even though the start state has a task, it seems to
      enter the "if" block, not the "else" part.

      Any suggestions would be appreciated.

      Thanks,

      Debnath


        • 1. Re: Re: task in start state
          kukeltje

          please create a unit test that demonstrates the problem

          • 2. Re: task in start state
            debnathm

            Hi

            Here is the JUnit test case. Please check if the APIs have
            been used correctly

            Thanks,

            Debnath

            package org.jbpm.tutorial.startstatetask;
            
            import org.jbpm.graph.def.ProcessDefinition;
            import org.jbpm.graph.exe.ProcessInstance;
            import org.jbpm.graph.exe.Token;
            import org.jbpm.taskmgmt.exe.TaskMgmtInstance;
            
            import junit.framework.TestCase;
            
            public class StartStateTask extends TestCase {
             public void testStartStateTask() {
            
             ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
             "<process-definition> " +
             " <start-state name='start'>" +
             " <task name='StartStateTask'> " +
             " <controller> " +
             " <variable access='read,write,required' name='variable1' mapped-name='Var1'></variable> " +
             " </controller> " +
             " </task> " +
             " <transition to='task-node1' name='to_task_node1'></transition>" +
             " </start-state> " +
             " <task-node name='task-node1'> " +
             " <task name='SecondTask'>" +
             " <controller> " +
             " <variable access='read,write,required' name='variable2' mapped-name='Var2'></variable>" +
             " </controller> " +
             " </task> " +
             "<transition to='end' name='to_end'></transition>" +
             "</task-node>" +
             "<end-state name='end'></end-state>" +
             "</process-definition>");
            
             ProcessInstance processInstance =
             new ProcessInstance(processDefinition);
            
             Token token = processInstance.getRootToken();
             TaskMgmtInstance taskmgmtInstance = processInstance.getTaskMgmtInstance();
             assertEquals(true, taskmgmtInstance.hasUnfinishedTasks(token));
             }

            }


            • 3. Re: Re: task in start state
              kukeltje

              jbpm contains many unittests. If you look at the test (code below for convenience) you'll quickly see the difference

              package org.jbpm.taskmgmt.exe;
              
              import org.jbpm.graph.def.ProcessDefinition;
              import org.jbpm.graph.exe.ProcessInstance;
              
              import junit.framework.TestCase;
              
              public class StartTaskTest extends TestCase {
              
               public void testStartTaskPresent() {
               ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
               "<process-definition>" +
               " <start-state>" +
               " <task name='lets get it started' />" +
               " <transition to='going steady' />" +
               " </start-state>" +
               " <state name='going steady' />" +
               "</process-definition>"
               );
              
               ProcessInstance processInstance = new ProcessInstance(processDefinition);
              
               TaskInstance taskInstance = processInstance.getTaskMgmtInstance().createStartTaskInstance();
               assertNotNull(taskInstance);
               assertEquals("lets get it started", taskInstance.getName());
               taskInstance.end();
              
               assertEquals("going steady", processInstance.getRootToken().getNode().getName());
               }
              
               public void testStartTaskAbsent() {
               ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
               "<process-definition>" +
               " <start-state>" +
               " <transition to='going steady' />" +
               " </start-state>" +
               " <state name='going steady' />" +
               "</process-definition>"
               );
              
               ProcessInstance processInstance = new ProcessInstance(processDefinition);
              
               TaskInstance taskInstance = processInstance.getTaskMgmtInstance().createStartTaskInstance();
               assertNull(taskInstance);
               }
              
              }
              


              • 4. Re: task in start state
                debnathm

                It worked. Thanks,

                Debnath

                • 5. Re: Re: task in start state
                  kukeltje

                  you see... there is so much documentation and api examples....