jbpm4.4项目测试源码下载,效果图

来源:互联网 发布:linux ll命令结果显示 编辑:程序博客网 时间:2024/04/29 10:15

关于如何配置请到网上找相关资料,

jbpm4.4项目测试源码下载, 注释都在代码里!

下载地址:http://download.csdn.net/detail/liangrui1988/6303585

里面只加了struts2,没有用到spring,用的太多反而不好理解!本来也不想用strtus2的,但那样做起来太麻烦........


效果图:

junit测试代码:

package com.accp.test2;import java.util.HashMap;import java.util.List;import java.util.Map;import org.jbpm.api.Configuration;import org.jbpm.api.ExecutionService;import org.jbpm.api.ProcessEngine;import org.jbpm.api.task.Task;import org.junit.Test;public class Qingjia {//创建表@Testpublic void createTable(){new org.hibernate.cfg.Configuration().configure("jbpm.hibernate.cfg.xml");}//加载文件ProcessEngine pe=new Configuration().setResource("jbpm.cfg.xml").buildProcessEngine();//ProcessEngine pe=Configuration.getProcessEngine();//部署资源流程@Testpublic void deploye(){pe.getRepositoryService().createDeployment().addResourceFromClasspath("leave.jpdl.xml").deploy();}//启动流程@Testpublic void startProcess(){//参数Map map=new HashMap();map.put("owner","张三");map.put("day", 1);ExecutionService executionService=pe.getExecutionService();executionService.startProcessInstanceByKey("leave",map);}//查询任务@Testpublic void findTask(){String userID="张三"; //要查询任务的用户名字System.out.println(userID);List<Task> listTask=pe.getTaskService().findPersonalTasks(userID);for(Task t:listTask){System.out.println("TaskID: "+t.getId());//int day=(Integer) pe.getTaskService().getVariable(taskID,"day");   }}//完成任务@Testpublic void completeTask(){//String  taskID="10004";//任务idString  taskID="70004";//任务idMap map=new HashMap();map.put("owner","张三");map.put("manager","李经理");map.put("boss", "王老板");//pe.getTaskService().completeTask(taskID,map);//得到上一步传过来的值int day=(Integer) pe.getTaskService().getVariable(taskID,"day");map.put("day", day);//map.put("day", -1);//传入值pe.getTaskService().setVariables(taskID, map);pe.getTaskService().completeTask(taskID);//完成任务}}


主要action代码:

package com.accp.action;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.zip.ZipInputStream;import org.apache.commons.io.FileUtils;import org.apache.struts2.ServletActionContext;import org.jbpm.api.Configuration;import org.jbpm.api.ProcessDefinition;import org.jbpm.api.ProcessEngine;import org.jbpm.api.ProcessInstance;import org.jbpm.api.TaskService;import org.jbpm.api.history.HistoryProcessInstance;import org.jbpm.api.task.Task;import com.accp.bean.User;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;import com.opensymphony.xwork2.Preparable;public class JbpmManger extends ActionSupport implements Preparable{// 流程定义集合private List<ProcessDefinition> processDefinitionList;// 流程实例集合private List<ProcessInstance> procesInstanceList;// 流程参数集合private Map<String, Object> map;// 历史流程private List<HistoryProcessInstance> historyProcessInstanceList;// 当前用户任务集合private List<Task> tasks;//加载jbpm.xml文件  得到工作流引擎private ProcessEngine processEngine;////private User user;public ProcessEngine getProcessEngine() {//processEngine=new Configuration().setResource("jbpm.cfg.xml").buildProcessEngine();processEngine=Configuration.getProcessEngine();return processEngine;}public void setProcessEngine(ProcessEngine processEngine) {this.processEngine = processEngine;}public List<ProcessDefinition> getProcessDefinitionList() {//流程定义集合processDefinitionList=processEngine.getRepositoryService().createProcessDefinitionQuery().list();return processDefinitionList;}public void setProcessDefinitionList(List<ProcessDefinition> processDefinitionList) {this.processDefinitionList = processDefinitionList;}public List<ProcessInstance> getProcesInstanceList() {//流程实列集合procesInstanceList=processEngine.getExecutionService().createProcessInstanceQuery().list();return procesInstanceList;}public void setProcesInstanceList(List<ProcessInstance> procesInstanceList) {this.procesInstanceList = procesInstanceList;}public List<HistoryProcessInstance> getHistoryProcessInstanceList() {    //历史记录historyProcessInstanceList=processEngine.getHistoryService().createHistoryProcessInstanceQuery().list();return historyProcessInstanceList;}public void setHistoryProcessInstanceList(List<HistoryProcessInstance> historyProcessInstanceList) {this.historyProcessInstanceList = historyProcessInstanceList;}public List<Task> getTasks() {//通过用户 获取工作列表System.out.println("actionUserName"+actionUserName);List<Task> listTask=processEngine.getTaskService().findPersonalTasks(actionUserName);for(Task t:listTask){System.out.println("TaskID: "+t.getId()  +"  "+t.getActivityName()+"t "+t.getAssignee());}return listTask;}public void setTasks(List<Task> tasks) {this.tasks = tasks;}//初如化action  这里暂不用spring 本来连struts也不想用的,但写在servlet实在太烦锁了    为了更好理解jbpm的动行原理========================================================================private String actionUserName;private String actionRole;public void prepare() throws Exception {getProcessEngine(); actionUserName=(String) ServletActionContext.getRequest().getSession().getAttribute("username");if("".equals(actionUserName)||null==actionUserName){returnIndex();//如果没有用户则返回} actionRole=(String) ServletActionContext.getRequest().getSession().getAttribute("role");}//如果没有登陆则返回public String returnIndex(){return "showIndex";}//初如化数据库表========================================================================================public String initDB() throws Exception {new org.hibernate.cfg.Configuration().configure("jbpm.hibernate.cfg.xml");return "showIndex";}//直接 部署流程========================================================================================public String deployeJbpm() throws Exception {processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("leave.jpdl.xml").deploy();return "showIndex";}//ZIP方式 部署流程========================================================================================private File fileJbpmZip;//接收上传的文件private String fileJbpmZipFileName;//自动获取文件名称private String fileJbpmZipContentType;//文件内型private String saveDir;//需要保存的文件目录文件夹public void setSaveDir(String saveDir) {this.saveDir = saveDir;}public void setFileJbpmZipFileName(String fileJbpmZipFileName) {this.fileJbpmZipFileName = fileJbpmZipFileName;}public void setFileJbpmZipContentType(String fileJbpmZipContentType) {this.fileJbpmZipContentType = fileJbpmZipContentType;}public void setFileJbpmZip(File fileJbpmZip) {this.fileJbpmZip = fileJbpmZip;}//ZIP方式 部署流程========================================================================================public String deployeJbpmZIP() /*throws Exception*/ {public String deployeJbpmZIP() /*throws Exception*/ { String filePath=""; //服务器目录+文件夹的目录+/+文件名 filePath=ServletActionContext.getServletContext().getRealPath(saveDir)+File.separator+fileJbpmZipFileName;    //通过文件路径创建File对象 System.out.println("filePath:  "+filePath);File fileUpload=new File(filePath);//拷贝文件 上传的File拷贝到新创建的Filetry {FileUtils.copyFile(fileJbpmZip, fileUpload);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}//创建zipInputStream文件  通过fileInputStream文件输出流ZipInputStream zis=null;try {zis=new ZipInputStream(new FileInputStream(filePath));} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}//部署文件ZipprocessEngine=Configuration.getProcessEngine();processEngine.getRepositoryService().createDeployment().addResourcesFromZipInputStream(zis).deploy();return "showIndex";}//ZIP方式 部署固定文件 流程=======================================================================================public String deployeJbpmZIP() /*throws Exception*/ {public String deployeJbpmZIPs() throws Exception { //String filePath=ServletActionContext.getServletContext().getRealPath(saveDir)+File.separator+"leave.jpdl.zip";//创建zipInputStream文件  通过fileInputStream文件输出流 new FileInputStream(filePath)   ZipInputStream zis=new ZipInputStream(this.getClass().getResourceAsStream("/leave.zip"));//部署文件ZipprocessEngine=Configuration.getProcessEngine();processEngine.getRepositoryService().createDeployment().addResourcesFromZipInputStream(zis).deploy();return "showIndex";}//remove流程定义=========================================================================private String definitionID;//流程实列idpublic void setDefinitionID(String definitionID) {this.definitionID = definitionID;}public String removeDeployeJbpm()throws Exception {processEngine.getRepositoryService().deleteDeploymentCascade(definitionID);return "showIndex";}//用户登陆==========================================================================  /*  public String userLogin(){String manager="manager,admin,zhang";String boss="boss,song";    if("".equals(user.getUsername())||user.getUsername()==null){     return "plassLogin";    }else if(manager.contains(user.getUsername())){        //经理登陆    user.setRole("manager");}else if(boss.contains(user.getUsername())){user.setRole("boss");}else{user.setRole("user");}        return "showIndex";    }*/ //填写申请单==========================================================================private int day;private String message;public String getMessage() {return message;}public int getDay() {return day;}public void setDay(int day) {this.day = day;}public String  empAddLeave() throws Exception {//角色员工的参数操作String role=(String) ServletActionContext.getRequest().getSession().getAttribute("role");String username=(String) ServletActionContext.getRequest().getSession().getAttribute("username");Map map=new HashMap();if(0>=day){message="请正确填写天数!";//System.out.println("请填写天数!");return "showIndex";}map.put("owner",username);//获取经理,老板 需要用到sql 这里省略map.put("manager","李经理");//部门经理map.put("boss","王老板");//老板map.put("day",day);processEngine.getExecutionService().startProcessInstanceByKey("leave",map);return "showIndex";}//提交请假单complete==========================================================================private String taskId;private String flog;//用于判断是审批还是驳回public void setFlog(String flog) {this.flog = flog;}public void setTaskId(String taskId) {this.taskId = taskId;}public String getTaskId() {return taskId;}//经理操作public String  empCompleteLeave() throws Exception {TaskService taskService=processEngine.getTaskService();Map map=new HashMap();map.put(actionRole,actionUserName);//传入参数taskService.setVariables(taskId, map);flog=new String(flog.getBytes("ISO-8859-1"),"utf-8");if("to 填写申请单".equals(flog)){//提交请假任务taskService.completeTask(taskId,"to 经理审批");}else if("驳回".equals(flog)){//经理驳回taskService.completeTask(taskId,"驳回");}else if("to exclusive1".equals(flog)){//经理批准taskService.completeTask(taskId,"to exclusive1");}if("to end1".equals(flog)){//老板批准taskService.completeTask(taskId,"to end1");}return "showIndex";}//显示修改请假单==========================================================================public String empUpdateLeave() throws Exception {//根据任务id和变量名获取值    Object getDay= processEngine.getTaskService().getVariable(taskId,"day");day=Integer.parseInt(getDay.toString());return "updateJsp";}//修改请假单提交==========================================================================public String updateLeaveOk() throws Exception {//角色员工的参数操作String role=(String) ServletActionContext.getRequest().getSession().getAttribute("role");String username=(String) ServletActionContext.getRequest().getSession().getAttribute("username");Map map=new HashMap();if(0>=day){message="请正确填写天数!";//System.out.println("请填写天数!");return "updateJsp";}map.put("owner",username);//获取经理,老板 需要用到sql 这里省略map.put("manager","李经理");//部门经理map.put("boss","王老板");//老板map.put("day",day);//processEngine.getExecutionService().startProcessInstanceByKey("leave",map);processEngine.getTaskService().setVariables(taskId, map);return "showIndex";}}


原创粉丝点击