1.BPMN 业务流程建模标注 详细介绍请看
http://www.uml.org.cn/RequirementProject/200904141.asp
2.BPMN是OMG推出的一种工作流建模的标准。还有JBoss自己搞的Jbpm,但jbpm不是标准。
3.BPMN的资料不多,设计器设计出来的BPMN很多不是标准的BPMN2.0.如果eclipse stp bpmn,oracle bpm..
4.Jbpm4.3推出来之后,开始支持BPMN2.0.所以这次我用jbpm4.3的跑我设计的BPMN工作流。
5.准备工作(我的平台)
Eclipse 3.5.2
JDK1.6
Tomcat 6
JBPM4.3(安装请看http://blog.csdn.net/inkfish/archive/2010/01/10/5169700.aspx)
6.请假系统工作流
7.实现上面工作流的BPMN代码---leave.bpmn.xml
<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schema.omg.org/spec/BPMN/2.0 ../../../../../../../../../../bpmn/src/main/resources/BPMN20.xsd" xmlns="http://schema.omg.org/spec/BPMN/2.0" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://jbpm.org/example/bpmn2/none_start_end_event" xmlns:jbpm="http://jbpm.org/bpmn2"> <process id="leave" name="BPMN2 Example process"> <startEvent id="start" /> <sequenceFlow id="flow1" name="To Apply Leave" sourceRef="start" targetRef="applyLeave" /> <userTask id="applyLeave" name="Apply Leave" implementation="other"> <potentialOwner resourceRef="user" jbpm:type="group"> <resourceAssignmentExpression> <formalExpression>user</formalExpression> </resourceAssignmentExpression> </potentialOwner> </userTask> <sequenceFlow id="to_teacher" name="To Teacher Check" sourceRef="applyLeave" targetRef="techerCheck" /> <userTask id="techerCheck" name="Teacher Check" implementation="other"> <potentialOwner resourceRef="user" jbpm:type="group"> <resourceAssignmentExpression> <formalExpression>teachers</formalExpression> </resourceAssignmentExpression> </potentialOwner> </userTask> <sequenceFlow id="teacherRefuse" name="Teacher Refuse" sourceRef="techerCheck" targetRef="applyLeave"> <conditionExpression xsi:type="tFormalExpression">${approveResult == 'NotOK'}</conditionExpression> </sequenceFlow> <sequenceFlow id="to_decide" name="To Decide" sourceRef="techerCheck" targetRef="decideBasedOnAmountGateway" > <conditionExpression xsi:type="tFormalExpression">${approveResult == 'OK'}</conditionExpression> </sequenceFlow> <exclusiveGateway id="decideBasedOnAmountGateway" name="decideBasedOnAmount" /> <sequenceFlow id="to_master" name="To Master" sourceRef="decideBasedOnAmountGateway" targetRef="masterCheck"> <conditionExpression xsi:type="tFormalExpression">${days > 3}</conditionExpression> </sequenceFlow> <sequenceFlow id="to_end1" name="To End1" sourceRef="decideBasedOnAmountGateway" targetRef="theEnd"> <conditionExpression xsi:type="tFormalExpression">${days <= 3}</conditionExpression> </sequenceFlow> <userTask id="masterCheck" name="Master Check" implementation="other"> <potentialOwner resourceRef="user" jbpm:type="group"> <resourceAssignmentExpression> <formalExpression>masters</formalExpression> </resourceAssignmentExpression> </potentialOwner> </userTask> <sequenceFlow id="masterRefuse" name="Master Refuse" sourceRef="masterCheck" targetRef="applyLeave"> <conditionExpression xsi:type="tFormalExpression">${approveResult == 'NotOK'}</conditionExpression> </sequenceFlow> <sequenceFlow id="to_end2" name="To End2" sourceRef="masterCheck" targetRef="theEnd"> <conditionExpression xsi:type="tFormalExpression">${approveResult == 'OK'}</conditionExpression> </sequenceFlow> <endEvent id="theEnd" name="End" /> </process> </definitions>
没有设计器,都是我自己看BPMN2.0的介绍和JBPM的内容,自己写出来的 leave.bpmn.xml
8.剩下的使用JBPM4.3的API让我的leave.bpmn.xml,跑起来
思想是:
学生都放在user用户组。user组都可以申请请假
老师放在teachers用户组。该用户组都可以审批学生请假(登录是用teacher)
主任放在masters用户组。该用户组审批请假超过3天的学生请假。(登录是用master)
部分代码:
String username = session.getAttribute("username").toString(); ProcessEngine processEngine = Configuration.getProcessEngine();//获得工作流引擎 RepositoryService repositoryService = processEngine//获得启动的工作流 .getRepositoryService(); ExecutionService executionService = processEngine//获得 工作流实例 .getExecutionService(); TaskService taskService = processEngine.getTaskService();//获得 任务 List<ProcessDefinition> pdList = repositoryService .createProcessDefinitionQuery().processDefinitionKey( "leave").list(); List<ProcessInstance> piList = executionService .createProcessInstanceQuery().list(); List<Task> taskList = taskService.createTaskQuery().candidate( username).list();
具体看代码。我上传了