Java Code Examples for org.activiti.bpmn.model.BpmnModel#addProcess()

The following examples show how to use org.activiti.bpmn.model.BpmnModel#addProcess() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddBpmnModelTest.java    From CrazyWorkflowHandoutsActiviti6 with MIT License 7 votes vote down vote up
private static BpmnModel createProcessModel() {
	// 创建BPMN模型
	BpmnModel model = new BpmnModel();
	// 创建一个流程定义
	Process process = new Process();
	model.addProcess(process);
	process.setId("myProcess");
	process.setName("My Process");
	// 开始事件
	StartEvent startEvent = new StartEvent();
	startEvent.setId("startEvent");
	process.addFlowElement(startEvent);
	// 用户任务
	UserTask userTask = new UserTask();
	userTask.setName("User Task");
	userTask.setId("userTask");
	process.addFlowElement(userTask);
	// 结束事件
	EndEvent endEvent = new EndEvent();
	endEvent.setId("endEvent");
	process.addFlowElement(endEvent);		
	// 添加流程顺序
	process.addFlowElement(new SequenceFlow("startEvent", "userTask"));
	process.addFlowElement(new SequenceFlow("userTask", "endEvent"));
	return model;
}
 
Example 2
Source File: AddBpmnModelTest.java    From CrazyWorkflowHandoutsActiviti6 with MIT License 6 votes vote down vote up
private static BpmnModel createProcessModel() {
	// 创建BPMN模型
	BpmnModel model = new BpmnModel();
	// 创建一个流程定义
	Process process = new Process();
	model.addProcess(process);
	process.setId("myProcess");
	process.setName("My Process");
	// 开始事件
	StartEvent startEvent = new StartEvent();
	startEvent.setId("startEvent");
	process.addFlowElement(startEvent);
	// 用户任务
	UserTask userTask = new UserTask();
	userTask.setName("User Task");
	userTask.setId("userTask");
	process.addFlowElement(userTask);
	// 结束事件
	EndEvent endEvent = new EndEvent();
	endEvent.setId("endEvent");
	process.addFlowElement(endEvent);		
	// 添加流程顺序
	process.addFlowElement(new SequenceFlow("startEvent", "userTask"));
	process.addFlowElement(new SequenceFlow("userTask", "endEvent"));
	return model;
}
 
Example 3
Source File: AbstractActivitiTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Since the 'one task process' is used everywhere the actual process content doesn't matter, instead of copying around the BPMN 2.0 xml one could use this method which gives a {@link BpmnModel}
 * version of the same process back.
 */
public BpmnModel createOneTaskTestProcess() {
  BpmnModel model = new BpmnModel();
  org.activiti.bpmn.model.Process process = new org.activiti.bpmn.model.Process();
  model.addProcess(process);
  process.setId("oneTaskProcess");
  process.setName("The one task process");

  StartEvent startEvent = new StartEvent();
  startEvent.setId("start");
  process.addFlowElement(startEvent);

  UserTask userTask = new UserTask();
  userTask.setName("The Task");
  userTask.setId("theTask");
  userTask.setAssignee("kermit");
  process.addFlowElement(userTask);

  EndEvent endEvent = new EndEvent();
  endEvent.setId("theEnd");
  process.addFlowElement(endEvent);

  process.addFlowElement(new SequenceFlow("start", "theTask"));
  process.addFlowElement(new SequenceFlow("theTask", "theEnd"));

  return model;
}
 
Example 4
Source File: AbstractActivitiTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public BpmnModel createTwoTasksTestProcess() {
  BpmnModel model = new BpmnModel();
  org.activiti.bpmn.model.Process process = new org.activiti.bpmn.model.Process();
  model.addProcess(process);
  process.setId("twoTasksProcess");
  process.setName("The two tasks process");

  StartEvent startEvent = new StartEvent();
  startEvent.setId("start");
  process.addFlowElement(startEvent);

  UserTask userTask = new UserTask();
  userTask.setName("The First Task");
  userTask.setId("task1");
  userTask.setAssignee("kermit");
  process.addFlowElement(userTask);

  UserTask userTask2 = new UserTask();
  userTask2.setName("The Second Task");
  userTask2.setId("task2");
  userTask2.setAssignee("kermit");
  process.addFlowElement(userTask2);

  EndEvent endEvent = new EndEvent();
  endEvent.setId("theEnd");
  process.addFlowElement(endEvent);

  process.addFlowElement(new SequenceFlow("start", "task1"));
  process.addFlowElement(new SequenceFlow("start", "task2"));
  process.addFlowElement(new SequenceFlow("task1", "theEnd"));
  process.addFlowElement(new SequenceFlow("task2", "theEnd"));

  return model;
}
 
