`
wangyong58566
  • 浏览: 4072 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

我转一个请假流程实例的全部!及详细代码!很有代表性。

阅读更多

流程定义

<?xml version="1.0" encoding="UTF-8"?>

<process-definition
  xmlns="urn:jbpm.org:jpdl-3.1"  name="MyRequest">
   
  <start-state name="SS_Request">
      <transition name="" to="TN_WriteRequest"></transition>
   </start-state>

   <task-node name="TN_WriteRequest">
      <task name="Task_WriteRequest">
         <controller>
            <variable name="dayCount" access="read,write,required"></variable>
         </controller>
         <assignment class="com.myrequest.task.WriteRequestAssignmentHandler"></assignment>
      </task>
      <transition name="Tr_WriteLeave" to="Fork_request">
         <action name="Ac_WriteLeave" class="com.myrequest.action.WriteLeaveActionHandler"></action>
      </transition>
   </task-node>

   <fork name="Fork_request">
      <transition name="Tr_Cancel" to="TN_RequesterCancel"></transition>
      <transition name="Tr_Request" to="Deci_IsChiefHere">
         <action name="Ac_GetChiefState" class="com.myrequest.action.GetChiefStateActionHandler"></action>
      </transition>
   </fork>

   <decision name="Deci_IsChiefHere">
      <handler class="com.myrequest.decision.IsChiefHereDecisionHandler"/>
      <transition name="Tr_Chief" to="TN_ChiefDecide"></transition>
      <transition name="Tr_Boss" to="TN_BossDecide"></transition>
   </decision>

   <task-node name="TN_RequesterCancel">
      <task name="Task_CancelRequest">
         <assignment class="com.myrequest.task.CancelRequestAssignmentHandler"></assignment>
      </task>
      <transition name="Tr_RequestCancel" to="Join_Request">
         <action name="Ac_RequestCancel" class="com.myrequest.action.RequestCancelActionHandler"></action>
      </transition>

   </task-node>
   <task-node name="TN_ChiefDecide">
      <task name="Task_ChiefDecide">
         <assignment class="com.myrequest.task.ChiefDecideAssignmentHandler"></assignment>
      </task>
      <transition name="Tr_ChiefApprove" to="Deci_NeedBossDecide">
         <action name="Ac_ChiefApprove" class="com.myrequest.action.ChiefApproveActionHandler"></action>
      </transition>
      <transition name="Tr_ChiefNotApprove" to="Join_Request">
         <action name="Ac_ChiefNotApprove" class="com.myrequest.action.ChiefNotApproveActionHandler"></action>
      </transition>
   </task-node>

  <decision name="Deci_NeedBossDecide">
      <handler class="com.myrequest.decision.NeedBossDecideDecisionHandler"/>
      <transition name="Tr_Need" to="TN_BossDecide"></transition>
      <transition name="Tr_NotNeed" to="Join_Request">
         <action name="Ac_NotNeed" class="com.myrequest.action.NotNeedActionHandler"></action>
      </transition>
   </decision>

   <task-node name="TN_BossDecide">
      <task name="Task_BossDecide">
         <assignment class="com.myrequest.task.BossDecideAssignmentHandler"></assignment>
      </task>
      <transition name="Tr_BossApprove" to="Join_Request">
         <action name="Ac_BossApprove" class="com.myrequest.action.BossApproveActionHandler"></action>
      </transition>
      <transition name="Tr_BossNotApprove" to="Join_Request">
         <action name="Ac_BossNotApprove" class="com.myrequest.action.BossNotApproveActionHandler"></action>
      </transition>
   </task-node>
 <join name="Join_Request">
      <transition name="Tr_Join" to="Deci_DoSomething"></transition>
   </join>

   <decision name="Deci_DoSomething">
       <handler class="com.myrequest.decision.DoSomethingDecisionHandler"/>
      <transition name="Tr_Approve" to="ES_Finished">
         <action name="Ac_Approve" class="com.myrequest.action.ApproveActionHandler"></action>
      </transition>
      <transition name="Tr_NotApprove" to="ES_Finished">
         <action name="Ac_NotApprove" class="com.myrequest.action.NotApproveActionHandler"></action>
      </transition>

      <transition name="Tr_Cancel" to="ES_Finished">
         <action name="Ac_Cancel" class="com.myrequest.action.CancelActionHandler"></action>
      </transition>

   </decision>

   <end-state name="ES_Finished">
      <event type="node-enter">
          <action name="Ac_Finished" class="com.myrequest.action.FinishedActionHandler"></action>
      </event>
   </end-state> 
</process-definition>

下面是他的调用。。。。用JUnit 实现。分别是普通的内存数据库,和真实的数据。
下面用的是内存数据的JUNIT。。。。。

package com.myrequest;

import org.jbpm.graph.node.*;
import java.io.FileInputStream;
import java.util.*;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.taskmgmt.*;
import org.jbpm.identity.*;
import org.jbpm.context.exe.ContextInstance;
import org.jbpm.taskmgmt.exe.*;
import junit.framework.TestCase;
import com.myrequest.*;

public class ApproveActionHandler extends TestCase {
 
 ProcessDefinition pdf;
 ProcessInstance pi;
 String userId;

 boolean isChiefHere;
 public void setUp() {
  userId = "dust";
  isChiefHere = true;
 }
 
 public void test14DayAndChiefApproveAndUserCancel() throws Exception {
  this.deployProcessDefinition();
  this.createProcessInstance();
  System.out.println("+++++++++++++++++++++++++++++++++++++++");
  this.userWriteRequest(14);
  System.out.println("+++++++++++++++++++++++++++++++++++++++");
  this.chiefDecide(true);
  System.out.println("+++++++++++++++++++++++++++++++++++++++");
  this.userCancel();
  System.out.println("+++++++++++++++++++++++++++++++++++++++");
  this.checkTasks();
  System.out.println("+++++++++++++++++++++++++++++++++++++++");
 }
 /*
 public void test14DayAndBossNotApprove() throws Exception {
  this.deployProcessDefinition();
  this.createProcessInstance();
  this.userWriteRequest(14);
  this.chiefDecide(true);
  this.bossDecide(false);
  this.checkTasks();
 }
 public void test4DayAndChiefApprove() throws Exception {

  this.deployProcessDefinition();
  this.createProcessInstance();
  this.userWriteRequest(4);
  this.chiefDecide(true);
  this.checkTasks();
 }

 
 */
 protected void deployProcessDefinition() throws Exception {

  System.out.println("==MyRequestProcessTest.deployProcessDefinition()==");
  FileInputStream fis = new FileInputStream(
    "E://JAVA_PROJECT//workspace//jbpm.3//src//java.jbpm//com//myrequest//processdefinition.xml");
  pdf = ProcessDefinition.parseXmlInputStream(fis);
  assertNotNull("Definition should not be null", pdf);
 }

 protected void createProcessInstance() throws Exception {
  System.out.println("==MyRequestProcessTest.createProcessInstance()==");
  assertNotNull("Definition should not be null", pdf);
  pi = new ProcessInstance(pdf);
  assertNotNull("processInstance should not be null", pi);
  Join join_Request = (Join) pi.getProcessDefinition().getNode(
    "Join_Request");
  assertNotNull("should find join_request node !", join_Request);
  join_Request.setDiscriminator(true);
  // 设置申请人
  pi.getContextInstance().createVariable(RequestVariable.userId,
    this.userId);
  // 设置流程运行是,部门主管是否在岗
  pi.getContextInstance().createVariable(RequestVariable.isChiefHere,
    new Boolean(this.isChiefHere));
  // 启动流程
  pi.getRootToken().signal();
  System.out.println("==MyRequestProcessTest.createProcessInstance()==");
 }

 /**
  *
  * @param daycount
  *            请假天数
  *
  */

 protected void userWriteRequest(int daycount) {
  System.out.println("++++++++++++++++++++++ MyRequestProcessTest.userWriteRequest()++++++++++++++++++++++ ");
  
  TaskMgmtInstance taskMgmtInstance  =  pi.getTaskMgmtInstance();
  
  TaskInstance wr = (TaskInstance) taskMgmtInstance
    .getTaskInstances().iterator().next();
  System.out.println("++++++++++++++++++++++ MyRequestProcessTest.userWriteRequest()++++++++++++++++++++++ ");
  assertEquals(this.userId, wr.getActorId());
  System.out.println("++++++++++++++++++++++ MyRequestProcessTest.userWriteRequest()++++++++++++++++++++++ ");
  ContextInstance ci = pi.getContextInstance();
  System.out.println("++++++++++++++++++++++ MyRequestProcessTest.userWriteRequest()++++++++++++++++++++++ ");
  ci.setVariable("dayCount", new Integer(daycount));
  System.out.println("++++++++++++++++++++++ MyRequestProcessTest.userWriteRequest()++++++++++++++++++++++ ");
  wr.end();
  System.out.println("++++++++++++++++++++++ userWrite Task end ++++++++++++++++++++++");
 }

 /**
  *
  * @param isApprove
  *            部门主管是否同意请假
  *
  */

 protected void chiefDecide(boolean isApprove) {
  System.out.println("==MyRequestProcessTest.chiefDecide()==");
  // String chiefId="today123";
  /**
   *
   * 如果后台使用数据库的话,就可以使用
   *
   * org.jbpm.db.TaskMgmtSession.findTaskInstances(java.lang.String
   * actorId) 得到所有分配给chiefId的taskInstance
   *
   */
  Collection coll = pi.getTaskMgmtInstance().getTaskInstances();
  Iterator it = coll.iterator();
  while (it.hasNext()) {
   TaskInstance ti = (TaskInstance) it.next();
   if (ti.getName().equals("Task_ChiefDecide")) {
    assertEquals("today123", ti.getActorId());
    if (isApprove)
     ti.end("Tr_ChiefApprove");
    else

     ti.end("Tr_ChiefNotApprove");

    return;
   }
  }
 }
 /**
  *
  * @param isApprove
  *            老板是否同意请假
  *
  */
 protected void bossDecide(boolean isApprove) {
  System.out.println("==MyRequestProcessTest.bossDecide()==");
  // String bossId="elena";
  /**
   *
   * 如果后台使用数据库的话,就可以使用
   *
   * org.jbpm.db.TaskMgmtSession.findTaskInstances(java.lang.String
   * actorId) 得到所有分配给bossId的taskInstance
   *
   */
  Collection coll = pi.getTaskMgmtInstance().getTaskInstances();
  Iterator it = coll.iterator();

  while (it.hasNext()) {
   TaskInstance ti = (TaskInstance) it.next();
   if (ti.getName().equals("Task_BossDecide")) {
    assertEquals("elena", ti.getActorId());
    if (isApprove)
     ti.end("Tr_BossApprove");
    else
     ti.end("Tr_BossNotApprove");
    return;
   }
  }
 }

 protected void userCancel() {
  System.out.println("==MyRequestProcessTest.userCancel()==");
  /**
   *
   * 如果后台使用数据库的话,就可以使用
   *
   * org.jbpm.db.TaskMgmtSession.findTaskInstances(java.lang.String
   * actorId) 得到所有分配给userid的taskInstance
   *
   */
  Collection coll = pi.getTaskMgmtInstance().getTaskInstances();
  Iterator it = coll.iterator();

  while (it.hasNext()) {
   TaskInstance ti = (TaskInstance) it.next();
   if (ti.getName().equals("Task_CancelRequest")) {
    assertEquals(this.userId, ti.getActorId());
    ti.end();
    return;
   }
  }
 }

 protected void checkTasks() {
  System.out.println("==MyRequestProcessTest.checkTasks()==");
  Collection coll = pi.getTaskMgmtInstance().getTaskInstances();
  Iterator it = coll.iterator();
  System.out.println("====Process has task:====");

  while (it.hasNext()) {
   TaskInstance ti = (TaskInstance) it.next();
   System.out.println("==" + ti.getName() + "==");
   System.out.println("==" + ti.getActorId() + "==");
   System.out.println("==" + ti.getVariables().toString() + "==");
  }
  System.out.println("====end====");
 }

}

下面的使用的ORACLE 9 的数据库做为的后台。。。

package com.myrequest;

import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.graph.node.*;
import java.io.FileInputStream;
import java.util.*;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.taskmgmt.*;
import org.jbpm.identity.*;
import org.jbpm.context.exe.ContextInstance;
import org.jbpm.db.GraphSession;
import org.jbpm.taskmgmt.exe.*;
import junit.framework.TestCase;
import com.myrequest.*;

public class ApproveActionHandler_db extends TestCase
{
 static JbpmConfiguration jbpmConfiguration = null;

   static {
     // An example configuration file such as this can be found in
     // 'src/config.files'.  Typically the configuration information is in the
     // resource file 'jbpm.cfg.xml', but here we pass in the configuration
     // information as an XML string.
    
     // First we create a JbpmConfiguration statically.  One JbpmConfiguration
     // can be used for all threads in the system, that is why we can safely
     // make it static.

     jbpmConfiguration = JbpmConfiguration.parseXmlString(
       "<jbpm-configuration>" +
      
       // A jbpm-context mechanism separates the jbpm core
       // engine from the services that jbpm uses from
       // the environment. 
      
       "  <jbpm-context>" +
       "    <service name='persistence' " +
       "             factory='org.jbpm.persistence.db.DbPersistenceServiceFactory' />" +
       "  </jbpm-context>" +
      
       // Also all the resource files that are used by jbpm are
       // referenced from the jbpm.cfg.xml
      
       "  <string name='resource.hibernate.cfg.xml' " +
       "          value='hibernate.cfg.xml' />" +
       "  <string name='resource.business.calendar' " +
       "          value='org/jbpm/calendar/jbpm.business.calendar.properties' />" +
       "  <string name='resource.default.modules' " +
       "          value='org/jbpm/graph/def/jbpm.default.modules.properties' />" +
       "  <string name='resource.converter' " +
       "          value='org/jbpm/db/hibernate/jbpm.converter.properties' />" +
       "  <string name='resource.action.types' " +
       "          value='org/jbpm/graph/action/action.types.xml' />" +
       "  <string name='resource.node.types' " +
       "          value='org/jbpm/graph/node/node.types.xml' />" +
       "  <string name='resource.varmapping' " +
       "          value='org/jbpm/context/exe/jbpm.varmapping.xml' />" +
       "</jbpm-configuration>"
     );
   }

 boolean isChiefHere;
 String userId = "";
 long processInstant_id;
 public void setUp() {
  userId = "dust";
  isChiefHere = true;
 }

 public void test14DayAndBossNotApprove() throws Exception {
  System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  //this.deployProcessDefinition();
  System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  
  this.createProcessInstance();
  
  System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  System.out.println("----------------------------------------------------------------");
   
  this.userWriteRequest(14);
  
  System.out.println("----------------------------------------------------------------");
  System.out.println("----------------------------------------------------------------");
  System.out.println("----------------------------------------------------------------");
  System.out.println("----------------------------------------------------------------");
  System.out.println("----------------------------------------------------------------");
  System.out.println("----------------------------------------------------------------");
  System.out.println("----------------------------------------------------------------");
   
  this.chiefDecide(true);
  
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");

  
  this.bossDecide(false);
  
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");

  this.checkTasks();
  
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");
  System.out.println("****************************************************************");
  /*
  */
 }
 /*
 public void test4DayAndChiefApprove() throws Exception {

  this.deployProcessDefinition();
  this.createProcessInstance();
  this.userWriteRequest(4);
  this.chiefDecide(true);
  this.checkTasks();
 }

 public void test14DayAndChiefApproveAndUserCancel() throws Exception {
  this.deployProcessDefinition();
  this.createProcessInstance();
  this.userWriteRequest(14);
  this.chiefDecide(true);
  this.userCancel();
  this.checkTasks();
 }
 */
 protected void deployProcessDefinition() throws Exception {

  System.out.println("==MyRequestProcessTest.deployProcessDefinition()==");
  
  ProcessDefinition processDefinition = null;
  FileInputStream fis = new FileInputStream(
    "E://JAVA_PROJECT//workspace//jbpm.3//src//java.jbpm//com//myrequest//processdefinition.xml");
  processDefinition = ProcessDefinition.parseXmlInputStream(fis);
  
  
  JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
       // Deploy the process definition in the database
       jbpmContext.deployProcessDefinition(processDefinition);
       jbpmContext.close();
      
  assertNotNull("Definition should not be null", processDefinition);
  
 }

 protected void createProcessInstance() throws Exception {
  
  System.out.println("==MyRequestProcessTest.createProcessInstance()==");
  JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
     GraphSession graphSession = jbpmContext.getGraphSession(); 
     ProcessDefinition processDefinition =
     graphSession.findLatestProcessDefinition("MyRequest");    
     assertNotNull("Definition should not be null", processDefinition);
    
     ProcessInstance processInstance =
           new ProcessInstance(processDefinition);
     assertNotNull("processInstance should not be null", processInstance);
    
     this.processInstant_id = processInstance.getId();
    
    
     Join join_Request = (Join) processInstance.getProcessDefinition().getNode(
  "Join_Request");    
     assertNotNull("should find join_request node !", join_Request);
     join_Request.setDiscriminator(true);
     //   设置申请人
     processInstance.getContextInstance().createVariable(RequestVariable.userId,
    this.userId);
     processInstance.getContextInstance().createVariable(RequestVariable.isChiefHere,
    new Boolean(this.isChiefHere));
    
  // 启动流程
     processInstance.getRootToken().signal();
     jbpmContext.save(processInstance);    
     jbpmContext.close();
  /*
  System.out.println("==MyRequestProcessTest.createProcessInstance()==");
  assertNotNull("Definition should not be null", pdf);
  pi = new ProcessInstance(pdf);
  assertNotNull("processInstance should not be null", pi);
  Join join_Request = (Join) pi.getProcessDefinition().getNode(
    "Join_Request");
  assertNotNull("should find join_request node !", join_Request);
  join_Request.setDiscriminator(true);
  // 设置申请人
  pi.getContextInstance().createVariable(RequestVariable.userId,
    this.userId);
  // 设置流程运行是,部门主管是否在岗
  pi.getContextInstance().createVariable(RequestVariable.isChiefHere,
    new Boolean(this.isChiefHere));
  // 启动流程
  pi.getRootToken().signal();
  */
 }
 /**
  *
  * @param daycount
  *            请假天数
  *
  */

 protected void userWriteRequest(int daycount) {
  System.out.println("==MyRequestProcessTest.userWriteRequest()==");
  
  
  JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
     GraphSession graphSession = jbpmContext.getGraphSession();
    
     ProcessDefinition processDefinition =
     graphSession.findLatestProcessDefinition("MyRequest");
     assertNotNull("Definition should not be null", processDefinition);
    
     List processInstances =
         graphSession.findProcessInstances(processDefinition.getId());
     ProcessInstance processInstance =
         (ProcessInstance) processInstances.get(0);
     long id = processInstance.getId();
     System.out.println("processInstance id:" + id);
     assertNotNull("processInstance should not be null", processInstance);
  
     //System.out.println("processInstance:" + processInstance.getId());
         
    
     TaskMgmtInstance taskMgmtInstance = processInstance.getTaskMgmtInstance();

  System.out.println("****************************************************************");
  TaskInstance wr = (TaskInstance) taskMgmtInstance
    .getTaskInstances().iterator().next();
  System.out.println("****************************************************************");
  assertEquals(this.userId, wr.getActorId());  
  ContextInstance ci = processInstance.getContextInstance();  
  ci.setVariable("dayCount", new Integer(daycount));  
  wr.end();
  
  processInstance.signal();
  
  jbpmContext.save(processInstance);
     jbpmContext.close();
 }

 /**
  *
  * @param isApprove
  *            部门主管是否同意请假
  *
  */

 protected void chiefDecide(boolean isApprove)
 {
  System.out.println("==MyRequestProcessTest.chiefDecide()==");
  // String chiefId="today123";
  /**
   *
   * 如果后台使用数据库的话,就可以使用
   *
   * org.jbpm.db.TaskMgmtSession.findTaskInstances(java.lang.String
   * actorId) 得到所有分配给chiefId的taskInstance
   *
   */
  JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
     GraphSession graphSession = jbpmContext.getGraphSession(); 
     ProcessDefinition processDefinition =
     graphSession.findLatestProcessDefinition("MyRequest");    
     assertNotNull("Definition should not be null", processDefinition);
     List processInstances =
         graphSession.findProcessInstances(processDefinition.getId());    
     ProcessInstance processInstance =
         (ProcessInstance) processInstances.get(0);

     assertNotNull("processInstance should not be null", processInstance);
  
  Collection coll = processInstance.getTaskMgmtInstance().getTaskInstances();
  Iterator it = coll.iterator();
  while (it.hasNext()) {
   TaskInstance ti = (TaskInstance) it.next();
   if (ti.getName().equals("Task_ChiefDecide")) {
    assertEquals("today123", ti.getActorId());
    if (isApprove)
     ti.end("Tr_ChiefApprove");
    else

     ti.end("Tr_ChiefNotApprove");

    return;
   }
  }
  
  processInstance.signal();  
  jbpmContext.save(processInstance);
     jbpmContext.close();
  
 }
 
 
 /**
  *
  * @param isApprove
  *            老板是否同意请假
  *
  */
 protected void bossDecide(boolean isApprove) {
  System.out.println("==MyRequestProcessTest.bossDecide()==");
  // String bossId="elena";
  /**
   *
   * 如果后台使用数据库的话,就可以使用
   *
   * org.jbpm.db.TaskMgmtSession.findTaskInstances(java.lang.String
   * actorId) 得到所有分配给bossId的taskInstance
   *
   */
  
  JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
     GraphSession graphSession = jbpmContext.getGraphSession(); 
     ProcessDefinition processDefinition =
     graphSession.findLatestProcessDefinition("MyRequest");    
     assertNotNull("Definition should not be null", processDefinition);
         
     ProcessInstance processInstance = graphSession.getProcessInstance(this.processInstant_id);

     assertNotNull("processInstance should not be null", processInstance);
  
  
  
  Collection coll = processInstance.getTaskMgmtInstance().getTaskInstances();
  Iterator it = coll.iterator();

  while (it.hasNext()) {
   TaskInstance ti = (TaskInstance) it.next();
   if (ti.getName().equals("Task_BossDecide")) {
    assertEquals("elena", ti.getActorId());
    if (isApprove)
     ti.end("Tr_BossApprove");
    else
     ti.end("Tr_BossNotApprove");
    break;
   }
  }
  
  processInstance.signal();  
  jbpmContext.save(processInstance);
     jbpmContext.close();
 }

 protected void userCancel() {
  System.out.println("==MyRequestProcessTest.userCancel()==");
  /**
   *
   * 如果后台使用数据库的话,就可以使用
   *
   * org.jbpm.db.TaskMgmtSession.findTaskInstances(java.lang.String
   * actorId) 得到所有分配给userid的taskInstance
   *
   */
  JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
     GraphSession graphSession = jbpmContext.getGraphSession(); 
     ProcessDefinition processDefinition =
     graphSession.findLatestProcessDefinition("MyRequest");    
     assertNotNull("Definition should not be null", processDefinition);
     ProcessInstance processInstance = graphSession.getProcessInstance(this.processInstant_id);

     assertNotNull("processInstance should not be null", processInstance);
  
  
  
  Collection coll = processInstance.getTaskMgmtInstance().getTaskInstances();
  Iterator it = coll.iterator();

  while (it.hasNext()) {
   TaskInstance ti = (TaskInstance) it.next();
   if (ti.getName().equals("Task_CancelRequest")) {
    assertEquals(this.userId, ti.getActorId());
    ti.end();
    break;
   }
  }
  
  processInstance.signal();  
  jbpmContext.save(processInstance);
     jbpmContext.close();

 }

 protected void checkTasks() {
  System.out.println("==MyRequestProcessTest.checkTasks()==");
  JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
     GraphSession graphSession = jbpmContext.getGraphSession(); 
     ProcessDefinition processDefinition =
     graphSession.findLatestProcessDefinition("MyRequest");    
     assertNotNull("Definition should not be null", processDefinition);
     ProcessInstance processInstance = graphSession.getProcessInstance(this.processInstant_id);

     assertNotNull("processInstance should not be null", processInstance);
  
  
  
  Collection coll = processInstance.getTaskMgmtInstance().getTaskInstances();
  Iterator it = coll.iterator();
  System.out.println("====Process has task:====");

  while (it.hasNext()) {
   TaskInstance ti = (TaskInstance) it.next();
   System.out.println("==" + ti.getName() + "==");
   System.out.println("==" + ti.getActorId() + "==");
   System.out.println("==" + ti.getVariables().toString() + "==");
  }
  
  processInstance.signal();  
  jbpmContext.save(processInstance);
     jbpmContext.close();
  System.out.println("====end====");
 }
}


  • com.rar (92.2 KB)
  • 下载次数: 702
分享到:
评论
4 楼 godofdeath 2007-05-21  
学习ing
3 楼 yangrong 2007-05-16  
这里就没有个可以在tomcat里运行的简单的例子吗?
2 楼 rihoonet 2007-05-08  
共享区里的东西为什么我下载不了?
1 楼 wangyong58566 2007-04-16  
我的XML怎么没有上传上去啊。不过下载那里可以拿到所有的。呵呵。

相关推荐

    jbpm3.2 简单的请假流程

    在本场景中,我们关注的是jbpm3.2版本的一个简单的请假流程示例。jbpm3.2是jbpm项目早期的一个稳定版本,它提供了一个强大的框架,允许开发者创建、部署和执行业务流程。 jbpm的请假流程示例通常会展示如何通过jbpm...

    jbpm4.3学习笔记及请假流程代码

    【JBPM4.3学习笔记及请假流程代码】 JBPM(Java Business Process Management)是一个开源的工作流管理系统,它提供了一套完整的解决方案,用于管理和执行业务流程。JBPM4.3是该系统的其中一个版本,它包含了流程...

    jbpm4.4 简单请假流程

    - **工作流实例(Process Instance)**:流程定义在运行时的实体,每个实例代表一个具体的流程执行。 - **任务(Task)**:流程中的一个步骤,可以分配给一个或多个参与者执行。 - **节点(Node)**:流程图中的...

    activiti网页版实例

    用户通过Web界面启动请假流程,这通常会触发一个HTTP请求,后端代码则通过调用Activiti API的`RuntimeService`来实例化一个新的流程实例。在请假申请中,可能需要收集一些数据,这些数据可以通过表单提交并关联到...

    JBPM例子源码 PM4.3流程实例的执行 任务与事件 用户、组与Java节点

    通过API或工作流服务,我们可以控制这些实例的运行,比如启动一个新的流程实例,或者对已有的实例进行干预。 2. **任务与事件** 任务(Task)是流程实例中的一个工作单元,通常分配给特定的用户或组来完成。JBPM4...

    jbpm4.4实例

    这个实例可能包含了流程定义文件(.bpmn或.xml)、数据库脚本、配置文件以及相关的Java代码,用于展示如何启动、执行和跟踪一个请假申请流程。 请假流程通常涉及员工提交申请、经理审批等步骤,这些步骤可以通过...

    学生请假管理系统.zip

    在`studentqj`这个文件名中,"qj"可能代表“请假”,可能是包含请假申请记录的数据文件,或者是一个处理请假业务逻辑的Java类。通过这些组件,系统能实现请假申请的提交、审批、查询等功能。 总结来说,这个学生...

    jbpm5_持久化及流转流程剖析

    1. **流程实例的创建与启动**:一个流程实例代表了流程的一个具体执行过程。当启动流程时,jbpm5会创建一个新的流程实例,并将初始节点设置为当前活动节点。 2. **活动与任务**:在流程中,每个节点都代表一个活动,...

    jbpm4.3工作流程管理例子

    2. 流程实例:流程定义可以创建多个实例,每个实例代表一次流程的执行,它们各自独立,可以有不同的执行路径和状态。 3. 任务分配:jbpm4.3可以根据预设的角色或用户分配任务,也可以动态地将任务指派给特定人员。 4...

    通达OA工作流程案例及快速入门手册

    2. 流程节点:每个工作流程由多个节点组成,每个节点代表一个工作阶段,如发起、审核、批准等。 3. 节点设置:用户可指定每个节点的处理人,设定审批条件,设置处理时间限制,以及添加附加操作,如转交、退回等。 4....

    完整的源代码

    总的来说,这个压缩包提供了一个jbpm项目的实例,尤其是关于请假流程的实现,对于学习和理解jbpm的工作流管理、事务处理以及Java编程实践非常有价值。通过研究这个示例,开发者可以更好地掌握如何在实际项目中运用...

    完整状态机工作流实例

    状态机工作流则是工作流的一种类型,它基于状态转换理论,每个状态代表流程中的一个阶段,而转换则是从一个状态到另一个状态的条件或事件触发的动作。 在“推荐]状态机工作流_实列_报销审批流程 - WF应用 - WF工作...

    JBPM流程框架源码

    - **流程实例**:每个流程定义在运行时都会产生一个或多个实例,代表实际的流程执行过程。 - **工作项(Task)**:任务节点在流程实例中的具体表现,可能分配给个人或角色执行。 - **变量**:用于存储流程运行...

    JBPM用户指南[中文]+实例

    提供的入门实例可能是通过创建一个简单的业务流程,如请假申请流程,演示如何定义流程、启动实例、分配任务、审批流程,并最终完成流程。实例会覆盖从建模到执行的全过程,让学习者能够亲手实践,加深理解。 **6. ...

    画流程图的例子(源码)OsWorkFlow.rar

    例如,一个简单的请假流程可能包含“申请”、“审批”和“反馈”三个节点,每个节点代表一个任务,转移则表示任务间的顺序或条件关系。OsWorkFlow的源码中包含了对这些XML配置的解析和执行逻辑,这为我们提供了极大...

    JBPM-学生管理系统

    - **创建KieSession**: KieSession是JBPM的核心接口,它代表了一个运行时环境,可以创建、启动和管理流程实例。 - **加载流程定义**: 使用KieServices加载.bpmn2文件,并将其转换为ProcessDefinition。 - **部署...

    snaker实现的工作流

    以一个请假审批流程为例,员工提交请假申请后,流程引擎会自动创建流程实例,分配审批任务给上级。上级完成审批后,流程继续流转至下一审批人,直至流程结束。在整个过程中,Snaker负责跟踪流程状态,确保任务的正确...

Global site tag (gtag.js) - Google Analytics