activiti 流程定义(二)

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipInputStream;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.apache.commons.io.FileUtils;
import org.junit.Test;

/**
 * 
 #流程定义表<br>
 * 
 * select * from act_re_deployment; # 部署对象表<br>
 * select * from act_re_procdef; # 流程定义表<br>
 * select * from act_ge_bytearray; # 资源文件表<br>
 * select * from act_ge_property; # 资源文件表<br>
 * 
 * @author ZHEN.L
 * @DATE 2016.04.28
 * 
 */

public class ProcessDefinitionTest {

	ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); // 获取流程引擎

	/**
	 * 部署
	 */
	@Test
	public void deploymentProcessDefinitionZip() {
		InputStream is = this.getClass().getResourceAsStream(
				"diagrams/MyProcess.zip");
		Deployment deployment = processEngine.getRepositoryService()
				.createDeployment().addZipInputStream(new ZipInputStream(is))
				.name("Zip流程定义").deploy();
		System.out.println(deployment.getId());
		System.out.println(deployment.getName());

	}

	/**
	 * 查询流程定义
	 */
	@Test
	public void findProcessDefinition() {
		List<ProcessDefinition> list = processEngine.getRepositoryService()
				.createProcessDefinitionQuery()
				.orderByProcessDefinitionVersion().asc().list();
		if (list != null && list.size() > 0) {
			for (ProcessDefinition p : list) {
				System.out.println("流程定义ID:" + p.getId());
				System.out.println("流程定义名称:" + p.getName());
				System.out.println("部署对象ID:" + p.getDeploymentId());
				System.out.println("流程定义key:" + p.getKey());
				System.out.println("流程定义版本:" + p.getVersion());
				System.out.println("#############################");
			}
		}
	}

	/**
	 * 删除流程定义<br>
	 * 默认只能删除未启动的流程,且不会级联删除
	 */
	@Test
	public void deleteProcessDefinition() {
		String deploymentId = "1101";
		processEngine.getRepositoryService().deleteDeployment(deploymentId);
	}

	/**
	 * 查看流程图
	 */
	@Test
	public void viewProcesssPic() {
		String deploymentId = "701";
		List<String> list = processEngine.getRepositoryService()
				.getDeploymentResourceNames(deploymentId);
		String resourceName = "";
		for (String name : list) {
			if (name.indexOf(".png") >= 0) {
				resourceName = name;
			}
		}
		InputStream is = processEngine.getRepositoryService()
				.getResourceAsStream(deploymentId, resourceName);
		try {
			FileUtils.copyInputStreamToFile(is, new File("f:/" + resourceName));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查询最新版本的流程定义<br>
	 * 流程定义不能被修改,以新版的形式定义修改。
	 */
	@Test
	public void findLeastPorcessDefinition() {
		Map<String, ProcessDefinition> map = new LinkedHashMap<String, ProcessDefinition>();
		List<ProcessDefinition> processDefinitions = processEngine
				.getRepositoryService().createProcessDefinitionQuery()
				.orderByProcessDefinitionVersion().asc().list();
		if (processDefinitions != null && processDefinitions.size() > 0) {
			for (ProcessDefinition p : processDefinitions) {
				map.put(p.getId(), p);
			}
		}
	}

	/**
	 * 删除版本不同的所有的流程实例
	 */
	@Test
	public void deleteProcessDefinitionByKey() {
		String processDefinitionKey = "myProcess";
		List<ProcessDefinition> list = processEngine.getRepositoryService()
				.createProcessDefinitionQuery()
				.processDefinitionKey(processDefinitionKey).list();
		if (list != null && list.size() > 0) {
			for (ProcessDefinition p : list) {
				processEngine.getRepositoryService().deleteDeployment(
						p.getDeploymentId(), true);
			}
		}
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值