Activiti 5 在线流程设计器开发

嵌入式企鹅圈 2011-11-30

    jbpm4的开发成员tom离开了jboss后,加入afresco公司,并且才有activiti5的项目,这开源项目继承了jbpm4的所有优点,同时将其发扬光大,相对jbpm4,activiti5改进了储多我们国内开发人员关心的问题,如:

  • 流程代办
  • 在线流程设计器
  • 流程嵌入式部署
  • 流程独立部署
  • 动流程节点
  • 自由流程
  • 支持了bpmn2的标准
  • 支持规则引擎

     activiti 5 底层上的api跟jbpm4的api相似程序也达60%以上,特别是service提供的接口,都是在jbpm4上提供扩展,大大方便了jbpm4的开发人员,这也是tom的先明之处,毕竟jbpm原来打的品牌效应不可否认的,把原来的jbpm4积累的人气再次带至activiti5上,这也将是该项目能够断续前进的重要保障。

     尽管activiti5目前发展趋势前途光明,但其也有不足的地方,其前端的的表现总是存在不足,如在线流程设计器,目前eclipse插件生成的bpmn20.xml文件则不行,而官方提供的activiti-modler设计器,扩展及实现均面临困难,并且对浏览器的要求让它在国内的项目实施总会面临技术难度。

       宏天estbpm3则又是一个基于activiti5的产品,并且公司也有打算断续原来的产品销售模式,对企业开放源代码,而原来的设计器通过改进后,则可以直接支持activiti5的流程设计的需要,如:

Activiti 5 在线流程设计器开发

设计器按设计器生成一份文档格式,通过系统中提供的xslt转化文档,完成转化后,生成bpmn20的格式文档,该文档可被activiti5直接识别。

其设计器及转化效果如下所示:

Activiti 5 在线流程设计器开发

Activiti 5 在线流程设计器开发

发布后,通过activiti5的api生成的流程图如下所示:

Activiti 5 在线流程设计器开发

Activiti 5 在线流程设计器开发

设计器原生成的文档格式:

