activiti学习笔记(五) 流程部署

activiti流程部署

activit部署方法api

    activiti共有六种部署方式,最终实现都是DeploymentEntityImpl的addResource方法

public interface DeploymentBuilder {

  //根据流进行部署,获取bpmn文件的流进行部署,resourceName是资源名可以自定义
  DeploymentBuilder addInputStream(String resourceName, InputStream inputStream);

  //通过文件路径进行部署
  DeploymentBuilder addClasspathResource(String resource);

  //根据文本字符串进行部署,文本字符串可以是读取文件的,也可以自己手写
  DeploymentBuilder addString(String resourceName, String text);

  //根据字节码尽心部署
  DeploymentBuilder addBytes(String resourceName, byte[] bytes);

  //根据zip流进行部署
  DeploymentBuilder addZipInputStream(ZipInputStream zipInputStream);

  //根据BpmnModel实例进行部署
  DeploymentBuilder addBpmnModel(String resourceName, BpmnModel bpmnModel);
}

activiti部署前提

       预设某些情况有了bpmn文件,首先我们需要repositoryService这个实例,接下来进行部署使用的都是这个实例

@Before
	public void init() {
		processEngine = ProcessEngineConfiguration
				.createProcessEngineConfigurationFromResource(
                        "com/activiti_study/ch10/activiti1.cfg.xml")
				.buildProcessEngine();

		repositoryService = processEngine.getRepositoryService();
	}

activiti部署过程

zip流部署

       这种方式是把其压缩成zip文件,然后进行部署

        @Test
	public void testAddZipInputStream() throws Exception {
		InputStream in = App.class.getClassLoader().getResourceAsStream(
                "com/activiti_study/ch10/common.zip");
		ZipInputStream zipInputStream = new ZipInputStream(in);
		DeploymentBuilder deployment = repositoryService.createDeployment();
		deployment.addZipInputStream(zipInputStream).deploy();

	}

普通流部署

    根据资源文件路径,获取其流,进行部署

        @Test
	public void testAddInputStream() throws Exception {
		DeploymentBuilder deployment = repositoryService.createDeployment();

		InputStream inputStream = App.class.getClassLoader()
				.getResource("com/activiti_study/ch10/common.bpmn")
				.openStream();
		deployment.addInputStream(resourceName, inputStream).deploy();
	}

根据资源文件路径进行部署

        @Test
	public void testAddClasspathResource() {
		DeploymentBuilder deployment = repositoryService.createDeployment();
		deployment.addClasspathResource(
                "com/activiti_study/ch10/common.bpmn").deploy();
	}

根据bpmnModel实例进行部署

        @Test
	public void testAddBpmnModel() {
		DeploymentBuilder deployment = repositoryService.createDeployment();
		BpmnModel bpmnModel = getBpmnModel();
		deployment.addBpmnModel(resourceName, bpmnModel).deploy();
	}
        private BpmnModel getBpmnModel() {
		BpmnModel bpmnModel = new BpmnModel();
		// 连线1
		SequenceFlow flow1 = new SequenceFlow();
		flow1.setId("flow1");
		flow1.setName("开始节点-->任务节点1");
		flow1.setSourceRef("start1");
		flow1.setTargetRef("userTask1");

		// 连线2
		SequenceFlow flow2 = new SequenceFlow();
		flow2.setId("flow2");
		flow2.setName("任务节点1-->任务节点2");
		flow2.setSourceRef("userTask1");
		flow2.setTargetRef("userTask2");

		// 连线3
		SequenceFlow flow3 = new SequenceFlow();
		flow3.setId("flow3");
		flow3.setName("任务节点2-->结束节点");
		flow3.setSourceRef("userTask2");
		flow3.setTargetRef("endEvent");
		// 开始节点
		StartEvent start = new StartEvent();
		start.setId("start1");
		start.setName("开始节点");
		start.setOutgoingFlows(Arrays.asList(flow1));
		// 任务节点1
		UserTask userTask1 = new UserTask();
		userTask1.setId("userTask1");
		userTask1.setName("任务节点1");
		userTask1.setIncomingFlows(Arrays.asList(flow1));
		userTask1.setOutgoingFlows(Arrays.asList(flow2));

		// 任务节点2
		UserTask userTask2 = new UserTask();
		userTask2.setId("userTask2");
		userTask2.setName("任务节点2");
		userTask2.setIncomingFlows(Arrays.asList(flow2));
		userTask2.setOutgoingFlows(Arrays.asList(flow3));
		//结束节点
		EndEvent endEvent = new org.activiti.bpmn.model.EndEvent();
		endEvent.setId("endEvent");
		endEvent.setName("结束节点");
		endEvent.setIncomingFlows(Arrays.asList(flow3));
		
		Process process=new Process();
		process.setId("process1");
		process.addFlowElement(start);
		process.addFlowElement(flow1);
		process.addFlowElement(flow2);
		process.addFlowElement(flow3);
		process.addFlowElement(userTask1);
		process.addFlowElement(userTask2);
		process.addFlowElement(endEvent);
		bpmnModel.addProcess(process);
		return bpmnModel;
	}








