您的位置:首页 > 其它

activiti5.20简单介绍(七) -- 流程操作

2016-10-14 17:28 375 查看
1.部署说明
(1)部署流程之后,在对应的记录表(act_ge_bytearray--流程资源文件表)会生成响应的两条记录,其中一条是流程定义文件,一条是流程图片
(2)act_ge_property--流程主键生成策略表
(3)act_re_deployment--流程对象表,部署之后会在表中生成一条响应的记录
(4)act_re_procdef--流程定义表,保存所部属流程的信息,id规则为( 流程定义的key:版本:随机值)
 
2.部署方式
  // 仓库管理流程服务
RepositoryService repositoryService = engine.getRepositoryService();

// 部署管理构建
DeploymentBuilder builder = repositoryService.createDeployment();

//---------------------------------
// 部署流程,使用deploy()方法部署,部署同时还可以使用name方法为流程起一个名字,
// 使用category()方法为流程设定类别,返回值为Deployment对象
// 1.使用流程文件路径部署,会自动生成图片文件,建议将图片文件一同部署addClasspathResource("process/hello.png")
Deployment d = builder.addClasspathResource("process/hello.bpmn")
.addClasspathResource("process/hello.png")
.name("hello").category("first").tenantId("1").deploy();
System.out.println("流程定义id: "+d.getId());

//---------------------------------
// 2.使用输入流部署,不生成图片文件,建议将图片文件一同部署getResourceAsStream("/process/hello.png")
// InputStream in =
// this.getClass().getResourceAsStream("/process/hello.bpmn");
// builder.addInputStream("hello",in).deploy();

//---------------------------------
// 3.使用zipinputStream部署,将流程定义文件与图片文件一起打包为zip格式文件
InputStream in =
this.getClass().getResourceAsStream("/process/hello.zip");
ZipInputStream zip = new ZipInputStream(in);
builder.addZipInputStream(zip).name("hello").deploy();

//---------------------------------
// 4.使用文本部署,建议将图片文件一同部署addClasspathResource("process/hello.png")
// String context = "<?xml version=\"1.0\" Encoding=\"utf-8\" ?>
// xxxxxx";
// builder.addString("hello", context).name("12345").deploy();

3.删除流程
  RepositoryService repositoryService = engine.getRepositoryService();
// 删除流程,如果流程已启动,则抛出异常
//repositoryService.deleteDeployment("1");

// 级联删除流程,不论是否启动,都会删除
repositoryService.deleteDeployment(id, true);
删除方法的第二个参数是在删除操作使用级联删除,此时会强制删除与之关联的所有条目,包括正在运行的任务等,但是这样会导致业务流程的崩溃,也就是一些流程无法继续运行,一般不建议使用,如果是流程更新换代,在保证业务安全的情况下可以执行。
 
二、查询流程
1.查询
使用仓库服务获取流程部署的查询对象,该对象提供了丰富的查询方式,若是无法满足要求,还可以使用本地查询方式进行查询
  RepositoryService repositoryService = engine.getRepositoryService();
DeploymentQuery deploymentQuery = repositoryService.createDeploymentQuery();
// 根据类别查询
// deploymentQuery.deploymentCategory();
// deploymentQuery.deploymentCategoryNotEquals(categoryNotEquals);

// 根据id查询
List<Deployment> list = deploymentQuery.deploymentId(id)
.orderByDeploymentId().desc().listPage(0, 10);

// 根据名字查询
// deploymentQuery.deploymentName(name);
// deploymentQuery.deploymentNameLike(nameLike);

// 查询结果
if(list!=null && list.size()>0){
Deployment deployment = list.get(0);
System.out.println("流程ID: "+deployment.getId());
System.out.println("流程名称: "+deployment.getName());
System.out.println("流程类别: "+deployment.getCategory());
System.out.println("流程所有人: "+deployment.getTenantId());
System.out.println("部署时间: "+deployment.getDeploymentTime());
}

2.获取流程文件
//获取流程部署文件
List<String> resourceNames = repositoryService.getDeploymentResourceNames(id);
System.out.println(resourceNames);
//遍历文件名
for (String string : resourceNames)
{
//通过文件名和流程id获取文件
InputStream in = repositoryService.getResourceAsStream(id, string);
string = string.substring(string.indexOf("/")+"/".length());
//写出文件
OutputStream out = new FileOutputStream(new File("d:/"+string));
int len = 0;
byte[] b = new byte[1024];
while((len=in.read(b))!=-1){
out.write(b, 0, len);
}
out.flush();
out.close();
in.close();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  activiti