簡易プロセステスト(レビューへの導入)(2)

4916 ワード

	/**
	 *   : 
	 * @title: test 
	 * @param 
	 * @return void  
	 * @date 2015-7-4    zp
	 */
	public void test(){
		  // Deploy the process definition
		repositoryService.createDeployment().addClasspathResource("/com/future/sem/resource/activiti/diagrams/testGW.bpmn").deploy();

	    // Start a process instance
	    String procId = runtimeService.startProcessInstanceByKey("financialReport").getId();
	   
	    List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("accountancy").list();
	    for (Task task : tasks) {
	      System.out.println("Following task is available for accountancy group: " + task.getName());

	      // claim it
	      taskService.claim(task.getId(), "fozzie");
	    }

	    // Verify Fozzie can now retrieve the task
	    tasks = taskService.createTaskQuery().taskAssignee("fozzie").list();
	    for (Task task : tasks) {
	      System.out.println("Task for fozzie: " + task.getName());

	      // Complete the task
	      taskService.complete(task.getId());
	    }

	    System.out.println("Number of tasks for fozzie: "
	            + taskService.createTaskQuery().taskAssignee("fozzie").count());

	    // Retrieve and claim the second task
	    tasks = taskService.createTaskQuery().taskCandidateGroup("management").list();
	    for (Task task : tasks) {
	      System.out.println("Following task is available for accountancy group: " + task.getName());
	      taskService.claim(task.getId(), "kermit");
	    }

	    // Completing the second task ends the process
	    for (Task task : tasks) {
	      taskService.complete(task.getId());
	    }
	   
	    HistoricProcessInstance historicProcessInstance =
	      historyService.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult();
	    System.out.println("Process instance end time: " + historicProcessInstance.getEndTime());
	    
	    List listh2 = historyService.createHistoricDetailQuery()
	    .formProperties()
	    .processInstanceId(procId)
	    .orderByVariableName().asc()
	    .list();	    
	}


導入プロセス定義

/**
 *  
 */
@Test
public void deploymentProcessDefinition() {
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    Deployment deployment = processEngine.getRepositoryService()//  Service
            .createDeployment() //  
            .name("activiti").addClasspathResource("helloworld.bpmn")//  classpath 
            .addClasspathResource("helloworld.png").deploy(); //  

    System.out.println("ID: " + deployment.getId());
    System.out.println("name: " + deployment.getName());
}

ここでRepositoryService導入プロセスを使用してaddClasspathResourceを定義すると、クラスパスからリソースファイルがロードされ、一度に1つのファイルしかロードできません.

プロセスインスタンスの起動

/**
 *  
 */
@Test
public void startProcessInstance() {
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    String processDefinitionKey = "helloworld";
    ProcessInstance pi = processEngine.getRuntimeService()
            .startProcessInstanceByKey(processDefinitionKey);

    System.out.println(" ID:" + pi.getId());
    System.out.println(" ID:" + pi.getProcessDefinitionId());
}

ここではRuntimeServiceを使用してプロセスインスタンスを起動します.

個人タスクの表示

/**
 *  
 */
@Test
public void findMyPersonTask() {
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    String assignee = " ";
    List<Task> list = processEngine.getTaskService().createTaskQuery()
            .taskAssignee(assignee).list();
    for (Task task : list) {
        System.out.println(task.getId());
        System.out.println(task.getName());
        System.out.println(task.getCreateTime());
        System.out.println(task.getAssignee());
    }
}

TaskServiceを使用してタスクを完了するクエリー
個人的な任務を果たす
/**
 *  
 */
@Test
public void completeMyPersonTask() {
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    String taskId = "104";
    processEngine.getTaskService().complete(taskId);

    System.out.println(" :" + taskId);
}

ここで使用
TaskService
任務の遂行