Example 5
Source File: TestProcessUtil.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static BpmnModel createTwoTasksBpmnModel() {
  BpmnModel model = new BpmnModel();
  org.activiti.bpmn.model.Process process = new org.activiti.bpmn.model.Process();
  model.addProcess(process);
  process.setId("twoTasksProcess");
  process.setName("The two tasks process");

  StartEvent startEvent = new StartEvent();
  startEvent.setId("start");
  process.addFlowElement(startEvent);

  UserTask userTask = new UserTask();
  userTask.setName("The First Task");
  userTask.setId("task1");
  userTask.setAssignee("kermit");
  process.addFlowElement(userTask);

  UserTask userTask2 = new UserTask();
  userTask2.setName("The Second Task");
  userTask2.setId("task2");
  userTask2.setAssignee("kermit");
  process.addFlowElement(userTask2);

  EndEvent endEvent = new EndEvent();
  endEvent.setId("theEnd");
  process.addFlowElement(endEvent);

  process.addFlowElement(new SequenceFlow("start", "task1"));
  process.addFlowElement(new SequenceFlow("start", "task2"));
  process.addFlowElement(new SequenceFlow("task1", "theEnd"));
  process.addFlowElement(new SequenceFlow("task2", "theEnd"));

  return model;
}
 
Example 6
Source File: DefaultProcessValidatorTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllNonExecutableProcesses() {
  BpmnModel bpmnModel = new BpmnModel();
  for (int i = 0; i < 5; i++) {
    org.activiti.bpmn.model.Process process = TestProcessUtil.createOneTaskProcess();
    process.setExecutable(false);
    bpmnModel.addProcess(process);
  }

  List<ValidationError> errors = processValidator.validate(bpmnModel);
  Assert.assertEquals(1, errors.size());
}
 
Example 7
Source File: SubprocessXMLConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private List<BpmnModel> parseSubModels(FlowElement subElement, Map<String, GraphicInfo> locations, 
                                       Map<String, List<GraphicInfo>> flowLocations, Map<String, GraphicInfo> labelLocations) {
  List<BpmnModel> subModels = new ArrayList<BpmnModel>();
  BpmnModel subModel = new BpmnModel();
  String elementId = null;

  // find nested subprocess models
  Collection<FlowElement> subFlowElements = ((SubProcess)subElement).getFlowElements();
  // set main process in submodel to subprocess
  Process newMainProcess = new Process();
  newMainProcess.setId(subElement.getId());
  newMainProcess.getFlowElements().addAll(subFlowElements);
  newMainProcess.getArtifacts().addAll(((SubProcess)subElement).getArtifacts());
  subModel.addProcess(newMainProcess);

  for (FlowElement element : subFlowElements) {
    elementId = element.getId();
    if (element instanceof SubProcess) {
      subModels.addAll(parseSubModels(element, locations, flowLocations, labelLocations));
    }
    
    if (element instanceof SequenceFlow && null != flowLocations.get(elementId)) {
      // must be an edge
      subModel.getFlowLocationMap().put(elementId, flowLocations.get(elementId));
    } else {
      // do not include data objects because they do not have a corresponding shape in the BPMNDI data
      if (!(element instanceof DataObject) && null != locations.get(elementId)) {
        // must be a shape
        subModel.getLocationMap().put(elementId, locations.get(elementId));
      }
    }
    // also check for any labels
    if (null != labelLocations.get(elementId)) {
      subModel.getLabelLocationMap().put(elementId, labelLocations.get(elementId));
    }
  }
  subModels.add(subModel);

  return subModels;
}
 
Example 8
Source File: AbstractActivitiTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Since the 'one task process' is used everywhere the actual process content
 * doesn't matter, instead of copying around the BPMN 2.0 xml one could use 
 * this method which gives a {@link BpmnModel} version of the same process back.
 */
