activiti 7 + springboot2 (five) to deploy a test process

A deployment process definition , the code stickers

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.junit.Test;

public class ActivitiTest {

    /**
     * 部署流程
     */
    @Test
    public void deploy(){
        //创建ProcessEngineConfiguration对象
        ProcessEngineConfiguration configuration = ProcessEngineConfiguration
                .createProcessEngineConfigurationFromResource("activiti.cfg.xml");
        // Create an object ProcessEngine 
        ProcessEngine processEngine = configuration.buildProcessEngine ();
         // get RepositoryService example 
        RepositoryService RepositoryService = processEngine.getRepositoryService ();
         // deploy 
        the Deployment Deployment = repositoryService.createDeployment () 
                .addClasspathResource ( "Processes / diagram_1.bpmn" )   // add bpmn resources 
                .addClasspathResource ( "processes / diagram_1.png" ) 
                .name ( "absence form process" ) 
                the .deploy (); 

        System.out.println (deployment.getName ()); 
        System.out.println (deployment.getId ());
    }

}
activiti.cfg.xml see springboot2 + activiti 7 integration (c) project and create the table structure dependent on configuration
run is complete, open the database to see the data flow definition table ACT_RE_PROCDEF, you can see  activiti  will be specified in the code top  bpm  and picture files stored in the database.

 Two start a process instance

/ ** 
* start a process instance
* /
@Test
public void startProcessInstance () {
the ProcessEngine processEngine getProcessEngine = ();
RuntimeService runtimeService processEngine.getRuntimeService = ();
the ProcessInstance = runtimeService.startProcessInstanceByKey instance ( "myProcess_1");

the System.out. println ( "process instance ID:" + instance.getId ());
System.out.println ( "process definition ID:" + instance.getProcessDefinitionId ());
}

public getProcessEngine the ProcessEngine () {
// create objects ProcessEngineConfiguration
ProcessEngineConfiguration configuration ProcessEngineConfiguration =
.createProcessEngineConfigurationFromResource ( "activiti.cfg.xml");
// create an object ProcessEngine
return configuration.buildProcessEngine();
}

After running, open the Task node table ACT_RU_TASK runtime

   A process started up.

 Three tasks inquiry

After the process starts, the head of Calvary task can query their current tasks need to be addressed, check out the user's tasks are to-do tasks

/ ** 
* Query the user's task list
* /
@Test
public void taskQuery () {
the ProcessEngine processEngine = getProcessEngine ();

TaskService TaskService = processEngine.getTaskService ();

// be implemented according to the current user process definition key, the person in charge assignee the task list query
list <task> list = taskService.createTaskQuery ()
.processDefinitionKey ( "myProcess_1")
.taskAssignee ( "tom")
.list ();

IF (! = null && list.size list ()> 0) {
for (the task task: List) {
System.out.println ( "task ID:" + task.getId ());
System.out.println ( "task name:" + task.getName ());
the System.out. println ( "created task:" + task.getCreateTime ());
System.out.println("任务的办理人:"+task.getAssignee());
System.out.println("流程实例ID:"+task.getProcessInstanceId());
System.out.println("执行对象ID:"+task.getExecutionId());
System.out.println("流程定义ID:"+task.getProcessDefinitionId());
System.out.println("getOwner:"+task.getOwner());
System.out.println("getCategory:"+task.getCategory());
System.out.println("getDescription:"+task.getDescription());
System.out.println("getFormKey:"+task.getFormKey());
Map<String, Object> map = task.getProcessVariables();
for (Map.Entry<String, Object> m : map.entrySet()) {
System.out.println("key:" + m.getKey() + " value:" + m.getValue());
}
for (Map.Entry<String, Object> m : task.getTaskLocalVariables().entrySet()) {
System.out.println("key:" + m.getKey() + " value:" + m.getValue());
}

}
}
}

Four to complete the task 

    / ** 
     * task 
     * / 
    @Test 
    public  void the completeTask () {
         // task ID 
        String taskld = "2505" ; 
        the ProcessEngine processEngine = getProcessEngine (); 
        TaskService TaskService = processEngine.getTaskService (); 
        taskService.complete (taskld); 
        System.out.println ( "task: task ID:" + taskld); 
    }

 The entire process completed later:

Guess you like

Origin www.cnblogs.com/zsg88/p/12165902.html