Java Code Examples for org.activiti.bpmn.model.Process#addFlowElement()

The following examples show how to use org.activiti.bpmn.model.Process#addFlowElement() . 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: EventJavaTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testStartEventWithExecutionListener() throws Exception {
  BpmnModel bpmnModel = new BpmnModel();
  Process process = new Process();
  process.setId("simpleProcess");
  process.setName("Very simple process");
  bpmnModel.getProcesses().add(process);
  StartEvent startEvent = new StartEvent();
  startEvent.setId("startEvent1");
  TimerEventDefinition timerDef = new TimerEventDefinition();
  timerDef.setTimeDuration("PT5M");
  startEvent.getEventDefinitions().add(timerDef);
  ActivitiListener listener = new ActivitiListener();
  listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
  listener.setImplementation("${test}");
  listener.setEvent("end");
  startEvent.getExecutionListeners().add(listener);
  process.addFlowElement(startEvent);
  UserTask task = new UserTask();
  task.setId("reviewTask");
  task.setAssignee("kermit");
  process.addFlowElement(task);
  SequenceFlow flow1 = new SequenceFlow();
  flow1.setId("flow1");
  flow1.setSourceRef("startEvent1");
  flow1.setTargetRef("reviewTask");
  process.addFlowElement(flow1);
  EndEvent endEvent = new EndEvent();
  endEvent.setId("endEvent1");
  process.addFlowElement(endEvent);

  byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel);

  new BpmnXMLConverter().validateModel(new InputStreamSource(new ByteArrayInputStream(xml)));

  Deployment deployment = repositoryService.createDeployment().name("test").addString("test.bpmn20.xml", new String(xml)).deploy();
  repositoryService.deleteDeployment(deployment.getId());
}
 
Example 4
Source File: EventJavaTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testStartEventWithExecutionListener() throws Exception {
  BpmnModel bpmnModel = new BpmnModel();
  Process process = new Process();
  process.setId("simpleProcess");
  process.setName("Very simple process");
  bpmnModel.getProcesses().add(process);
  StartEvent startEvent = new StartEvent();
  startEvent.setId("startEvent1");
  TimerEventDefinition timerDef = new TimerEventDefinition();
  timerDef.setTimeDuration("PT5M");
  startEvent.getEventDefinitions().add(timerDef);
  ActivitiListener listener = new ActivitiListener();
  listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
  listener.setImplementation("${test}");
  listener.setEvent("end");
  startEvent.getExecutionListeners().add(listener);
  process.addFlowElement(startEvent);
  UserTask task = new UserTask();
  task.setId("reviewTask");
  task.setAssignee("kermit");
  process.addFlowElement(task);
  SequenceFlow flow1 = new SequenceFlow();
  flow1.setId("flow1");
  flow1.setSourceRef("startEvent1");
  flow1.setTargetRef("reviewTask");
  process.addFlowElement(flow1);
  EndEvent endEvent = new EndEvent();
  endEvent.setId("endEvent1");
  process.addFlowElement(endEvent);
  
  byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel);
  
  new BpmnXMLConverter().validateModel(new InputStreamSource(new ByteArrayInputStream(xml)));
  
  Deployment deployment = repositoryService.createDeployment().name("test").addString("test.bpmn20.xml", new String(xml))
      .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE)
      .deploy();
  repositoryService.deleteDeployment(deployment.getId());
}
 
