1、引言
在前面我们知道了怎么创建流程控制引擎,而Activiti 的正常使用还需要进行部署流程,而这就有一个很重要的前提。那就是创建相应的流程图,并让其能被 service 所调用从而实现流程的执行。
2、流程图创建工具
2.1 简述第一种创建方式
在这里说明一点,流程图的创建可以使用两种方式,第一种是XML版本的,案例如下:
我们看到的是一个开始事件(左侧的圆圈),后面是两个用户任务:“写每月财务报告”和 “验证每月财务报告”,以一个结束事件(右侧带有粗边框的圆圈)结束。
- 在这里,start task 告诉我们什么入口点的过程。
- 在 user task 声明是我们的过程的人工任务的表示。请注意,第一个任务分配给会计组,而第二个任务分配给管理组。有关如何将用户和组分配给用户任务的更多信息,请参见用户任务分配部分。
- 当到达 end task 时,该过程结束。
- 这些元素通过顺序流相互连接。这些顺序流具有source和target,用于定义顺序流的方向。
其对应的xml 版本的配置如下:
<definitions id="definitions"
targetNamespace="http://activiti.org/bpmn20"
xmlns:activiti="http://activiti.org/bpmn"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL">
<process id="financialReport" name="Monthly financial report reminder process">
<startEvent id="theStart" />
<sequenceFlow id='flow1' sourceRef='theStart' targetRef='writeReportTask' />
<userTask id="writeReportTask" name="Write monthly financial report" >
<documentation>
Write monthly financial report for publication to shareholders.
</documentation>
<potentialOwner>
<resourceAssignmentExpression>
<formalExpression>accountancy</formalExpression>
</resourceAssignmentExpression>
</potentialOwner>
</userTask>
<sequenceFlow id='flow2' sourceRef='writeReportTask' targetRef='verifyReportTask' />
<userTask id="verifyReportTask" name="Verify monthly financial report" >
<documentation>
Verify monthly financial report composed by the accountancy department.
This financial report is going to be sent to all the company shareholders.
</documentation>
<potentialOwner>
<resourceAssignmentExpression>
<formalExpression>management</formalExpression>
</resourceAssignmentExpression>
</potentialOwner>
</userTask>
<sequenceFlow id='flow3' sourceRef='verifyReportTask' targetRef='theEnd' />
<endEvent id="theEnd" />
</process>
</definitions>
2.2 视图模式创建流程图
上述工作流,其XML配置如下:
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<endEvent id="endevent1" name="End"></endEvent>
<userTask id="usertask1" name="myprocess" activiti:assignee="白夜行"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
<bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="320.0" y="150.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="320.0" y="330.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="285.0" y="220.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="337.0" y="185.0"></omgdi:waypoint>
<omgdi:waypoint x="337.0" y="220.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="337.0" y="275.0"></omgdi:waypoint>
<omgdi:waypoint x="337.0" y="330.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
以上的XML 由 标签和 bpmndi:BPMNDiagram/标签组成。
bpmndi:BPMNDiagram/ 主要是 该流程图在界面上的所处位置表示,以及该流程图的对应 Id;这里只针对一点做出说明即可,那就是 <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess"> 标签在所有的 bpmn 中是不可重复的,当出现重复情况会抛出异常 exclusivegateway1。
针对 详细说明一下:
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<endEvent id="endevent1" name="End"></endEvent>
<userTask id="usertask1" name="myprocess" activiti:assignee="白夜行"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
</process>
说明如下:
- process表示流程,有一个Id必须提供,启动流程或者查询都根据这个key, name可以为各种语言如中文表达。
- startEvent表示开始事件,如果在流程开始之前做什么事,就定义这个事件。
- userTask表示一个用户任务,也就是需要用户完成的任务,流程会在此等待用户介入。一般用户任务需要分配给人或组织,这里分配者和表单都是activiti的自定义数据方式,通过用户任务将流程和人相关,如果这里是serviceTask服务任务,就会将流程和机器服务相关。
- sequenceFlow表示顺序流,类似两个节点之间的连接线,方向是固定的,代表逻辑顺序。
- endEvent表示结束事件,流程实例结束。流程引擎一般不会再保存该流程状态,会放入历史归档。
它们之间的对应关系图:
如果你觉得这边内容对你挺有帮助的话:
- 点赞支持下吧,让更多的人也能看到这篇内容(收藏不点赞,都是耍流氓-_-)
- 作者暂无公众号,但可以关注作者的个人网站,进行更多技术上的交流
- 如果在文章中看到遗漏或不足失误之处,欢迎指出,作者将十分感谢您的指点。