动态创建activiti流程_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 动态创建activiti流程

动态创建activiti流程

 2013/9/15 21:46:17  lihao312  程序员俱乐部  我要评论(0)
  • 摘要:@TestpublicvoidtestDynamicDeploy()throwsException{//1.BuildupthemodelfromscratchBpmnModelmodel=newBpmnModel();Processprocess=newProcess();model.addProcess(process);process.setId("my-process");process.addFlowElement(createStartEvent());process
  • 标签:创建 流程
class="java" name="code">
@Test
public void testDynamicDeploy() throws Exception {
  // 1. Build up the model from scratch
  BpmnModel model = new BpmnModel();
  Process process = new Process();
  model.addProcess(process);
  process.setId("my-process");
 
  process.addFlowElement(createStartEvent());
  process.addFlowElement(createUserTask("task1", "First task", "fred"));
  process.addFlowElement(createUserTask("task2", "Second task", "john"));
  process.addFlowElement(createEndEvent());
 
  process.addFlowElement(createSequenceFlow("start", "task1"));
  process.addFlowElement(createSequenceFlow("task1", "task2"));
  process.addFlowElement(createSequenceFlow("task2", "end"));
 
  // 2. Generate graphical information
  new BpmnAutoLayout(model).execute();
 
  // 3. Deploy the process to the engine
  Deployment deployment = activitiRule.getRepositoryService().createDeployment()
    .addBpmnModel("dynamic-model.bpmn", model).name("Dynamic process deployment")
    .deploy();
 
  // 4. Start a process instance
  ProcessInstance processInstance = activitiRule.getRuntimeService()
    .startProcessInstanceByKey("my-process");
 
  // 5. Check if task is available
  List tasks = activitiRule.getTaskService().createTaskQuery()
    .processInstanceId(processInstance.getId()).list();
 
  Assert.assertEquals(1, tasks.size());
  Assert.assertEquals("First task", tasks.get(0).getName());
  Assert.assertEquals("fred", tasks.get(0).getAssignee());
 
  // 6. Save process diagram to a file  
  InputStream processDiagram = activitiRule.getRepositoryService()
    .getProcessDiagram(processInstance.getProcessDefinitionId());
  FileUtils.copyInputStreamToFile(processDiagram, new File("target/diagram.png"));
 
  // 7. Save resulting BPMN xml to a file
  InputStream processBpmn = activitiRule.getRepositoryService()
    .getResourceAsStream(deployment.getId(), "dynamic-model.bpmn");
  FileUtils.copyInputStreamToFile(processBpmn, 
    new File("target/process.bpmn20.xml"));
}
 
protected UserTask createUserTask(String id, String name, String assignee) {
  UserTask userTask = new UserTask();
  userTask.setName(name);
  userTask.setId(id);
  userTask.setAssignee(assignee);
  return userTask;
}
 
protected SequenceFlow createSequenceFlow(String from, String to) {
  SequenceFlow flow = new SequenceFlow();
  flow.setSourceRef(from);
  flow.setTargetRef(to);
  return flow;
}
 
protected StartEvent createStartEvent() {
  StartEvent startEvent = new StartEvent();
  startEvent.setId("start");
  return startEvent;
}
 
protected EndEvent createEndEvent() {
  EndEvent endEvent = new EndEvent();
  endEvent.setId("end");
  return endEvent;
}
上一篇: HTML解析组件HtmlAgilityPack使用 下一篇: 没有下一篇了!
发表评论
用户名: 匿名