Activiti学习笔记(一)流程图的编辑
最近由于公司需要,本人有幸参加了一个工作流项目的开发过程。本人不才,在参与项目之前对工作流是一无所知。本次项目开发中,使用的主要技术为struts2+hibernate3+spring3的框架,以及Activiti工作流引擎。下面几篇文章将本次开发过程中所用到的技术以及遇到的错误记录如下,以备忘。
在使用Activiti之前,首先需要了解Activiti自动生成的表的作用。现做如下说明:
ACT_GE_BYTEARRAY 用来保存部署文件的大文本数据 1. ID_:资源文件编号,自增长 2. REV_INT:版本号 3. NAME_:资源文件名称 4. DEPLOYMENT_ID_:来自于父表ACT_RE_DEPLOYMENT的主键 5. BYTES_:大文本类型,存储文本字节流 ACT_GE_PROPERTY 属性数据表,存储这个流程引擎级别的数据 1. NAME_:属性名称 2. VALUE_:属性值 3. REV_INT:版本号 ACT_HI_ACTINST 流程活动的实例 ACT_HI_ATTACHMENT ACT_HI_COMMENT ACT_HI_DETAIL ACT_HI_PROCINST 流程实例 ACT_HI_TASKINST 任务实例 ACT_ID_GROUP 用户组 ACT_ID_INFO ACT_ID_MEMBERSHIP 用来保存用户的分组信息 1. USER_ID_:用户名 2. GROUP_ID_:用户组名 ACT_ID_USER 用户 1. ID_:用户名 2. REV_INT:版本号 3. FIRST_:用户名称 4. LAST_:用户姓氏 5. EMAIL_:邮箱 6. PWD_:密码 ACT_RE_DEPLOYMENT 用来存储部署时需要持久化保存下来的信息 1. ID_:部署编号,自增长 2. NAME_:部署包的名称 3. DEPLOY_TIME_:部署时间 ACT_RE_PROCDEF 业务流程定义数据表 1. ID_:流程ID,由“流程编号:流程版本号:自增长ID”组成 2. CATEGORY_:流程命名空间(该编号就是流程文件targetNamespace的属性值) 3. NAME_:流程名称(该编号就是流程文件process元素的name属性值) 4. KEY_:流程编号(该编号就是流程文件process元素的id属性值) 5. VERSION_:流程版本号(由程序控制,新增即为1,修改后依次加1来完成的) 6. DEPLOYMENT_ID_:部署编号 7. RESOURCE_NAME_:资源文件名称 8. DGRM_RESOURCE_NAME_:图片资源文件名称 9. HAS_START_FROM_KEY_:是否有Start From Key 注:此表和ACT_RE_DEPLOYMENT是多对一的关系,即,一个部署的bar包里可能包含多个流程定义文件,每个流程定义文件都会有一条记录在ACT_REPROCDEF表内,每个流程定义的数据,都会对于ACT_GE_BYTEARRAY表内的一个资源文件和PNG图片文件。和ACT_GE_BYTEARRAY的关联是通过程序用ACT_GE_BYTEARRAY.NAME与ACT_RE_PROCDEF.NAME_完成的,在数据库表结构中没有体现。 ACT_RU_EXECUTION 流程执行记录 1. ID_: 2. REV_:版本号 3. PROC_INST_ID_:流程实例编号 4. BUSINESS_KEY_:业务编号 5. PARENT_ID_: 6. PROC_DEF_ID_:流程ID 7. SUPER_EXEC_: 8. ACT_ID_: 9. IS_ACTIVE_: 10. IS_CONCURRENT_: 11. IS_SCOPE_: ACT_RU_IDENTITYLINK 任务参与者数据表,存储当前节点参与者的信息 1. ID_: 2. REV_: 3. GROUP_ID_: 4. TYPE_: 5. USER_ID_: 6. TASK_ID_: ACT_RU_JOB 运行时定时任务数据表 1. ID_: 2. REV_: 3. TYPE_: 4. LOCK_EXP_TIME_: 5. LOCK_OWNER_: 6. EXCLUSIVE_: 7. EXECUTION_ID_: 8. PROCESS_INSTANCE_ID_: 9. RETRIES_: 10. EXCEPTION_STACK_ID_: 11. EXCEPTION_MSG_: 12. DUEDATE_: 13. REPEAT_: 14. HANDLER_TYPE_: 15. HANDLER_CFG_: ACT_RU_TASK 运行时任务数据表 1. ID_: 2. REV_: 3. EXECUTION_ID_: 4. PROC_INST_ID_: 5. PROC_DEF_ID_: 6. NAME_: 7. DESCRIPTION_: 8. TASK_DEF_KEY_: 9. ASSIGNEE_: 10. PRIORITY_: 11. CREATE_TIME_: ACT_RU_VARIABLE 运行时流程变量数据表 1. ID_: 2. REV_: 3. TYPE_: 4. NAME_: 5. EXECUTION_ID_: 6. PROC_INST_ID_: 7. TASK_ID_: 8. BYTEARRAY_ID_: 9. DOUBLE_: 10. LONG_: 11. TEXT_: 12. TEXT2_:
说明了数据表的作用以后,在编写流程图之前,我们需要在Eclipse中安装一个Activiti的强大的插件,安装方法如下:
打开Eclipse----Help----Install new Software----Add----在Name栏中输入 Activiti BPMN 2.0 designer----在Location栏中输入 http://activiti.org/designer/update/ ----OK----next直到结束重启Eclipse。
既然是用到了Activiti工作流引擎,那么,我们在搭建好SSH框架以后,即需要画出一个以供我们使用的流程图。目前项目中使用的流程较为简单,具体流程图如下:
流程图运行步骤:1.首先用户需要填写某个申请;2.申请后,需要领导审批;3.如果领导不同意该申请,那么驳回后由原用户选择重新填写申请或不重新填写申请直接结束流程;4.如果领导同意该申请,那么需要由原用户填写回执后,结束流程。
流程图代码:
<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test"> <process id="RunMode" name="流程" isExecutable="true"> <documentation>流程</documentation> <startEvent id="startevent1" name="Start" activiti:initiator="applyUserId"></startEvent> <userTask id="leaderAudit" name="领导审批" activiti:candidateGroups="deptLeader"></userTask> <userTask id="usertask3" name="填写回执" activiti:assignee="${applyUserId}"></userTask> <sequenceFlow id="flow4" sourceRef="leaderAudit" targetRef="exclusivegateway1"></sequenceFlow> <endEvent id="endevent1" name="End"></endEvent> <sequenceFlow id="flow5" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow> <sequenceFlow id="flow6" sourceRef="startevent1" targetRef="leaderAudit"></sequenceFlow> <sequenceFlow id="flow8" name="同意" sourceRef="exclusivegateway1" targetRef="usertask3"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${LeaderPass}]]></conditionExpression> </sequenceFlow> <userTask id="modifyApply" name="调整申请" activiti:assignee="${applyUserId}"></userTask> <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway> <sequenceFlow id="flow9" name="不同意" sourceRef="exclusivegateway1" targetRef="modifyApply"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!LeaderPass}]]></conditionExpression> </sequenceFlow> <exclusiveGateway id="exclusivegateway2" name="Exclusive Gateway"></exclusiveGateway> <sequenceFlow id="flow10" sourceRef="modifyApply" targetRef="exclusivegateway2"></sequenceFlow> <sequenceFlow id="flow11" name="重新申请" sourceRef="exclusivegateway2" targetRef="leaderAudit"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${reApply}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="flow12" name="结束流程" sourceRef="exclusivegateway2" targetRef="endevent1"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!reApply}]]></conditionExpression> </sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_RunMode"> <bpmndi:BPMNPlane bpmnElement="RunMode" id="BPMNPlane_RunMode"> <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1"> <omgdc:Bounds height="35.0" width="35.0" x="140.0" y="147.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3"> <omgdc:Bounds height="55.0" width="105.0" x="530.0" y="137.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1"> <omgdc:Bounds height="35.0" width="35.0" x="690.0" y="323.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="leaderAudit" id="BPMNShape_leaderAudit"> <omgdc:Bounds height="55.0" width="105.0" x="220.0" y="137.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="modifyApply" id="BPMNShape_modifyApply"> <omgdc:Bounds height="55.0" width="105.0" x="363.0" y="230.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1"> <omgdc:Bounds height="40.0" width="40.0" x="395.0" y="144.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="exclusivegateway2" id="BPMNShape_exclusivegateway2"> <omgdc:Bounds height="40.0" width="40.0" x="395.0" y="320.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4"> <omgdi:waypoint x="325.0" y="164.0"></omgdi:waypoint> <omgdi:waypoint x="395.0" y="164.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5"> <omgdi:waypoint x="635.0" y="164.0"></omgdi:waypoint> <omgdi:waypoint x="707.0" y="164.0"></omgdi:waypoint> <omgdi:waypoint x="707.0" y="323.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6"> <omgdi:waypoint x="175.0" y="164.0"></omgdi:waypoint> <omgdi:waypoint x="220.0" y="164.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8"> <omgdi:waypoint x="435.0" y="164.0"></omgdi:waypoint> <omgdi:waypoint x="530.0" y="164.0"></omgdi:waypoint> <bpmndi:BPMNLabel> <omgdc:Bounds height="14.0" width="100.0" x="-20.0" y="-17.0"></omgdc:Bounds> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9"> <omgdi:waypoint x="415.0" y="184.0"></omgdi:waypoint> <omgdi:waypoint x="415.0" y="230.0"></omgdi:waypoint> <bpmndi:BPMNLabel> <omgdc:Bounds height="14.0" width="100.0" x="10.0" y="0.0"></omgdc:Bounds> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10"> <omgdi:waypoint x="415.0" y="285.0"></omgdi:waypoint> <omgdi:waypoint x="415.0" y="320.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11"> <omgdi:waypoint x="395.0" y="340.0"></omgdi:waypoint> <omgdi:waypoint x="272.0" y="339.0"></omgdi:waypoint> <omgdi:waypoint x="272.0" y="192.0"></omgdi:waypoint> <bpmndi:BPMNLabel> <omgdc:Bounds height="14.0" width="100.0" x="38.0" y="-7.0"></omgdc:Bounds> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow12" id="BPMNEdge_flow12"> <omgdi:waypoint x="435.0" y="340.0"></omgdi:waypoint> <omgdi:waypoint x="690.0" y="340.0"></omgdi:waypoint> <bpmndi:BPMNLabel> <omgdc:Bounds height="14.0" width="100.0" x="-38.0" y="-20.0"></omgdc:Bounds> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
流程代码解释:
<process id="RunMode" name="流程" isExecutable="true"> 流程ID及流程名称
<startEvent id="startevent1" name="Start" activiti:initiator="applyUserId">开始节点及流程的发起人
<userTask id="leaderAudit" name="领导审批" activiti:candidateGroups="deptLeader"></userTask>领导审批节点及可以有权限参与的用户组名(数据库关联)
<userTask id="usertask3" name="填写回执" activiti:assignee="${applyUserId}"></userTask>填写回执节点及设置参与人为流程的发起人
<sequenceFlow id="flow8" name="同意" sourceRef="exclusivegateway1" targetRef="usertask3">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${LeaderPass}]]> </conditionExpression>
</sequenceFlow>
同意申请与驳回类似于一个正则表达式,若传过来的参数为true,则自动同意申请;反之若传过来的参数为false,则驳回申请。
到目前为止,流程图制作已经结束。