根据纯文本进行部署
        @Test
	public void testAddSrtring() {
		DeploymentBuilder deployment = repositoryService.createDeployment();
		String text = readTxtFile("E:/activitilearing/activiti-study/src/main/java/com/shareniu/activiti_study/ch10/common.bpmn");
		deployment.addString(resourceName, text).deploy();
	}


        public static String readTxtFile(String filePath) {
		StringBuffer stringBuffer = new StringBuffer();
		InputStreamReader read = null;
		try {
			String encoding = "UTF-8";// UTF-8编码
			File file = new File(filePath);
			if (file.isFile() && file.exists()) { // 判断文件是否存在
				read = new InputStreamReader(new FileInputStream(file),
						encoding);// 考虑到编码格式
				BufferedReader bufferedReader = new BufferedReader(read);
				String lineTxt = null;
				while ((lineTxt = bufferedReader.readLine()) != null) {
					stringBuffer.append(lineTxt);
				}
				return stringBuffer.toString();
			} else {
				System.out.println("找不到指定的文件");
			}
		} catch (Exception e) {
			System.out.println("读取文件内容出错");
		} finally {
			try {
				read.close();
			} catch (IOException e) {
			}
		}
		return "";
	}

 
activiti部署后表数据
       a)     act_re_deployment
      存放流程定义的显示名和部署时间,每部署一次增加一条记录
 
    b)    act_re_procdef
      存放流程定义的属性信息,部署每个新的流程定义都会在这张表中增加一条记录。
 
    c)    act_ge_bytearray
      存储流程定义相关的部署信息。即流程定义文档的存放地。每部署一次就会增加两条记录,一条是关于bpmn规则文件的,一条是图片的(如果部署时只指定了bpmn一个文件,activiti会在部署时解析bpmn文件内容自动生成流程图)。两个文件不是很大,都是以二进制形式存储在数据库中。

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏转载gongluck的CSDN博客

cocos2dx 打灰机

#include "GamePlane.h" #include "PlaneSprite.h" #include "BulletNode.h" #include...

5466
来自专栏我和未来有约会

Silverlight第三方控件专题

这里我收集整理了目前网上silverlight第三方控件的专题,若果有所遗漏请告知我一下。 名称 简介 截图 telerik 商 RadC...

4025
来自专栏我和未来有约会

Kit 3D 更新

Kit3D is a 3D graphics engine written for Microsoft Silverlight. Kit3D was inita...

2536
来自专栏陈仁松博客

ASP.NET Core 'Microsoft.Win32.Registry' 错误修复

今天在发布Asp.net Core应用到Azure的时候出现错误InvalidOperationException: Cannot find compilati...

4848
来自专栏魂祭心

原 canvas绘制clock

4074
来自专栏张善友的专栏

Silverlight + Model-View-ViewModel (MVVM)

     早在2005年,John Gossman写了一篇关于Model-View-ViewModel模式的博文,这种模式被他所在的微软的项目组用来创建Expr...

2968
来自专栏张善友的专栏

Miguel de Icaza 细说 Mix 07大会上的Silverlight和DLR

Mono之父Miguel de Icaza 详细报道微软Mix 07大会上的Silverlight和DLR ,上面还谈到了Mono and Silverligh...

2707
来自专栏一个会写诗的程序员的博客

Spring Reactor 项目核心库Reactor Core

Non-Blocking Reactive Streams Foundation for the JVM both implementing a Reactiv...

2152
来自专栏张善友的专栏

LINQ via C# 系列文章

LINQ via C# Recently I am giving a series of talk on LINQ. the name “LINQ via C...

2645
来自专栏杨龙飞前端

scrollto 到指定位置

2504

扫码关注云+社区