1. What is the process instance
Participants (which may be user may be a program) initiates a process in accordance with the process definition content, which is a process instance is dynamic;
Process definitions and examples illustrate the process:
2. Start the process instance
Process definition deployed after activiti, you can go to manage the implementation of the process by activiti in the system execution flow represents a flow of execution; such systems leave after deployment process, if a user wants to apply for leave then you need to perform this process, If another user must leave the application have to perform this process, each performed independently of each other, each performing a separate process instances;
com.wn Package;
Import org.activiti.engine.ProcessEngine;
Import org.activiti.engine.ProcessEngines;
Import org.activiti.engine.RuntimeService;
Import org.activiti.engine.runtime.ProcessInstance;
/ * process instance is started
* ` act_hi_actinst` has started and finished the event information
* `act_hi_identitylink` history participant information
*` act_hi_procinst` process instance
* `act_hi_taskinst` historical task instance
*` act_ru_execution` task execution information
* `act_ru_identitylink` current task execution participant
*` act_ru_task` task information
*
* * /
public class StartInstance {
public static void main (String [] args) {
// Get the ProcessEngine
the ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine ();
// Get the object RuntimeService
RuntimeService runtimeService = processEngine.getRuntimeService ();
// create a process instance
the ProcessInstance hoilday = runtimeService.startProcessInstanceByKey ( " hoilday " );
// output instance information
System . OUT .println ( " Get deployment process ID: " + hoilday.getDeploymentId ());
the System. OUT .println ( " Get process instance ID: " +hoilday.getId ());
. the System OUT .println ( " Get process activity ID: " + hoilday.getActivityId ());
}
}
3.BusinessKey (service identification)
When the process instance is started, it will be performed businessKey businessKey stored in the execution table of the process instance act_ru_execution;
BusinessKey: service identifier, typically the primary key of the table service, the business process instance identification and correspondence; service identifier from the service system; storage service identifier is used to associate data query service system according to the service identifier;
For example: leave the process to start a process instance, it can leave the single id as the service identifier stored activiti in future queries activiti the process instance can get leave single id obtained information leave form from association inquiry service system database ;
com.wn.activiti Package;
Import org.activiti.engine.ProcessEngine;
Import org.activiti.engine.ProcessEngines;
Import org.activiti.engine.RuntimeService;
Import org.activiti.engine.TaskService;
Import org.activiti.engine. task.Task;
/ * associated business process instance is started and the system * /
public class StartInstance {
public static void main (String [] args) {
// Get the processEngine
the processEngine processEngine = ProcessEngines.getDefaultProcessEngine ();
// get a RuntimeService objects
RuntimeService = runtimeService processEngine.getRuntimeService ();
//Generation process
runtimeService.startProcessInstanceByKey ( " hoilday " , " . 1 " );
// submitted for approval by the process leave
TaskService TaskService = processEngine.getTaskService ();
the Task Task . TaskService.createTaskQuery = () TaskAssignee ( " zhangsan " ) .processDefinitionKey ( " hoilday " ) .singleResult ();
// task approval
taskService.complete (task.getId ());
}
}
4. query process instance
State may flow during operation of the query process instance, operating current node information;
package com.wn.activiti;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import java.util.List;
public class QueryProcessInstance {
public static void main(String[] args) {
//获取processEngine对象
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//流程定义
String processDefinitionKeu="hoilday";
//获取RuntimeService
RuntimeService runtimeService = processEngine.getRuntimeService();
List<ProcessInstance> list=runtimeService
.createProcessInstanceQuery()
.processDefinitionKey(processDefinitionKeu)
.list();
for (ProcessInstance processInstance:list){
System.out.println(" ");
System.out.println("流程实例id:"
+ processInstance.getProcessInstanceId()); System.out.println("所属流程定义id:"
+ ProcessInstance.getProcessDefinitionId ());
System. OUT .println ( " whether complete: " + processInstance.isEnded ());
System. OUT .println ( " Are pause: " + processInstance.isSuspended ());
. System OUT .println ( " current activity represented: " + processInstance.getActivityId ());
}
}
}
5. Suspend the activation process instance
Some cases may be due to process changes you need to pause the currently running processes, rather than delete, suspend the process will not be executed;
5.1 All pending process instance
Operation process is defined as a suspended state, giant process definition below all process instances all suspended;
Pending the filling process is defined as the process definition will be allowed to start a new process instance, while all of this process definition process instances will all hang suspended;
com.wn.activiti Package;
Import org.activiti.engine.ProcessEngine;
Import org.activiti.engine.ProcessEngines;
Import org.activiti.engine.RepositoryService;
Import org.activiti.engine.repository.ProcessDefinition;
/ * all process instances suspend * /
public class AllSuspend {
public static void main (String [] args) {
// Get the processEngine
the processEngine processEngine = ProcessEngines.getDefaultProcessEngine ();
// Get the object RepositoryService
RepositoryService RepositoryService = processEngine.getRepositoryService ();
// Get process definition
. ProcessDefinition hoilday = repositoryService.createProcessDefinitionQuery () processDefinitionKey ( " hoilday " ) .singleResult ();
// get the current process definition whether the suspended state suspended the method is true is suspended, suspended method is false is running
boolean suspended = hoilday .isSuspended ();
IF (Suspended) {
repositoryService.activateProcessDefinitionById (hoilday.getId (), to true , null );
. the System OUT .println ( " the activation process definition " );
} the else {
repositoryService.suspendProcessDefinitionById (hoilday.getId ( ),to true , null );
. the System OUT .println ( " the process definition suspension " );
}
}
}
Single process instance is suspended 5.2
Operation process instance object, perform suspend operations for a single process, a process instance is suspended this process does not proceed to complete the current mandate of the process instance will report anomalies;
com.wn.activiti Package;
Import org.activiti.engine.ProcessEngine;
Import org.activiti.engine.ProcessEngines;
Import org.activiti.engine.RepositoryService;
Import org.activiti.engine.RuntimeService;
Import org.activiti.engine. runtime.ProcessInstance;
/ * a single process instance is suspended * /
/ * act_hi_taskinst * /
public class SingleSuspend {
public static void main (String [] args) {
// Get the object processEngine
the processEngine processEngine = ProcessEngines.getDefaultProcessEngine ();
// Get RuntimeService objects
RuntimeService = RuntimeService processEngine.getRuntimeService ();
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery () processInstanceId (. " 32501 " ) .singleResult ();
// get the current process definition whether the suspended state suspended to true method is to run on behalf of the pause false the
Boolean Suspended = processInstance.isSuspended ();
IF (Suspended) {
runtimeService.activateProcessInstanceById ( " 32501 " );
. the System OUT .println ( " leave activation process " );
} the else {
runtimeService.suspendProcessInstanceById ( " 32501 " );
the System. OUT .println ( " leave Suspend Process " );
}
}
}