ProcessEngine processEngine=ProcessEngines.getDefaultProcessEngine();
/**部署流程定义(从inputStream)*/
@Test
public void deploymentProcess_inputstream(){
InputStream inputStreamBpmn = this.getClass().getResourceAsStream("start.bpmn");
InputStream inputStreamPng = this.getClass().getResourceAsStream("start.png");
Deployment deployment = processEngine.getRepositoryService()//与流程定义和部署对象相关的Service
.createDeployment()//创建一个部署对象
.name("开始活动")//添加部署的名称
.addInputStream("start.bpmn", inputStreamBpmn)//
.addInputStream("start.png", inputStreamPng)//
.deploy();//完成部署
System.out.println("部署ID:"+deployment.getId());// 部署ID:3201
System.out.println("部署名称:"+deployment.getName());// 部署名称:开始活动
}
// 启动流程实例
@Test
public void startProcessInstance(){
//流程定义的key
String processDefinitionKey = "myProcess";
ProcessInstance pit=processEngine.getRuntimeService()
.startProcessInstanceByKey(processDefinitionKey);
System.out.println("流程实例ID:"+pit.getId()); // 流程实例ID:3701
System.out.println("流程定义ID:"+pit.getProcessDefinitionId()); // 流程定义ID:myProcess:4:3204
/**判断流程是否结束,查询正在执行的执行对象表*/
ProcessInstance pi=processEngine.getRuntimeService()
.createProcessInstanceQuery() //创建流程实例查询对象
.processInstanceId(pit.getId())
.singleResult();
if(pi==null){
/**查询历史,获取流程的相关信息*/
HistoricProcessInstance hpi=processEngine.getHistoryService() //
.createHistoricProcessInstanceQuery()
.processInstanceId(pit.getId()) // 使用流程实例ID
.singleResult();
System.out.println(hpi.getId()+" "+hpi.getProcessDefinitionId()+" "+hpi.getStartTime()+" "+hpi.getEndTime());
}
/*
流程实例ID:3701
流程定义ID:myProcess:4:3204
/**部署流程定义(从inputStream)*/
@Test
public void deploymentProcess_inputstream(){
InputStream inputStreamBpmn = this.getClass().getResourceAsStream("start.bpmn");
InputStream inputStreamPng = this.getClass().getResourceAsStream("start.png");
Deployment deployment = processEngine.getRepositoryService()//与流程定义和部署对象相关的Service
.createDeployment()//创建一个部署对象
.name("开始活动")//添加部署的名称
.addInputStream("start.bpmn", inputStreamBpmn)//
.addInputStream("start.png", inputStreamPng)//
.deploy();//完成部署
System.out.println("部署ID:"+deployment.getId());// 部署ID:3201
System.out.println("部署名称:"+deployment.getName());// 部署名称:开始活动
}
// 启动流程实例
@Test
public void startProcessInstance(){
//流程定义的key
String processDefinitionKey = "myProcess";
ProcessInstance pit=processEngine.getRuntimeService()
.startProcessInstanceByKey(processDefinitionKey);
System.out.println("流程实例ID:"+pit.getId()); // 流程实例ID:3701
System.out.println("流程定义ID:"+pit.getProcessDefinitionId()); // 流程定义ID:myProcess:4:3204
/**判断流程是否结束,查询正在执行的执行对象表*/
ProcessInstance pi=processEngine.getRuntimeService()
.createProcessInstanceQuery() //创建流程实例查询对象
.processInstanceId(pit.getId())
.singleResult();
if(pi==null){
/**查询历史,获取流程的相关信息*/
HistoricProcessInstance hpi=processEngine.getHistoryService() //
.createHistoricProcessInstanceQuery()
.processInstanceId(pit.getId()) // 使用流程实例ID
.singleResult();
System.out.println(hpi.getId()+" "+hpi.getProcessDefinitionId()+" "+hpi.getStartTime()+" "+hpi.getEndTime());
}
/*
流程实例ID:3701
流程定义ID:myProcess:4:3204
3701 myProcess:4:3204 Thu Feb 22 11:37:54 CST 2018 Thu Feb 22 11:37:54 CST 2018
*/
}