public BpmnModel createOneTaskTestProcess() {
	BpmnModel model = new BpmnModel();
	org.activiti.bpmn.model.Process process = new org.activiti.bpmn.model.Process();
  model.addProcess(process);
  process.setId("oneTaskProcess");
  process.setName("The one task process");
 
  StartEvent startEvent = new StartEvent();
  startEvent.setId("start");
  process.addFlowElement(startEvent);
  
  UserTask userTask = new UserTask();
  userTask.setName("The Task");
  userTask.setId("theTask");
  userTask.setAssignee("kermit");
  process.addFlowElement(userTask);
  
  EndEvent endEvent = new EndEvent();
  endEvent.setId("theEnd");
  process.addFlowElement(endEvent);
  
  process.addFlowElement(new SequenceFlow("start", "theTask"));
  process.addFlowElement(new SequenceFlow("theTask", "theEnd"));
  
  return model;
}
 
Example 9
Source File: AbstractActivitiTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public BpmnModel createTwoTasksTestProcess() {
	BpmnModel model = new BpmnModel();
	org.activiti.bpmn.model.Process process = new org.activiti.bpmn.model.Process();
  model.addProcess(process);
  process.setId("twoTasksProcess");
  process.setName("The two tasks process");
 
  StartEvent startEvent = new StartEvent();
  startEvent.setId("start");
  process.addFlowElement(startEvent);
  
  UserTask userTask = new UserTask();
  userTask.setName("The First Task");
  userTask.setId("task1");
  userTask.setAssignee("kermit");
  process.addFlowElement(userTask);
  
  UserTask userTask2 = new UserTask();
  userTask2.setName("The Second Task");
  userTask2.setId("task2");
  userTask2.setAssignee("kermit");
  process.addFlowElement(userTask2);
  
  EndEvent endEvent = new EndEvent();
  endEvent.setId("theEnd");
  process.addFlowElement(endEvent);
  
  process.addFlowElement(new SequenceFlow("start", "task1"));
  process.addFlowElement(new SequenceFlow("start", "task2"));
  process.addFlowElement(new SequenceFlow("task1", "theEnd"));
  process.addFlowElement(new SequenceFlow("task2", "theEnd"));
  
  return model;
}
 
Example 10
Source File: TestProcessUtil.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static BpmnModel createTwoTasksBpmnModel() {
	BpmnModel model = new BpmnModel();
	org.activiti.bpmn.model.Process process = new org.activiti.bpmn.model.Process();
	model.addProcess(process);
	process.setId("twoTasksProcess");
	process.setName("The two tasks process");

	StartEvent startEvent = new StartEvent();
	startEvent.setId("start");
	process.addFlowElement(startEvent);

	UserTask userTask = new UserTask();
	userTask.setName("The First Task");
	userTask.setId("task1");
	userTask.setAssignee("kermit");
	process.addFlowElement(userTask);

	UserTask userTask2 = new UserTask();
	userTask2.setName("The Second Task");
	userTask2.setId("task2");
	userTask2.setAssignee("kermit");
	process.addFlowElement(userTask2);

	EndEvent endEvent = new EndEvent();
	endEvent.setId("theEnd");
	process.addFlowElement(endEvent);

	process.addFlowElement(new SequenceFlow("start", "task1"));
	process.addFlowElement(new SequenceFlow("start", "task2"));
	process.addFlowElement(new SequenceFlow("task1", "theEnd"));
	process.addFlowElement(new SequenceFlow("task2", "theEnd"));

	return model;
}
 
Example 11
Source File: DefaultProcessValidatorTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllNonExecutableProcesses() {
	BpmnModel bpmnModel = new BpmnModel();
	for (int i=0; i<5; i++) {
		org.activiti.bpmn.model.Process process = TestProcessUtil.createOneTaskProcess();
		process.setExecutable(false);
		bpmnModel.addProcess(process);
	}
	
	List<ValidationError> errors = processValidator.validate(bpmnModel);
	Assert.assertEquals(1, errors.size());
}
 
Example 12
Source File: TestProcessUtil.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * Since the 'one task process' is used everywhere the actual process content doesn't matter, instead of copying around the BPMN 2.0 xml one could use this method which gives a {@link BpmnModel}
 * version of the same process back.
 */
