/**部署流程定义*/
@Test
public void deploymentProcessDefinition(){
//与流程定义和部署对象相关的Service
RepositoryService repositoryService=processEngine.getRepositoryService();
DeploymentBuilder deploymentBuilder=repositoryService.createDeployment();//创建一个部署对象
deploymentBuilder.name("helloWorld入门程序");//添加部署的名称
deploymentBuilder.addClasspathResource("diagrams/MyProcess.bpmn");//从classpath的资源加载,一次只能加载一个文件
deploymentBuilder.addClasspathResource("diagrams/MyProcess.png");//从classpath的资源加载,一次只能加载一个文件
Deployment deployment=deploymentBuilder.deploy();//完成部署
//打印我们的流程信息
System.out.println("部署Id:"+deployment.getId());
System.out.println("部署名称Name:"+deployment.getName());
}
说明:
/**部署流程定义(Zip)*/
@Test
public void deploymentProcessDefinitionZip(){
//获得上传文件的输入流程
InputStream in=this.getClass().getClassLoader().getResourceAsStream("diagrams/MyProcess.zip");
ZipInputStream zipInputStream=new ZipInputStream(in);
//获取仓库服务,从类路径下完成部署
RepositoryService repositoryService=processEngine.getRepositoryService();
DeploymentBuilder deploymentBuilder=repositoryService.createDeployment();//创建一个部署对象
deploymentBuilder.name("helloWorld入门程序");//添加部署的名称
deploymentBuilder.addZipInputStream(zipInputStream);
Deployment deployment=deploymentBuilder.deploy();//完成部署
//打印我们的流程信息
System.out.println("部署Id:"+deployment.getId());
System.out.println("部署名称Name:"+deployment.getName());
}
/**查看流程定义
* id:(key):(version):(随机值)
* name:对应流程文件process节点的name属性
* key:对应流程文件process节点的id属性
* version:发布时自动生成的。如果是第一次发布的流程,version默认从1开始;
* 如果当前流程引擎中已存在相同的流程,则找到当前key对应的最高版本号,在最高版本号上加1*/
@Test
public void queryProcessDefinition() throws Exception{
//获取仓库服务对象,使用版本的升级排列,查询列表
List pdList=processEngine.getRepositoryService()
.createProcessDefinitionQuery()
//添加查询条件
//.processDefinitionId(processDefinitionId)
//.processDefinitionKey(processDefinitionKey)
//.processDefinitionName(processDefinitionName)
//排序(可以按照id/key/name/version/Cagetory排序)
.orderByProcessDefinitionVersion().asc()
//.count()
//.listPage(firstResult, maxResults)
//.singleResult()
.list();//总的结果集数量
//便利集合,查看内容
for (ProcessDefinition pd:pdList) {
System.out.println("id:"+pd.getId());
System.out.println("name:"+pd.getName());
System.out.println("key:"+pd.getKey());
System.out.println("version:"+pd.getVersion());
System.out.println("resourceName:"+pd.getDiagramResourceName());
System.out.println("###########################################");
}
}
结果:
/**删除流程*/
@Test
public void deleteDeployment(){
//删除发布信息
String deploymentId="1";
//获取仓库服务对象
RepositoryService repositoryService=processEngine.getRepositoryService();
//普通删除,如果当前规则下有正在执行的流程,则抛异常
//repositoryService.deleteDeployment(deploymentId);
//级联删除,会删除和当前规则相关的所有信息,正在执行的信息,也包括历史信息
repositoryService.deleteDeployment(deploymentId, true);
}
说明:
/**查看流程附件(查看流程图片)*/
@Test
public void viewImage() throws Exception{
//从仓库中找需要展示的文件
String deploymentId="1";
List names=processEngine.getRepositoryService()
.getDeploymentResourceNames(deploymentId);
String imageName=null;
for(String name:names){
System.out.println("name:"+name);
if(name.indexOf(".png")>0){
imageName=name;
break;
}
}
System.out.println("imageName:"+imageName);
if(imageName!=null){
File f=new File("e:/"+imageName);
//通过部署ID和文件名称得到文件的输入流
InputStream in = processEngine.getRepositoryService()
.getResourceAsStream(deploymentId, imageName);
FileUtils.copyInputStreamToFile(in, f);
}
}
运行结果:
如果我们的流程需要修改应该怎么操作呢?请看下一篇
转载请注明出处:http://blog.csdn.net/acmman/article/details/60981267