`
ioio
  • 浏览: 142415 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

jbpm example

阅读更多


===========工作流程=======================================================================================
<?xml version="1.0" encoding="UTF-8"?>

<process-definition
  xmlns=""  name="exceptionReporter">
   <start-state name="開始">
      <transition name="to_report" to="呈報考勤異常">
         <action name="start_report" class="com.ccc.handler.StartReprotExceptionActionHandler"></action>
      </transition>
   </start-state>
   <task-node name="課級主管審核">
      <task name="submit_exception">
       <assignment class="com.ccc.handler.AttendanceExceptionCheckAssignmentHandler"></assignment>
      </task>     
      <transition name="to_confirm" to="高階主管審核">
       <assignment class="com.ccc.handler.AttendanceExceptionCheckAssignmentHandler"></assignment>
      </transition>
      <transition name="to_reapply" to="呈報考勤異常">
    
      </transition>
   </task-node>
   <task-node name="高階主管審核">
 <task name="to_summit">  
  <assignment class="com.ccc.handler.AttendanceExceptionCheckAssignmentHandler"></assignment> 
 </task>
      <transition name="to_finish" to="結束">
      <!-- 結束任務 -->
     
      </transition>
      <transition name="to_recofirm" to="課級主管審核">
      <!-- 退給課級主管 -->
      <assignment class="com.ccc.handler.AttendanceExceptionCheckAssignmentHandler"></assignment>
      </transition>
   </task-node>
   <end-state name="結束"></end-state>
   <task-node name="呈報考勤異常">
      <task name="report_exception">
      <assignment actor-id="#{initiator}"></assignment>
      </task>
      <transition name="to_apply" to="課級主管審核"></transition>
   </task-node>
</process-definition>

==================================發起流程================================================================
 public JbpmContext doJbpmAction(final String employeeId, final String empNo,
   final String empName,final String formId)
   throws Exception {
  return (JbpmContext)jbpmTemplate.execute(new JbpmCallback() {
   @SuppressWarnings("unchecked")
   public Object doInJbpm(JbpmContext jbpmContext) throws JbpmException {
   try {
    
    //取得考勤異常提報的流程定義
    ProcessDefinition process = processDefinitionManager.getLastestProcessDefinition("exceptionReporter");
    ProcessInstance processinstance = new ProcessInstance(process);
    //流程發起者
    processinstance.getContextInstance().setVariable("initiator",employeeId);
    //開啟流程
    jbpmContext.save(processinstance);
    //同時完成下個個流程 ,對該任務進行指派
    processinstance.signal("to_report");
    jbpmTemplate.getHibernateTemplate().flush();
    //記錄該任務相關信息
    List<TaskInstance> taskInstances = (List<TaskInstance>)jbpmContext.getTaskList(employeeId);
    //
    //查找該提報人所在的課級組織信息
     CommOrganizationInfo org1 =baseManager.findOrganizationInfoByEmployeeIdAndOrgLevel(Long.valueOf(employeeId),HrConstant.COMM_ORGANIZATION_LEVEL_CLASS);
     //查找該員工課級主管信息

    List<CommEmployeeInfo> list = organizationManager.getParentCommOrganizationInfoMasterByOrganizationId(org1.getOrganizationId());
    if(taskInstances!=null){
     try{
     for (TaskInstance ti : taskInstances) {  
      if(ti.getName().equals("report_exception")){
         ContextInstance ci = ti.getContextInstance();
      //表單id
      ci.setVariable("requestId",formId);
      ci.setVariable("empName",empName);
      ci.setVariable("employeeId",employeeId);
      ci.setVariable("empNo", empNo);
      ci.setVariable("managerList", list);
      ti.end();
      jbpmContext.save(ti);
      }
      
     }
     }catch(Exception e)
     {
      e.printStackTrace();
     }
    }  
   }catch(JbpmException e1){ 
    e1.printStackTrace();
    throw e1;
   }catch(Exception e2){
    e2.printStackTrace();
   }finally{
    jbpmTemplate.getHibernateTemplate().flush();
   } 
    
    
    return jbpmContext;
   }

  });
  
 }
===================================第一步審核==========================================================================
public boolean submitExceptionHanele(final String empNo, final String taskId,
   final String operatorFlag, final long employeeId,final CommEmployeeInfo commitEmp) throws Exception {

  return (Boolean) jbpmTemplate.execute(new JbpmCallback() {
   public Boolean doInJbpm(JbpmContext jbpmContext)
     throws JbpmException {
    try{
     TaskInstance ti = jbpmContext.getTaskInstance(Long.parseLong(taskId));
     if (operatorFlag.equals("pass")) { 
      try{
      //查找該審核人所在的處級組織信息
       CommOrganizationInfo org1 =baseManager.findOrganizationInfoByEmployeeIdAndOrgLevel(Long.valueOf(employeeId),HrConstant.COMM_ORGANIZATION_LEVEL_SECTION);
      //查找該員工高階主管信息
      List<CommEmployeeInfo> list = organizationManager.getParentCommOrganizationInfoMasterByOrganizationId(org1.getOrganizationId());
      ContextInstance ci = ti.getContextInstance();
      //表單id
      ci.setVariable("formId", ti.getVariable("requestId"));
      //審核人工號
      ci.setVariable("empNo", empNo);
      ci.setVariable("empName", ti.getVariable("empName"));
      ci.setVariable("employeeId", employeeId);
      ci.setVariable("managerList", list);
      ti.end("to_confirm");
      jbpmContext.save(ti);
      }catch(Exception e1)
      {
       e1.printStackTrace();
      }
      jbpmTemplate.getHibernateTemplate().flush();
     } else {    
      //執行退回動作
      //ContextInstance ci = ti.getContextInstance();
      //ci.setVariable("formId", ti.getVariable("requestId"));
      //ci.setVariable("empNo", empNo);
      //ci.setVariable("empName", ti.getVariable("empName"));
      //ci.setVariable("employeeId", employeeId);
      //ArrayList<CommEmployeeInfo> alist =new ArrayList<CommEmployeeInfo>();
      //alist.add(commitEmp); 
      //ci.setVariable("initiator", String.valueOf(commitEmp.getEmployeeId()));
      //jbpmTemplate.getHibernateTemplate().flush();
      ti.end("to_reapply");
      jbpmTemplate.getHibernateTemplate().flush();
      jbpmContext.save(ti);
     }
    }catch(Exception e2)
    {
     e2.printStackTrace();
    }
    return true;
   }
  });
 
 }
===================================第二步審核=======================================================================
public boolean confirmExceptionHanele(final String empNo,final String taskId,
   final String operatorFlag, final long employeeId) throws Exception {
  return (Boolean) jbpmTemplate.execute(new JbpmCallback() {
   public Boolean doInJbpm(JbpmContext jbpmContext)
     throws JbpmException {
    try{
     TaskInstance ti = jbpmContext.getTaskInstance(Long.parseLong(taskId));
     if (operatorFlag.equals("pass")) { 
      try{
      ContextInstance ci = ti.getContextInstance();
      //表單id
      ci.setVariable("formId", ti.getVariable("requestId"));
      //審核人工號
      ci.setVariable("empNo", empNo);
      ci.setVariable("empName", ti.getVariable("empName"));
      ci.setVariable("employeeId", employeeId);
      ti.end("to_finish");
      jbpmContext.save(ti);
      }catch(Exception e1)
      {
       e1.printStackTrace();
      }
      jbpmTemplate.getHibernateTemplate().flush();
     } else { 
      //重新給課級主管指派任務
      //查找該異常人所在高階主管____課級主管
       //CommOrganizationInfo org1 =baseManager.findOrganizationInfoByEmployeeIdAndOrgLevel(Long.valueOf(employeeId),HrConstant.COMM_ORGANIZATION_LEVEL_CLASS);
       //查找該員工課級主管信息
      //List<CommEmployeeInfo> list = organizationManager.getParentCommOrganizationInfoMasterByOrganizationId(org1.getOrganizationId());
      try{
//       ContextInstance ci = ti.getContextInstance();
//       //表單id
//       ci.setVariable("formId", ti.getVariable("requestId"));
//       //審核人工號
//       ci.setVariable("empNo", empNo);
//       ci.setVariable("empName", ti.getVariable("empName"));
//       ci.setVariable("employeeId", employeeId);
//       ci.setVariable("managerList", list);
       ti.end("to_recofirm");
       jbpmContext.save(ti);
       jbpmTemplate.getHibernateTemplate().flush();
       }catch(Exception e1)
       {
        e1.printStackTrace();
       }
       jbpmTemplate.getHibernateTemplate().flush();
     }
    }catch(Exception e2)
    {
     e2.printStackTrace();
    }
    return true;
   }
  });
 }
=============================================任務指派1=============================================================
package com.ccc.handler;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.exe.ExecutionContext;

import com.ccc.module.jbpm.handlers.MESActionHandlerManager;

public class StartReprotExceptionActionHandler extends MESActionHandlerManager{
 private transient final Log logger = LogFactory.getLog(StartReprotExceptionActionHandler.class);

 private static final long serialVersionUID = -7703930993012075081L;
 /**
  * 流程開始
  * @author F1632506
  * @date May 8, 2009 9:42:41 AM
  * @param param1
  * @see com.ccc.module.jbpm.empenter.action[#method([execute])]
  * @throws exceptionType
  *             如果...將拋出exceptionType異常.
  * @return returnType 返回類型描述
  */
 public void execute(ExecutionContext executionContext) throws Exception { 
  ContextInstance ci = executionContext.getContextInstance();
  String user = (String)ci.getVariable("initiator"); 
  logger.info(new Date()+user+"發起考勤異常提報流程..");
 }
}


==========
package com.ccc.handler;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.taskmgmt.def.AssignmentHandler;
import org.jbpm.taskmgmt.exe.Assignable;
import org.springmodules.workflow.jbpm31.JbpmTemplate;

import com.ccc.module.jbpm.empenter.assignment.NewEmpAssignmentHandler;

 

public class AttendanceExceptionAssignmentHandler implements AssignmentHandler
{
 @SuppressWarnings("unused")
 private JbpmTemplate jbpmTemplate;
 @SuppressWarnings("unused")
 private String actor; 
 private transient final Log logger = LogFactory.getLog(NewEmpAssignmentHandler.class);
 private static final long serialVersionUID = 8742291098601946988L;

 
 /**
  * 把所以當日考勤信息的提報任務指派給發起人
  * <p>
  *
  * @author Daniel
  * @date Jun 10, 2009 3:34:19 PM
  * @param assignable
  *            type  public void assign(Assignable
  * @param executionContext
  *            type ExecutionContext
  *            <ul>
  *            <li>jbpm中定義的Assignable
  *            <li>jbpm中定義的ExecutionContext
  *            </ul>
  * @throws exceptionType
  *             如果...將拋出exceptionType異常.
  * @return void
  */
 
 public void assign(Assignable assignable, ExecutionContext executionContext) throws Exception {
  ContextInstance ci = executionContext.getContextInstance();  
  String user = (String)ci.getVariable("initiator");  
  assignable.setActorId(user);
  
 }
 public void setActor(String actor) {
  this.actor = actor;
 }
 
 
 public void setJbpmTemplate(JbpmTemplate jbpmTemplate) {
  this.jbpmTemplate = jbpmTemplate;
 }
}
==========================================任務指派2=======================================================
package com.ccc.handler;
import java.util.List;

import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.taskmgmt.exe.Assignable;

import com.ccc.model.user.CommEmployeeInfo;
import com.ccc.module.jbpm.handlers.MESAssignmentHandlerManager;
public class AttendanceExceptionCheckAssignmentHandler  extends MESAssignmentHandlerManager
{
 private static final long serialVersionUID = 8067830912869790490L;;
 @SuppressWarnings("unchecked")
 public void assign(Assignable assignable, ExecutionContext executionContext) throws Exception {
  String temp[]=null;
  //取得上下文實例
  ContextInstance context = executionContext.getContextInstance();
  //獲取相應的部分主管
  List<CommEmployeeInfo> list = (List<CommEmployeeInfo>)context.getVariable("managerList"); 
  if(list!=null && list.size()>0)
  {
   int i=0;
   temp=new String[list.size()];
   for(CommEmployeeInfo employee:list)
   {
    
    temp[i++]=employee.getEmployeeId().toString();
    
   }
  }
   try{
   assignable.setPooledActors(temp);
   }catch(Exception e)
   {
    e.printStackTrace();
   } 
 }
}
===========================================end============================================================

 

分享到:
评论

相关推荐

    Spring-Jbpm-JSF-Example.pdf

    根据给定的文件信息,我们可以总结出以下关于“Spring-Jbpm-JSF-Example”的关键IT知识点: ### 1. **项目概述** 标题与描述提到的“Spring-Jbpm-JSF-Example.pdf”是一个示例项目,展示了如何将Spring框架、Jbpm...

    jbpm7示例(jbpm-7.3.0.Final-examples)

    2017年jBPM 正式发布了全新的 7版本。jBPM 是一个完全开源的业务流程管理(BPM)和案例管理解决方案。它支持流程和案例的完整生命周期,从编写工具到执行一直到监控和管理。 在核心引擎之上,提供了许多功能和工具来...

    jbpm学习笔记.docx

    jbpm学习笔记主要涵盖了jbpm(Java Business Process Management)的多个方面,包括Signavio的使用和配置、jBPM数据库的安装、Graphical ...同时,通过阅读和分析example项目,可以更好地理解和应用jBPM的实际操作。

    JBPM的使用与简单的操作

    把JBoss安装到${jbpm.home}/jboss-5.0.0... 从${jbpm.home}/install/src/demo/example.identities.sql,读取用户和组。 安装eclipse到${jbpm.home}/eclipse 启动eclipse 安装jBPM web控制台 安装Signavio web建模器

    jbpm jar java

    ProcessInstance processInstance = ksession.startProcess("com.example.myProcess"); // 处理任务 TaskService taskService = ksession.getTaskService(); List&lt;TaskSummary&gt; tasks = taskService....

    jbpm4.2开发文档

    ### jbpm4.2开发知识点概述 #### 一、jbpm简介 - **定义与特点**:jbpm(Java Business Process Model)是一个开源的工作流引擎,用于自动化业务流程的执行。它提供了一种灵活的方式来定义复杂的业务流程,并通过...

    jBPM4.4 安装在Tomcat+MySql环境

    - `ant load.example.identities`:加载示例用户和用户组数据到MySQL数据库。 - `ant install.signavio.into.tomcat`:将Signavio模型设计器安装到Tomcat。 - `ant install.eclipse`:解压`JBPM_HOME\install\...

    jbpm jpdl 帮助文档pdf版

    根据提供的文件信息,我们可以深入探讨jbpm jpdl帮助文档中的关键知识点。该文档主要围绕jBPM(一款开源的工作流引擎)以及其图形化过程设计语言jpdl进行介绍。接下来,我们将按照文档的大纲顺序来解析各个部分所...

    jbpm5example:jBPM5示例项目

    jbpm5example jBPM5示例项目当前,这些项目集中在JBoss BRMS 5.3.0上。 我可能会为其他版本添加一些分支(例如jBPM 5.3.0)BRMS 5.3.0存储库设置由于JBoss BRMS 5.3.0库不在公共存储库中托管,因此请按照以下步骤将...

    jbpm5第一个例子

    http://www.mastertheboss.com/jbpm5/jbpm-5-tutorial-first-example 一般不会的问题,从官方找就行,但上面说的也不详细,结果搞了一天也没通,后来把条件直接换成 true就行了,也不用什么return money&gt;1000了。 ...

    jbpm4.4的安装myeclipse配置还有helloworld实例

    - 运行 `ant load.example.identities` 命令来加载示例用户和用户组数据到 MySQL 数据库。 - **测试**: - 启动 Tomcat 服务器。 - 在浏览器中访问 `http://localhost:8080/jbpm-console`,如果页面正常显示,则...

    JBPM4.3使用说明.doc

    其中,doc 目录包含了用户指南和开发指南,Example 目录提供了 JBPM 自带的示例,Install 目录是安装目录,lib 目录包含了 JBPM 所有依赖包,Migration 目录用于 JBPM3 到 jbpm4.3 的回退升级,Src 目录包含了 JBPM...

    jbpm5.3各种例子

    在【jbpm5example-master】这个压缩包中,可能包含了以下类型的示例: 1. **基本流程示例**:这些示例展示了如何创建简单的开始事件到结束事件的流程,以及如何在流程中添加任务、网关等元素。 2. **用户任务示例*...

    spring3.0 整合jbpm4.3请假demo

    修改配置文件的数据库连接部分就可以直接运行,由于文件过大,没有上传jar包,需要自己加入。将juel.jar 替换tomcat下的D:\Application\...浏览器输入:http://localhost:8080/Spring3Jbpm/example/login/login.html

    jbpm-services-example:jBPM Serivces API示例

    jBPM Services REST项目该项目的目的是展示如何轻松地将jBPM服务api(带有ejb实现)用于在Java EE应用程序中嵌入jBPM。去做说明必要的组件(持久性单元,用户组回调机制) 我们是否需要此项目中的自定义回调或仅需要...

    JBPM安装指南

    - `ant load.example.identities` - `ant start.tomcat` 这些命令会完成JBPM的部署,启动数据库服务,创建JBPM所需的数据库架构,安装示例项目,并启动Tomcat服务器。 最后,验证JBPM的安装: 1. **访问控制台*...

Global site tag (gtag.js) - Google Analytics