Activiti Advanced API operations

Historical data query

  • Query process instance history list
HistoricProcessInstanceQuery query = pe.getHistoryService()
				.createHistoricProcessInstanceQuery();
List<HistoricProcessInstance> list = query.list();
for (HistoricProcessInstance hi : list) {
    System.out.println(hi.getId());
}
  • Query historical activity data
HistoricActivityInstanceQuery query = pe.getHistoryService()
				.createHistoricActivityInstanceQuery();
List<HistoricActivityInstance> list = query.list();
for (HistoricActivityInstance hi : list) {
    System.out.println(hi.getActivityId());
}
  • Query historical task data
HistoricTaskInstanceQuery query = pe.getHistoryService()
				.createHistoricTaskInstanceQuery();
List<HistoricTaskInstance> list = query.list();
for (HistoricTaskInstance hi : list) {
    System.out.println(hi.getAssignee());
}

Process variables

Setting process variables

  • Provided when starting a process instance
String processDefinitionKey = "variable";
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("key1", "value1");
variables.put("key2", 200);
ProcessInstance pi = pe.getRuntimeService().startProcessInstanceByKey(
        processDefinitionKey, variables);
System.out.println(pi.getId());
  • Set in the process of task
String taskId = "1206";
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("user", new User(1,"小王"));
pe.getTaskService().complete(taskId, variables);
  • Using the method provided RuntimeService
String executionId = "601";//流程实例id
String variableName = "key3";
Object value = "value3";
pe.getRuntimeService().setVariable(executionId , variableName , value);
  • Using the method provided TaskService
String taskId = "704";
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("key4", 400);
variables.put("k5", "v5");
pe.getTaskService().setVariables(taskId , variables);

Acquisition process variables

  • Use RuntimeService way to get
String executionId = "1201";
Map<String, Object> variables = pe.getRuntimeService().getVariables(executionId);
Set<String> set = variables.keySet();//key2 key1 user
for (String key : set) {
    Object value = variables.get(key);
    System.out.println(key + " = " + value);
}
  • Use TaskService way to get
String taskId = "1305";
Map<String, Object> variables = pe.getTaskService().getVariables(taskId );
System.out.println(variables);

task

  • Tasks are divided into individual tasks, common tasks, receiving task, individual tasks are performed by a single person, public tasks are performed by people, receiving tasks are performed by procedure call signal method (such as: text messages issued a notification process)
  • Public inquiry task
TaskQuery query = pe.getTaskService().createTaskQuery();
String candidateUser = "李四";
//根据候选人过滤
query.taskCandidateUser(candidateUser);
List<Task> list = query.list();
for (Task task : list) {
    System.out.println(task.getName());
}
  • Pick up the task (public task becomes personal tasks)
String taskId = "1602";
String userId = "王五";
pe.getTaskService().claim(taskId , userId);
  • Returns the job (personal tasks become common task)
String taskId = "1602";
pe.getTaskService().setAssignee(taskId , null);
  • Processing the received task
String executionId = "2101";
pe.getRuntimeService().signal(executionId );

Monitor

Execution listeners

  • ExecutionListener define a class that implements the interface, notify rewriting method, as follows
public class MyExecutionListener implements ExecutionListener {
	//当监听的事件发送时执行此方法
	public void notify(DelegateExecution execution) throws Exception {
		System.out.println("自定义的监听器执行了。");
	}
}
  • We just add a class defined in the design process when a listener

Task Listeners

  • TaskListener define a class that implements the interface, notify rewriting method, as follows
public class MyTaskListener implements TaskListener{
	//监听任务的事件
	public void notify(DelegateTask delegateTask) {
		String assignee = delegateTask.getAssignee();
		String eventName = delegateTask.getEventName();
		String name = delegateTask.getName();
		String processInstanceId = delegateTask.getProcessInstanceId();
		Set<String> variableNames = delegateTask.getVariableNames();
		for (String key : variableNames) {
			Object value = delegateTask.getVariable(key);
			System.out.println(key + " = " + value);
		}
		System.out.println("一个任务["+name+"]被创建了,由["+assignee+"]负责办理");
	}

}
Published 22 original articles · won praise 15 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_28566521/article/details/104003429