<diagram xmlns:bg="bpm.graphic" xmlns:ciied="com.hotent.bpm.editor"
	xmlns:fg="flash.geom">
	<bg:Task id="task1" height="50" user="true" width="90" x="230"
		y="110">
		<label>用户任务1</label>
		<ports>
			<ciied:Port id="port1" clipOnShape="true" movable="false" />
			<ciied:Port id="port2" x="0" />
			<ciied:Port id="port3" y="1" />
			<ciied:Port id="port4" clipOnShape="true" movable="false">
				<id>CENTER</id>
			</ciied:Port>
		</ports>
	</bg:Task>
	<bg:StartEvent id="startEvent1" height="46" width="31" x="60"
		y="119.5">
		<label>开始</label>
		<ports>
			<ciied:Port id="port5" clipOnShape="true" movable="false" />
			<ciied:Port id="port6" x="1" />
			<ciied:Port id="port7" clipOnShape="true" movable="false">
				<id>CENTER</id>
			</ciied:Port>
		</ports>
	</bg:StartEvent>
	<bg:SubProcess id="subProcess1" automaticGraphLayout="false"
		expandedHeight="210" expandedWidth="570" height="210" width="570" x="360"
		y="230">
		<label>子流程</label>
		<ports>
			<ciied:Port id="port8" clipOnShape="true" movable="false" />
			<ciied:Port id="port9" x="0" />
			<ciied:Port id="port10" y="0" />
			<ciied:Port id="port11" clipOnShape="true" movable="false">
				<id>CENTER</id>
			</ciied:Port>
			<ciied:Port id="port12" horizontalOffset="-5" y="1">
				<id>BOTTOM</id>
			</ciied:Port>
			<ciied:Port id="port13" horizontalOffset="5" y="1">
				<id>BOTTOM</id>
			</ciied:Port>
		</ports>
		<bg:Task id="task2" height="50" user="true" width="90" x="180"
			y="53">
			<label>用户任务2</label>
			<ports>
				<ciied:Port id="port14" clipOnShape="true" movable="false" />
				<ciied:Port id="port15" x="0" />
				<ciied:Port id="port16" x="1" />
				<ciied:Port id="port17" clipOnShape="true" movable="false">
					<id>CENTER</id>
				</ciied:Port>
			</ports>
		</bg:Task>
		<bg:StartEvent id="startEvent2" height="46" width="32"
			x="29" y="62.5">
			<label>开始2</label>
			<ports>
				<ciied:Port id="port18" clipOnShape="true" movable="false" />
				<ciied:Port id="port19" x="1" />
				<ciied:Port id="port20" clipOnShape="true" movable="false">
					<id>CENTER</id>
				</ciied:Port>
			</ports>
		</bg:StartEvent>
		<bg:SequenceFlow id="sequenceFlow1" endPort="port15"
			startPort="port19">
			<fallbackEndPoint>
				<fg:Point id="point1" x="198" y="58" />
			</fallbackEndPoint>
			<fallbackStartPoint>
				<fg:Point id="point2" />
			</fallbackStartPoint>
			<label></label>
		</bg:SequenceFlow>
		<bg:EndEvent id="endEvent1" height="49" width="34" x="380"
			y="61">
			<label>结束2</label>
			<ports>
				<ciied:Port id="port21" clipOnShape="true" movable="false" />
				<ciied:Port id="port22" x="0" />
				<ciied:Port id="port23" clipOnShape="true" movable="false">
					<id>CENTER</id>
				</ciied:Port>
			</ports>
		</bg:EndEvent>
		<bg:SequenceFlow id="sequenceFlow2" endPort="port22"
			startPort="port16">
			<fallbackEndPoint>
				<fg:Point id="point3" x="364" y="68" />
			</fallbackEndPoint>
			<fallbackStartPoint>
				<fg:Point id="point4" />
			</fallbackStartPoint>
			<label></label>
		</bg:SequenceFlow>
	</bg:SubProcess>
	<bg:EndEvent id="endEvent2" height="49" width="34" x="740"
		y="120">
		<label>结束1</label>
		<ports>
			<ciied:Port id="port24" clipOnShape="true" movable="false" />
			<ciied:Port id="port25" x="0" />
			<ciied:Port id="port26" clipOnShape="true" movable="false">
				<id>CENTER</id>
			</ciied:Port>
		</ports>
	</bg:EndEvent>
	<bg:SequenceFlow id="sequenceFlow3" endPort="port2"
		startPort="port6">
		<fallbackEndPoint>
			<fg:Point id="point5" x="237" y="125" />
		</fallbackEndPoint>
		<fallbackStartPoint>
			<fg:Point id="point6" />
		</fallbackStartPoint>
		<label></label>
	</bg:SequenceFlow>
	<bg:SequenceFlow id="sequenceFlow4" endPort="port9"
		startPort="port3">
		<fallbackEndPoint>
			<fg:Point id="point7" x="396" y="461" />
		</fallbackEndPoint>
		<fallbackStartPoint>
			<fg:Point id="point8" />
		</fallbackStartPoint>
		<label></label>
	</bg:SequenceFlow>
	<bg:SequenceFlow id="sequenceFlow5" endPort="port25"
		startPort="port10">
		<fallbackEndPoint>
			<fg:Point id="point9" x="674" y="191" />
		</fallbackEndPoint>
		<fallbackStartPoint>
			<fg:Point id="point10" />
		</fallbackStartPoint>
		<label></label>
	</bg:SequenceFlow>
	<bg:Task id="task3" height="50" user="true" width="90" x="440"
		y="520">
		<label>用户任务3</label>
		<ports>
			<ciied:Port id="port27" clipOnShape="true" movable="false">
				<id>CENTER</id>
			</ciied:Port>
			<ciied:Port id="port28" y="0">
				<id>TOP</id>
			</ciied:Port>
			<ciied:Port id="port29" y="1">
				<id>BOTTOM</id>
			</ciied:Port>
		</ports>
	</bg:Task>
	<bg:SequenceFlow id="sequenceFlow6" endPort="port28"
		startPort="port12">
		<fallbackEndPoint>
			<fg:Point id="point11" x="623" y="568" />
		</fallbackEndPoint>
		<fallbackStartPoint>
			<fg:Point id="point12" />
		</fallbackStartPoint>
		<label></label>
	</bg:SequenceFlow>
	<bg:Task id="task4" height="50" user="true" width="90" x="750"
		y="520">
		<label>用户任务4</label>
		<ports>
			<ciied:Port id="port30" clipOnShape="true" movable="false">
				<id>CENTER</id>
			</ciied:Port>
			<ciied:Port id="port31" y="0">
				<id>TOP</id>
			</ciied:Port>
			<ciied:Port id="port32" y="1">
				<id>BOTTOM</id>
			</ciied:Port>
		</ports>
	</bg:Task>
	<bg:SequenceFlow id="sequenceFlow7" endPort="port31"
		startPort="port13">
		<fallbackEndPoint>
			<fg:Point id="point13" x="760" y="536" />
		</fallbackEndPoint>
		<fallbackStartPoint>
			<fg:Point id="point14" />
		</fallbackStartPoint>
		<label></label>
	</bg:SequenceFlow>
	<bg:EndEvent id="endEvent3" height="49" width="34" x="620"
		y="630">
		<label>结束3</label>
		<ports>
			<ciied:Port id="port33" clipOnShape="true" movable="false">
				<id>CENTER</id>
			</ciied:Port>
			<ciied:Port id="port34" x="1">
				<id>RIGHT</id>
			</ciied:Port>
			<ciied:Port id="port35" x="0">
				<id>LEFT</id>
			</ciied:Port>
		</ports>
	</bg:EndEvent>
	<bg:SequenceFlow id="sequenceFlow8" endPort="port35"
		startPort="port29">
		<fallbackEndPoint>
			<fg:Point id="point15" x="632" y="653" />
		</fallbackEndPoint>
		<fallbackStartPoint>
			<fg:Point id="point16" />
		</fallbackStartPoint>
		<label></label>
	</bg:SequenceFlow>
	<bg:SequenceFlow id="sequenceFlow9" endPort="port34"
		startPort="port32">
		<fallbackEndPoint>
			<fg:Point id="point17" x="688" y="651" />
		</fallbackEndPoint>
		<fallbackStartPoint>
			<fg:Point id="point18" />
		</fallbackStartPoint>
		<label></label>
	</bg:SequenceFlow>
