I. Process Deployment (archive mode)
/** * Archive of deployed process */ @Test public void deploymentByZip () { // Get the object processEngine the ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine (); // get a target RepositoryService RepositoryService RepositoryService = processEngine.getRepositoryService (); // define an input stream, Zip file loading the InputStream = inputStream the this . . getClass () getClassLoader () the getResourceAsStream ( "BPMN / holiday.zip." ); // define a target ZIPInputStream ZipInputStream ZipInputStream = new new ZipInputStream (inputStream); // process deployment deployment deploy = repositoryService.createDeployment() .addZipInputStream(zipInputStream) .name ( "Request Approval Process" ) .key("holidayKey") .deploy(); System.out.println ( "Process Name:" + deploy.getName ()); }
II. Process Definition View
/** * Check process definition information */ @Test public void getProDef () { // Get the object processEngine the ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine (); // get a target RepositoryService RepositoryService RepositoryService = processEngine.getRepositoryService (); // get the process definition view object ProcessDefinitionQuery ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery ( ); // specified viewing process processDefinitionKey () key value in the designated process definition in accordance with the sort process definition orderByProcessDefinitionVersion version List <ProcessDefinition> holiday = processDefinitionQuery.processDefinitionKey ( "myProcess_1").orderByProcessDefinitionVersion().desc().list(); for (ProcessDefinition proDef:holiday) { System.out.println ( "process definition ID:" + proDef.getId ()); System.out.println ( "process definition name:" + proDef.getName ()); System.out.println ( "process definition Key:" + proDef.getKey ()); System.out.println ( "process definition version:" + proDef.getVersion ()); } }
III. Process Delete
/** * Delete process: * Assuming When you delete, currently have the process instance, it will result in removal failed * If mandatory, you can use repositoryService.deleteDeployment ( "1", true) ; true representatives cascade delete * / @Test public void deleteDeployment () { // Get the object processEngine the ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine (); // get a target RepositoryService RepositoryService RepositoryService = processEngine.getRepositoryService (); // removal process repositoryService.deleteDeployment ( ". 1", to true ); }
IV. Gets resource information database processes
rely:
<dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.5</version> <scope>test</scope> </dependency>
/** * Read the resource from the data file to a local */ @Test public void the getResource () throws IOException { // Get the object processEngine the ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine (); // get a target RepositoryService RepositoryService RepositoryService = processEngine.getRepositoryService (); // Get the object to process the query ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery (); // get into the flow of resources processDefinitionQuery.processDefinitionKey ( "myProcess_1" ); // get a single result ProcessDefinition processDefinition =processDefinitionQuery.singleResult (); // process deployment ID String deploymentId = processDefinition.getDeploymentId (); // acquired bpmnResource the InputStream bpmnStream = repositoryService.getResourceAsStream (deploymentId, processDefinition.getResourceName ()); // acquired PNG the InputStream pngStream = repositoryService.getResourceAsStream (deploymentId, processDefinition.getDiagramResourceName ()); // build the output stream the OutputStream bpmnOut = new new a FileOutputStream ( "E: the Test \\ \\" + processDefinition.getResourceName ()); PNGOUT the OutputStream = new new a FileOutputStream ( "E: the Test \\ \\" + processDefinition.getDiagramResourceName ()); // the output data to the disk which IOUtils.copy (bpmnStream, bpmnOut); IOUtils.copy(pngStream,pngOut); // off flow pngOut.close (); bpmnOut.close(); pngStream.close(); bpmnStream.close(); }
Implementation of the results:
V. business systems and processes associated with the system
/** * System startup associated process instance and Business * Normal data should first add them to business table, the primary key ID to get the current data is added, start the process by example, the primary key ID to BuessniessKkey * On behalf of associated systems and processes */ @Test public void startInstance(){ /** * Let Joe Smith submitted the page, and then get ID */ /** * Create an instance of the process leave Joe Smith * / // Get the object processEngine the ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine (); RuntimeService runtimeService = processEngine.getRuntimeService(); //生成流程 ProcessInstance holiday = runtimeService.startProcessInstanceByKey("myProcess_1","2"); /** * Joe Smith submitted for approval to leave * / // get a TaskService objects TaskService TaskService = processEngine.getTaskService (); // get the seating of the task . Task Task = taskService.createTaskQuery () TaskAssignee ( "zhangsan") processDefinitionKey ( "myProcess_1." ) .SingleResult () ; // task approval taskService.complete (task.getId ()); }
VI. Process activation and hangs
1. All pending process definition
/** * All pending process definition */ @Test public void allSuspend () { // Get the object processEngine the ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine (); // Get the object RepositoryService the RepositoryService RepositoryService = processEngine.getRepositoryService (); // Get the process definition ProcessDefinition holiday = repositoryService.createProcessDefinitionQuery () processDefinitionKey ( . "myProcess_1" ) .singleResult (); // Get the current process if the suspend state is defined as the true representative of the method is suspended to suspend the operation is false Boolean suspended = holiday.isSuspended (); iF (suspended) { repositoryService.activateProcessDefinitionById(holiday.getId(),true,null); System.out.println ( "defines the flow activation" ); }else{ repositoryService.suspendProcessDefinitionById(holiday.getId(),true,null); System.out.println ( "The Process Definition pause" ); } }
Executed again
2. A single process instance pending
/** * A single process instance pending */ @Test public void singleSuspend () { // Get the object processEngine the ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine (); // Get the object RuntimeService RuntimeService runtimeService = processEngine.getRuntimeService (); ProcessInstance ProcessInstance . = RuntimeService.createProcessInstanceQuery () processInstanceId ( "22501" ) .singleResult (); // get the current process definition whether the suspended state suspended the method is true representatives pause is running false boolean suspended = processInstance.isSuspended () ; IF (Suspended) { runtimeService.activateProcessInstanceById("22501"); System.out.println ( "XX leave the activation process" ); }else{ runtimeService.suspendProcessInstanceById("22501"); System.out.println ( "XX leave the suspend process" ); } }
Trying to process the pending procedure
Report an error