jBPM 4の休暇取得フロー例

6124 ワード

最近プロジェクトにワークフローが必要なので、ワークフローエンジンとしてjBPM 4を採用する予定です.
接触し始めたばかりで、多くのものが一歩一歩模索されてきたので、もちろん、いくつかの文章も検索しました.以下はこの2日間jBPM 4を使って休暇を取った例です.
プロセスは比較的簡単で、フローチャートは以下の通りです.
そもそも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     <[email protected]>
 * @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);
		}
	}

}

では、詳細なソースコードを確認するには、私がアップロードした圧縮パッケージをダウンロードしましょう.
tomcat 6を使用するとjavaが表示されます.lang.LinkageErrorというエラーは、参考になります
http://blog.csdn.net/ol_beta/article/details/5553473という文章です.
JBPMのjarパッケージを忘れずに追加してくださいね