activiti6.0 새 노드, 하나의activiti 5 공유.12 6.0.0의 새로운 노드 코드를 변경하고 사용하실 분 있으면 스스로 조정하세요.

5035 단어 activiti
activiti의 새로운 노드를 실현하고 5.12버전을 6.0.0버전으로 변경합니다
버전 5.12 코드
참조:https://blog.csdn.net/hj7jay/article/details/50848292
GITHUB 주소:https://github.com/frederikheremans/activiti-dynamic-process
다음은 제가 고친 6.0.0 버전의 코드입니다.
package cn.k12soft.servo.module.activiti.apply.service;

import junit.framework.Assert;
import org.activiti.bpmn.BpmnAutoLayout;
import org.activiti.bpmn.model.*;
import org.activiti.bpmn.model.Process;
import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@Transactional
public class DynamicActivitiProcessTest {

    public final TaskService taskService;
    public final RuntimeService runtimeService;
    public RepositoryService repositoryService;

    @Autowired
    public DynamicActivitiProcessTest(TaskService taskService,
                                      RuntimeService runtimeService,
                                      RepositoryService repositoryService
    ) {
        this.taskService = taskService;
        this.runtimeService = runtimeService;
        this.repositoryService = repositoryService;
    }

    /**
     *     
     */
    public void createDynamicDeploy(){
    // 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          
    //       
    ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
    //           
    //    repositoryService = engine.getRepositoryService();
    //       
    Deployment deployment = repositoryService.createDeployment()
              .addBpmnModel("dynamic-model.bpmn", model).name("Dynamic process deployment").deploy();

    //       
    ProcessDefinition pd = repositoryService.createProcessDefinitionQuery()
            .deploymentId(deployment.getId()).singleResult();

    // 4. Start a process instance         
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(pd.getId());

    // 5. Check if task is available         
    List tasks = taskService.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());
    
    try {
      // 6. Save process diagram to a file              
      InputStream processDiagram = repositoryService.getProcessDiagram(processInstance.getProcessDefinitionId());
      FileUtils.copyInputStreamToFile(processDiagram, new File("k12servo/src/main/resources/processes/diagram.png"));
        System.out.println(FileUtils.getTempDirectoryPath());


      // 7. Save resulting BPMN xml to a file     BPMN xml        
        InputStream processBpmn = repositoryService.getResourceAsStream(deployment.getId(), "dynamic-model.bpmn");
        FileUtils.copyInputStreamToFile(processBpmn, new File("k12servo/src/main/resources/processes/process.bpmn"));
        System.out.println(FileUtils.getTempDirectoryPath());

    } catch (IOException e) {
      e.printStackTrace();
    }

  }
  
  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;
  }
}

좋은 웹페이지 즐겨찾기