package com.nantian.jbpm.utils;
import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.junit.Before;
public class BaseJbpm {
public static ProcessEngine processEngine;
@Before
public void testBase(){
this.processEngine = Configuration.getProcessEngine();
}
}
package com.nantian.jbpm.pi;
import java.util.List;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.history.HistoryTask;
import org.jbpm.api.task.Task;
import org.junit.Test;
import com.nantian.jbpm.utils.BaseJbpm;
/**
* Process instance
* * Start the process instance
* * mission accomplished
* * Inquire
* * Query process instance
** Query task
* * Query the task being executed
* * Query all running tasks
* * Query the task being executed according to the executor of the task
* * Query executing tasks based on executionId
* * Query executing tasks according to piid
* * Query executing tasks according to pdid
* * Query tasks according to taskid taskService.getTask(String taskId); different from other queries
* * Query completed tasks
** Query all
* * According to the executor of the task
* * According to executionID
* * .......
* * End the process instance
* @author Administrator
*
*/
public class PITest extends BaseJbpm{
/**
* Tables involved
* * JBPM4_EXECUTION
* * Indicates the currently executing process instance
** Field
* DBID_: primary key
* ID_: Process instance ID
* ACTIVITYNAME_: The active node of the current process instance
* PROCDEFID_: Process definition ID
* * JBPM4_HIST_PROCINST
* * Represents historical process instances, but currently running process instances are also here
** Field
* DBID_: primary key
* ID_: Process instance ID
* START_: The start time of the entire process instance
* END_: The end time of the process instance, if the process instance is the currently running process, the value is empty
* STATE: Indicates the state of the process instance. If it is running, it is active and if the process instance ends, it is ended
* * JBPM4_TASK
* * Indicates the currently executing task
* Description: The task is a node of the jbpm flow chart
** Field
* DBID_: primary key, task ID
* NAME_: task name
* ASSIGNEE_: The executor of the task
* * JBPM4_HIST_TASK
* * Represents historical tasks, but currently executing tasks are also here
** Field
* STATE_: If a task is completed, the value is completed
* end_: The end time of the task has a value
* * JBPM4_HIST_ACTINST
* * Node representing history
** Field
* TYPE_: node type
* illustrate:
* * When the process instance is started, it will automatically leave the start node and flow to the next node
* * jbpm4_task is a temporary table, when the current task is completed, the data will be deleted
*/
@Test
public void testStartPIByPDID(){
ProcessInstance pi = processEngine.getExecutionService()
.startProcessInstanceById("qingjia-1");
System.out.println(pi.getId());
System.out.println(pi.getState());
}
/**
* Start the process instance according to the pdkey, which is the highest version under this key
*/
@Test
public void testStartPIByPDKEY(){
processEngine.getExecutionService()
.startProcessInstanceByKey("qingjia1");
}
/**
* mission accomplished
*/
@Test
public void testFinishTask(){
processEngine.getTaskService()
.completeTask("130001");
}
/**
* Query all process instances
*/
@Test
public void testQueryAllPI(){
List<ProcessInstance> piList = processEngine.getExecutionService()
.createProcessInstanceQuery()
///.processDefinitionId("")//You can query process instances according to pdid, many
.list();
for(ProcessInstance pi:piList){
/**
* You can query piid, pdid, state, etc.
*/
}
}
/**
* Query all running tasks
*/
@Test
public void testQueryAllTask(){
List<Task> taskList = processEngine.getTaskService()
.createTaskQuery()
//.processDefinitionId("")
.list();
for(Task task:taskList){
System.out.println("assignee:"+task.getAssignee());
System.out.println("name:"+task.getName());
System.out.println("createtime:"+task.getCreateTime());
}
}
/**
* You can query the currently executing task according to the executor of the task
* You can query the currently executing task according to pdid
*/
@Test
public void testQueryTaskByPDID(){
List<Task> taskList = processEngine.getTaskService()
.createTaskQuery()
.processDefinitionId("qingjia1-4")
.list();
System.out.println(taskList.size());
}
/**
* Execution
* * If there is no concurrency, then execution and process instance are the same
* * If there is concurrency, execution represents the branch, and process instance represents the main line
* * Query tasks according to executionID, there is only one
*/
@Test
public void testQueryTaskByTaskID(){
Task task = processEngine.getTaskService()
.getTask("100002");
System.out.println(task.getName());
}
/**
* Query all tasks that have been completed
*/
@Test
public void testQueryAllHistTask(){
List<HistoryTask> histTaskList = processEngine.getHistoryService()
.createHistoryTaskQuery()
//.assignee("") can query the completed tasks according to the executor of the task
//.executionId("") can query completed tasks according to executionID
.state("completed")
.list();
for (HistoryTask histTask: histTaskList)
System.out.println(histTask.getEndTime());
}
}
/**
* Directly end the process instance
*/
@Test
public void testEndPI(){
processEngine.getExecutionService()
.endProcessInstance("qingjia.70001", "error");
}
/**
* Query the process instance according to piid, if the result of the query is null, it means that the process instance has ended
*/
@Test
public void testIsEndPI(){
ProcessInstance pi = processEngine.getExecutionService()
.createProcessInstanceQuery()
.processInstanceId("qingjia.70001")
.uniqueResult();
System.out.println(pi);//If the value is null, the process instance has ended
}
}