Example 5
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 6
Source File: SimpleWorkflowTest.java    From maven-framework-project with MIT License 4 votes vote down vote up
@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 = this.repositoryService.createDeployment()
            .addBpmnModel("dynamic-model.bpmn", model).name("Dynamic process deployment")
            .deploy();

    // 3. Deploy the process to the engine
    deployment = this.repositoryService.createDeployment()
            .addBpmnModel("dynamic-model.bpmn", model).name("Dynamic process deployment")
            .deploy();

    // 4. Start a process instance
    ProcessInstance processInstance = runtimeService
            .startProcessInstanceByKey("my-process");

    // 5. Check if task is available
    List<Task> tasks = taskService.createTaskQuery()
            .processInstanceId(processInstance.getId()).list();

    assertEquals(1, tasks.size());
    assertEquals("First task", tasks.get(0).getName());
    assertEquals("fred", tasks.get(0).getAssignee());

    // 6. Save process diagram to a file
    InputStream processDiagram = repositoryService
            .getProcessDiagram(processInstance.getProcessDefinitionId());
    FileUtils.copyInputStreamToFile(processDiagram, new File("target/diagram.png"));
    // 7. Save resulting BPMN xml to a file
    InputStream processBpmn = repositoryService
            .getResourceAsStream(deployment.getId(), "dynamic-model.bpmn");
    FileUtils.copyInputStreamToFile(processBpmn,
            new File("target/process.bpmn20.xml"));
}
 
Example 7
Source File: DocApproveTest.java    From maven-framework-project with MIT License 4 votes vote down vote up
@Test
    public void testDynamicDeploy() throws Exception {
        String fakeGroup = "fakeGroup";
        String procId = Workflow.PROCESS_ID_DOC_APPROVAL + "-" + fakeGroup;
        // 1. Build up the model from scratch
        BpmnModel model = new BpmnModel();
        Process process = new Process();
        model.addProcess(process);
        process.setId(procId);

        process.addFlowElement(createStartEvent());

        //pub.addAttribute(createExpression("documentWorkflow.publish(execution)"));
        //pub.setImplementation("${documentWorkflow.publish(execution)}");
//        pub.setExtensionId(BpmnXMLConstants.ACTIVITI_EXTENSIONS_NAMESPACE,
//                BpmnXMLConstants.ATTRIBUTE_TASK_SERVICE_EXTENSIONID);


        UserTask submitTask = new UserTask();
        submitTask.setId("submitDocUserTask");
        submitTask.setName("Submit Document for Approval");
        process.addFlowElement(submitTask);
        process.addFlowElement(createSequenceFlow("start", submitTask.getId()));
        SubProcess sub = createSubProcess();
        process.addFlowElement(sub);

        process.addFlowElement(createSequenceFlow(submitTask.getId(), sub.getId()));

        BoundaryEvent boundaryEvent = new BoundaryEvent();
        boundaryEvent.setId("rejectedErrorBoundaryEvent");
        boundaryEvent.setName("Rejected Error Event");
        boundaryEvent.setAttachedToRef(sub);
        ErrorEventDefinition errorDef = new ErrorEventDefinition();
        errorDef.setErrorCode("errorDocRejected");
        boundaryEvent.addEventDefinition(errorDef);
        process.addFlowElement(boundaryEvent);

        process.addFlowElement(createSequenceFlow(boundaryEvent.getId(), submitTask.getId(), "Rejected"));
        ServiceTask pub = new ServiceTask();
        pub.setId("publishDocServiceTask");
        pub.setName("Publish Approved Document");
        pub.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
        pub.setImplementation("${documentWorkflow.publish(execution)}");

        process.addFlowElement(pub);
        process.addFlowElement(createSequenceFlow(sub.getId(), pub.getId()));

        process.addFlowElement(createEndEvent());
        process.addFlowElement(createSequenceFlow(pub.getId(), "end"));

        // 2. Generate graphical information
        new BpmnAutoLayout(model).execute();

        // 3. Deploy the process to the engine
        Deployment deployment = this.repositoryService.createDeployment()
                .addBpmnModel("dynamic-model.bpmn", model).name("Dynamic process deployment")
                .deploy();

        // 4. Start a process instance
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(procId);

        // 6. Save process diagram to a file
        InputStream processDiagram = repositoryService.getProcessDiagram(processInstance.getProcessDefinitionId());
        FileUtils.copyInputStreamToFile(processDiagram, new File("target/diagram.png"));

        // 7. Save resulting BPMN xml to a file
        InputStream processBpmn = repositoryService.getResourceAsStream(deployment.getId(), "dynamic-model.bpmn");
        FileUtils.copyInputStreamToFile(processBpmn, new File("target/process.bpmn20.xml"));
    }