activiti流程定义部署及查询
processDefinition;
import java.io.InputStream;
import java.util.List;
import java.util.zip.ZipInputStream;
import ine.ProcessEngine;
import ine.ProcessEngines;
import pository.Deployment;
import pository.ProcessDefinition;
import org.junit.Test;
public class ProcessDefinitionTest {
ProcessEngine processEngine = DefaultProcessEngine();
@Autowired
private RepositoryService repositoryService;
/**
* 根据modelId部署模型
* @param modelId
* @param response
* @param request
* @return
*/
@RequestMapping("/deploy")
@ResponseBody
public Map deploy(final String modelId, HttpServletResponse response,final HttpServletRequest request) {
OperateTemplete templete = new HttpTemplete(request) {
protected void doSomething() throws BizException {
JSONObject result = new JSONObject();
try {
Model modelData = Model(modelId);
ObjectNode modelNode = (ObjectNode) new ObjectMapper().Id())); byte[] bpmnBytes = null;
BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
bpmnBytes = new BpmnXMLConverter().convertToXML(model);
String processName = Name() + ".l";
DeploymentBuilder db = ateDeployment().Name());
Deployment deployment = db.addString(processName, new String(bpmnBytes,"utf-8")).deploy();
} catch (Exception e) {
e.printStackTrace();
throw new BizException("部署失败");
}
}
};
return templete.operate();
}
/*
*部署流程定义(从classpath)
*/
@Test
public void deploymentProcessDefinition_classpath(){
Deployment deployment = RepositoryService()//与流程定义和部署对象相关的Service
.createDeployment()//创建⼀个部署对象
.name("流程定义")//添加部署名称
.addClasspathResource("diagrams/HelloWorld.bpmn")//从classpath的资源中加载,⼀次只能加载⼀个⽂件
.addClasspathResource("diagrams/HelloWorld.png")
.deploy();//完成部署
.deploy();//完成部署
System.out.println("部署ID:"+Id());
System.out.println("部署名称:"+Name());
}
/*
*部署流程定义(从zip)
*/
@Test
public void deploymentProcessDefinition_zip(){
InputStream in = Class().getClassLoader().getResourceAsStream("diagrams/HelloWorld.zip");
ZipInputStream zipInputStream = new ZipInputStream(in);
Deployment deployment = RepositoryService()//与流程定义和部署对象相关的Service
.createDeployment()//创建⼀个部署对象
.name("流程定义")//添加部署名称
.addZipInputStream(zipInputStream)//完成zip⽂件的部署
.deploy();//完成部署
System.out.println("部署ID:"+Id());
System.out.println("部署名称:"+Name());
}
createprocessa/*
* 查询流程定义
*/
@Test
public void findProcessDefinition(){
List<ProcessDefinition> list = RepositoryService()//与流程定义和部署对象相关的Service
.createProcessDefinitionQuery()//创建⼀个流程定义查询
/*指定查询条件,where条件*/
//.deploymentId(deploymentId)//使⽤部署对象ID查询
//.processDefinitionId(processDefinitionId)//使⽤流程定义ID查询
//.processDefinitionKey(processDefinitionKey)//使⽤流程定义的KEY查询
//.processDefinitionNameLike(processDefinitionNameLike)//使⽤流程定义的名称模糊查询
/*排序*/
.orderByProcessDefinitionVersion().asc()//按照版本的升序排列
//.orderByProcessDefinitionName().desc()//按照流程定义的名称降序排列
.list();//返回⼀个集合列表,封装流程定义
//.singleResult();//返回唯⼀结果集
//.count();//返回结果集数量
//.listPage(firstResult, maxResults)//分页查询
if(list != null && list.size()>0){
for(ProcessDefinition processDefinition:list){
System.out.println("流程定义ID:"+Id());//流程定义的key+版本+随机⽣成数
System.out.println("流程定义名称:"+Name());//对应HelloWorld.bpmn⽂件中的name属性值
System.out.println("流程定义的key:"+Key());//对应HelloWorld.bpmn⽂件中的id属性值
System.out.println("流程定义的版本:"+Version());//当流程定义的key值相同的情况下,版本升级,默认从1开始 System.out.println("资源名称bpmn⽂件:"+ResourceName());
System.out.println("资源名称png⽂件:"+DiagramResourceName());
System.out.println("部署对象ID:"+DeploymentId());
System.out.println(">>>>>>##");
}
}
}
}
相关的表:
select * from act_re_model;#模型表
SELECT * FROM activiti.act_re_deployment a; #部署对象表
SELECT * FROM activiti.act_re_procdef a; #流程定义表
SELECT * FROM activiti.act_ge_bytearray a;# 资源⽂件表
SELECT * FROM activiti.act_ge_property a; #主键⽣成策略表
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论