public static BpmnModel createOneTaskBpmnModel() {
  BpmnModel model = new BpmnModel();
  model.addProcess(createOneTaskProcess());
  return model;
}
 
Example 13
Source File: SubprocessXMLConverter.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected List<BpmnModel> parseSubModels(BpmnModel model) {
  List<BpmnModel> subModels = new ArrayList<BpmnModel>();

  // find all subprocesses
  Collection<FlowElement> flowElements = model.getMainProcess().getFlowElements();
  Map<String, GraphicInfo> locations = new HashMap<String, GraphicInfo>();
  Map<String, List<GraphicInfo>> flowLocations = new HashMap<String, List<GraphicInfo>>();
  Map<String, GraphicInfo> labelLocations = new HashMap<String, GraphicInfo>();

  locations.putAll(model.getLocationMap());
  flowLocations.putAll(model.getFlowLocationMap());
  labelLocations.putAll(model.getLabelLocationMap());

  // include main process as separate model
  BpmnModel mainModel = new BpmnModel();
  // set main process in submodel to subprocess
  mainModel.addProcess(model.getMainProcess());

  String elementId = null;
  for (FlowElement element : flowElements) {
    elementId = element.getId();
    if (element instanceof SubProcess) {
      subModels.addAll(parseSubModels(element, locations, flowLocations, labelLocations));
    }
    
    if (element instanceof SequenceFlow && null != flowLocations.get(elementId)) {
      // must be an edge
      mainModel.getFlowLocationMap().put(elementId, flowLocations.get(elementId));
    } else {
      // do not include data objects because they do not have a corresponding shape in the BPMNDI data
      if (!(element instanceof DataObject) && null != locations.get(elementId)) {
        // must be a shape
        mainModel.getLocationMap().put(elementId, locations.get(elementId));
      }
    }
    // also check for any labels
    if (null != labelLocations.get(elementId)) {
      mainModel.getLabelLocationMap().put(elementId, labelLocations.get(elementId));
    }
  }
  // add main process model to list
  subModels.add(mainModel);

  return subModels;
}
 
Example 14
Source File: DynamicProcess.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
@Test
public void testDynamicDeploy() throws Exception {
    // 1. 创建一个空的BpmnModel和Process对象
    BpmnModel model = new BpmnModel();
    Process process = new Process();
    model.addProcess(process);
    process.setId("my-process");

    // 创建Flow元素(所有的事件、任务都被认为是Flow)
    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. 流程图自动布局(位于activiti-bpmn-layout模块)
    new BpmnAutoLayout(model).execute();

    // 3. 把BpmnModel对象部署到引擎
    Deployment deployment = activitiRule.getRepositoryService().createDeployment()
            .addBpmnModel("dynamic-model.bpmn", model).name("Dynamic process deployment")
            .deploy();

    // 4. 启动流程
    ProcessInstance processInstance = activitiRule.getRuntimeService()
            .startProcessInstanceByKey("my-process");

    // 5. 检查流程是否正常启动
    List<Task> 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. 导出流程图
    InputStream processDiagram = activitiRule.getRepositoryService()
            .getProcessDiagram(processInstance.getProcessDefinitionId());
    // 把文件生成在本章项目的test-classes目录中
    String userHomeDir = getClass().getResource("/").getFile();
    System.out.println(userHomeDir);
    FileUtils.copyInputStreamToFile(processDiagram, new File(userHomeDir + "/diagram.png"));

    // 7. 导出Bpmn文件到本地文件系统
    InputStream processBpmn = activitiRule.getRepositoryService()
            .getResourceAsStream(deployment.getId(), "dynamic-model.bpmn");
    FileUtils.copyInputStreamToFile(processBpmn,
            new File(userHomeDir + "/process.bpmn20.xml"));
}
 
Example 15
Source File: TestProcessUtil.java    From activiti6-boot2 with Apache License 2.0 2 votes vote down vote up
/**
 * Since the 'one task process' is used everywhere the actual process content
 * doesn't matter, instead of copying around the BPMN 2.0 xml one could use
 * this method which gives a {@link BpmnModel} version of the same process
 * back.
 */
public static BpmnModel createOneTaskBpmnModel() {
	BpmnModel model = new BpmnModel();
	model.addProcess(createOneTaskProcess());
	return model;
}