jBPM4之请假流程例子

最近项目需要工作流,所以就准备采用jBPM4作为工作流引擎,
才开始接触,很多东西都是一步一步摸索出来的,当然了,也搜索了一些文章,下面就是这两天使用jBPM4做的一个请假的例子.
流程比较简单,流程图如下:[img]http://dl.iteye.com/upload/picture/pic/113109/43d132a2-e743-3cef-a5f1-27d1977a219c.jpg[/img]
本来作为才开始学习JBPM的人来说,最好的方法就是先运行起程序,然后学习就要方便很多。
下面是我的servlet文件;

package com.vito.jbpm.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.jbpm.api.Configuration;
import org.jbpm.api.Execution;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.RepositoryService;
import org.jbpm.api.TaskService;
import org.jbpm.api.model.ActivityCoordinates;
import org.jbpm.api.task.Task;
/**
* 请假流程Servlet
* @author 周文滔 <zhouwentao16@gmail.com>
* @time 2012-5-27 下午05:39:32
*/
public class LeaveServlet extends HttpServlet {
private ProcessEngine processEngine = null;
private RepositoryService repositoryService = null;
private ExecutionService executionService = null;
private ProcessInstance processInstance = null;
private TaskService taskService = null;

public LeaveServlet() {
super();
}

public void init(ServletConfig config) throws ServletException {
super.init(config);
// 获取流程引擎
processEngine = new Configuration().buildProcessEngine();
repositoryService = processEngine.getRepositoryService();
executionService = processEngine.getExecutionService();
taskService = processEngine.getTaskService();
}

public void destroy() {
super.destroy(); // Just puts "destroy" string in log
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
process(request, response);
}

protected void process(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String action = request.getParameter("action");
HttpSession session = request.getSession();
if (action.equals("leave")) {
request.getRequestDispatcher("").forward(request, response);
} else if (action.equals("list")) {
String username = (String) session.getAttribute("username");
List<ProcessDefinition> pdList = repositoryService
.createProcessDefinitionQuery().list();
List<ProcessInstance> piList = executionService
.createProcessInstanceQuery().list();
List<Task> taskList = taskService.findPersonalTasks(username);
session.setAttribute("pdList", pdList);
session.setAttribute("piList", piList);
session.setAttribute("taskList", taskList);
request.getRequestDispatcher("list.jsp").forward(request, response);
}else if (action.equals("start")) {
Map map = new HashMap();
map.put("user",session.getAttribute("username"));
executionService.startProcessInstanceById(request.getParameter("id"),map);
request.getRequestDispatcher("leave?action=list").forward(request, response);
}else if (action.equals("submit")) {
String taskId = request.getParameter("taskId");
int day = Integer.parseInt(request.getParameter("day"));
String reason = request.getParameter("reason");
reason = new String(reason.getBytes("ISO-8859-1"),"UTF-8");
Map map = new HashMap();
map.put("days", day);
map.put("reason", reason);
taskService.completeTask(taskId, "to_teacher",map);
request.getRequestDispatcher("leave?action=list").forward(request, response);
}else if (action.equals("view")) {
String id = request.getParameter("id");
processInstance = executionService.findProcessInstanceById(id);
Set<String> activityNames = processInstance.findActiveActivityNames();
ActivityCoordinates ac = repositoryService.getActivityCoordinates(processInstance.getProcessDefinitionId(),activityNames.iterator().next());
request.setAttribute("ac", ac);
request.getRequestDispatcher("view.jsp").forward(request, response);
}else if (action.equals("deploy")) {
repositoryService.createDeployment().addResourceFromClasspath("leave.jpdl.xml").deploy();
}else if(action.equals("sh")){
String taskId = request.getParameter("taskId");
String result = request.getParameter("result");
result = new String(result.getBytes("ISO-8859-1"), "UTF-8");
System.out.println(result);
taskService.completeTask(taskId, result);
request.getRequestDispatcher("leave?action=list").forward(request, response);
}
}

}

好了,要想查看详细的源码,下载我上传的压缩包吧。
如果你使用的tomcat6, 出现java.lang.LinkageError这个错误的话,那么可以参考[url]http://blog.csdn.net/ol_beta/article/details/5553473[/url]这个文章。

还有不要忘记添加JBPM的jar包哦
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值