</diagram>

通过XSLT转化后的文档格式:

<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
	xmlns:ciied="com.ibm.ilog.elixir.diagram" xmlns:bg="bpm.graphic"
	xmlns:fn="http://www.w3.org/2005/02/xpath-functions" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
	xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
	xmlns:activiti="http://activiti.org/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	targetNamespace="http://www.activiti.org/test" expressionLanguage="http://www.w3.org/1999/XPath"
	typeLanguage="http://www.w3.org/2001/XMLSchema">
	<process id="subGraph2" name="子流程">
		<startEvent id="startEvent1" name="开始" />
		<endEvent id="endEvent2" name="结束1" />
		<endEvent id="endEvent3" name="结束3" />
		<userTask id="task1" name="用户任务1" />
		<userTask id="task3" name="用户任务3" />
		<userTask id="task4" name="用户任务4" />
		<sequenceFlow id="sequenceFlow3" name="" sourceRef="startEvent1"
			targetRef="task1" />
		<sequenceFlow id="sequenceFlow4" name="" sourceRef="task1"
			targetRef="subProcess1" />
		<sequenceFlow id="sequenceFlow5" name="" sourceRef="subProcess1"
			targetRef="endEvent2" />
		<sequenceFlow id="sequenceFlow6" name="" sourceRef="subProcess1"
			targetRef="task3" />
		<sequenceFlow id="sequenceFlow7" name="" sourceRef="subProcess1"
			targetRef="task4" />
		<sequenceFlow id="sequenceFlow8" name="" sourceRef="task3"
			targetRef="endEvent3" />
		<sequenceFlow id="sequenceFlow9" name="" sourceRef="task4"
			targetRef="endEvent3" />
		<subProcess id="subProcess1" name="子流程">
			<startEvent id="startEvent2" name="开始2" />
			<endEvent id="endEvent1" name="结束2" />
			<userTask id="task2" name="用户任务2" />
			<sequenceFlow id="sequenceFlow1" name="" sourceRef="startEvent2"
				targetRef="task2" />
			<sequenceFlow id="sequenceFlow2" name="" sourceRef="task2"
				targetRef="endEvent1" />
		</subProcess>
	</process>
	<bpmndi:BPMNDiagram id="BPMNDiagram_subGraph2">
		<bpmndi:BPMNPlane bpmnElement="subGraph2" id="BPMNPlane_subGraph2">
			<bpmndi:BPMNShape bpmnElement="startEvent1"
				id="BPMNShape_startEvent1">
				<omgdc:Bounds height="31" width="31" x="60" y="119.5" />
			</bpmndi:BPMNShape>
			<bpmndi:BPMNShape bpmnElement="startEvent2"
				id="BPMNShape_startEvent2">
				<omgdc:Bounds height="32" width="32" x="389.0" y="292.5" />
			</bpmndi:BPMNShape>
			<bpmndi:BPMNShape bpmnElement="endEvent1" id="BPMNShape_endEvent1">
				<omgdc:Bounds height="34" width="34" x="740.0" y="291.0" />
			</bpmndi:BPMNShape>
			<bpmndi:BPMNShape bpmnElement="endEvent2" id="BPMNShape_endEvent2">
				<omgdc:Bounds height="34" width="34" x="740" y="120" />
			</bpmndi:BPMNShape>
			<bpmndi:BPMNShape bpmnElement="endEvent3" id="BPMNShape_endEvent3">
				<omgdc:Bounds height="34" width="34" x="620" y="630" />
			</bpmndi:BPMNShape>
			<bpmndi:BPMNShape bpmnElement="task1" id="BPMNShape_task1">
				<omgdc:Bounds height="50" width="90" x="230" y="110" />
			</bpmndi:BPMNShape>
			<bpmndi:BPMNShape bpmnElement="task2" id="BPMNShape_task2">
				<omgdc:Bounds height="50" width="90" x="540.0" y="283.0" />
			</bpmndi:BPMNShape>
			<bpmndi:BPMNShape bpmnElement="task3" id="BPMNShape_task3">
				<omgdc:Bounds height="50" width="90" x="440" y="520" />
			</bpmndi:BPMNShape>
			<bpmndi:BPMNShape bpmnElement="task4" id="BPMNShape_task4">
				<omgdc:Bounds height="50" width="90" x="750" y="520" />
			</bpmndi:BPMNShape>
			<bpmndi:BPMNShape bpmnElement="subProcess1"
				id="BPMNShape_subProcess1">
				<omgdc:Bounds height="210" width="570" x="360" y="230" />
			</bpmndi:BPMNShape>
			<bpmndi:BPMNEdge bpmnElement="sequenceFlow1" id="BPMNEdge_sequenceFlow1">
				<omgdi:waypoint x="421.0" y="308.5"></omgdi:waypoint>
				<omgdi:waypoint x="480.5" y="308.5"></omgdi:waypoint>
				<omgdi:waypoint x="480.5" y="308.0"></omgdi:waypoint>
				<omgdi:waypoint x="540.0" y="308.0"></omgdi:waypoint>
			</bpmndi:BPMNEdge>
			<bpmndi:BPMNEdge bpmnElement="sequenceFlow2" id="BPMNEdge_sequenceFlow2">
				<omgdi:waypoint x="630.0" y="308.0"></omgdi:waypoint>
				<omgdi:waypoint x="740.0" y="308.0"></omgdi:waypoint>
			</bpmndi:BPMNEdge>
			<bpmndi:BPMNEdge bpmnElement="sequenceFlow3" id="BPMNEdge_sequenceFlow3">
				<omgdi:waypoint x="91.0" y="135.0"></omgdi:waypoint>
				<omgdi:waypoint x="230.0" y="135.0"></omgdi:waypoint>
			</bpmndi:BPMNEdge>
			<bpmndi:BPMNEdge bpmnElement="sequenceFlow4" id="BPMNEdge_sequenceFlow4">
				<omgdi:waypoint x="275.0" y="160.0"></omgdi:waypoint>
				<omgdi:waypoint x="275.0" y="335.0"></omgdi:waypoint>
				<omgdi:waypoint x="360.0" y="335.0"></omgdi:waypoint>
			</bpmndi:BPMNEdge>
			<bpmndi:BPMNEdge bpmnElement="sequenceFlow5" id="BPMNEdge_sequenceFlow5">
				<omgdi:waypoint x="645.0" y="230.0"></omgdi:waypoint>
				<omgdi:waypoint x="645.0" y="137.0"></omgdi:waypoint>
				<omgdi:waypoint x="740.0" y="137.0"></omgdi:waypoint>
			</bpmndi:BPMNEdge>
			<bpmndi:BPMNEdge bpmnElement="sequenceFlow6" id="BPMNEdge_sequenceFlow6">
				<omgdi:waypoint x="640.0" y="440.0"></omgdi:waypoint>
				<omgdi:waypoint x="640.0" y="480.0"></omgdi:waypoint>
				<omgdi:waypoint x="485.0" y="480.0"></omgdi:waypoint>
				<omgdi:waypoint x="485.0" y="520.0"></omgdi:waypoint>
			</bpmndi:BPMNEdge>
			<bpmndi:BPMNEdge bpmnElement="sequenceFlow7" id="BPMNEdge_sequenceFlow7">
				<omgdi:waypoint x="650.0" y="440.0"></omgdi:waypoint>
				<omgdi:waypoint x="650.0" y="480.0"></omgdi:waypoint>
				<omgdi:waypoint x="795.0" y="480.0"></omgdi:waypoint>
				<omgdi:waypoint x="795.0" y="520.0"></omgdi:waypoint>
			</bpmndi:BPMNEdge>
			<bpmndi:BPMNEdge bpmnElement="sequenceFlow8" id="BPMNEdge_sequenceFlow8">
				<omgdi:waypoint x="485.0" y="570.0"></omgdi:waypoint>
				<omgdi:waypoint x="485.0" y="647.0"></omgdi:waypoint>
				<omgdi:waypoint x="620.0" y="647.0"></omgdi:waypoint>
			</bpmndi:BPMNEdge>
			<bpmndi:BPMNEdge bpmnElement="sequenceFlow9" id="BPMNEdge_sequenceFlow9">
				<omgdi:waypoint x="795.0" y="570.0"></omgdi:waypoint>
				<omgdi:waypoint x="795.0" y="647.0"></omgdi:waypoint>
				<omgdi:waypoint x="654.0" y="647.0"></omgdi:waypoint>
			</bpmndi:BPMNEdge>
		</bpmndi:BPMNPlane>
	</bpmndi:BPMNDiagram>
</definitions>

转成后,则直接通过以下api可发布至流程引擎:

Deployment deployment= repositoryService.createDeployment().name(bpmDefinition.getSubject()).addString(bpmDefinition.getSubject()+".bpmn20.xml",actFlowDefXml).deploy();

最新实现效果图如:

Activiti 5 在线流程设计器开发

想部署及学习了解,可参考本人新的博客获得下载源代码。

相关推荐