ca88官方会员登录jBPM学习之动API完成流程实例。jBPM学习之用API完成流程实例。

流程引擎对象ProcessEngine是jBPM4所有的Service
API之源。在jBPM4受到各种服务相互依存,但具备的Service
API都由ProcessEngine中得到,由此可见ProcessEngine是jBPM4工作流API的着力。ProcessEngine是出于Configuration类构建的,即工作流引擎根据配置有。ProcessEngine是线程安全的,因此他得以确保存在静态变量中。

流程引擎对象ProcessEngine是jBPM4所有的Service
API之源。在jBPM4惨遭各种劳动相互依存,但所有的Service
API都于ProcessEngine中收获,由此可见ProcessEngine是jBPM4工作流API的中坚。ProcessEngine是出于Configuration类构建的,即工作流引擎根据部署起。ProcessEngine是线程安全的,因此他可以确保存在静态变量中。

用,我们好把获得ProcessEngine的代码编写如下:

之所以,我们得以拿收获ProcessEngine的代码编写如下:

package com.springchang.jbpm01;

import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.junit.Test;

public class MyTest01 {
    private static ProcessEngine processEngine; //直接将流程引擎写成静态变量

    //静态代码块,获取processEngine
    static {
        Configuration cfg = new Configuration();
        cfg.setResource("jbpm.cfg.xml");  
        processEngine = cfg.buildProcessEngine();
    }

    // 1,部署流程定义文档
    @Test
    public void testDeployProcessDefinition() throws Exception {
        String deploymentId = processEngine.getRepositoryService() //调用processEngine提供的接口
                .createDeployment()
                .addResourceFromClasspath("com/springchang/jbpm01/HelloWorld.jpdl.xml") //加载HelloWorld.jpdl.xml文件
                .addResourceFromClasspath("com/springchang/jbpm01/HelloWorld.png")      //加载Helloworld.png图片
                .deploy(); //发布流程定义
        System.out.println(deploymentId);
    }

}
package com.springchang.jbpm01;

import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.junit.Test;

public class MyTest01 {
    private static ProcessEngine processEngine; //直接将流程引擎写成静态变量

    //静态代码块,获取processEngine
    static {
        Configuration cfg = new Configuration();
        cfg.setResource("jbpm.cfg.xml");  
        processEngine = cfg.buildProcessEngine();
    }

    // 1,部署流程定义文档
    @Test
    public void testDeployProcessDefinition() throws Exception {
        String deploymentId = processEngine.getRepositoryService() //调用processEngine提供的接口
                .createDeployment()
                .addResourceFromClasspath("com/springchang/jbpm01/HelloWorld.jpdl.xml") //加载HelloWorld.jpdl.xml文件
                .addResourceFromClasspath("com/springchang/jbpm01/HelloWorld.png")      //加载Helloworld.png图片
                .deploy(); //发布流程定义
        System.out.println(deploymentId);
    }

}

若本节的重大是调用jBPM4.4饱受加以的各种API,从流程的发起,部署,办理任务到历史任务查询等一律密密麻麻的操作。首先,流程定义如图所示:
ca88官方会员登录 1

一经本节的重中之重是调用jBPM4.4遭加以的各种API,从流水线的发起,部署,办理任务到历史任务查询等一律多元之操作。首先,流程定义如图所示:
ca88官方会员登录 2

对应的jPDL:

对应的jPDL:

<?xml version="1.0" encoding="UTF-8"?>

<process name="process" xmlns="http://jbpm.org/4.4/jpdl">
   <start g="118,16,48,48" name="start1">
      <transition g="-66,-22" name="to state1" to="state1"/>
   </start>
   <!-- state活动是等待活动,需要收到一个外部的执行信号才能流转通过 -->
   <state g="96,96,92,52" name="state1">
      <transition g="-60,-22" name="to task1" to="task1"/>
   </state>
   <!-- task活动是等待活动,在这里被分配给用户Spring Chang办理,Spring Chang办理完成提交任务后才能流转通过 -->
   <task assignee="Spring Chang" g="96,180,92,52" name="task1">
      <transition g="-57,-22" name="to end1" to="end1"/>
   </task>
   <end g="118,264,48,48" name="end1"/>
</process>
<?xml version="1.0" encoding="UTF-8"?>

<process name="process" xmlns="http://jbpm.org/4.4/jpdl">
   <start g="118,16,48,48" name="start1">
      <transition g="-66,-22" name="to state1" to="state1"/>
   </start>
   <!-- state活动是等待活动,需要收到一个外部的执行信号才能流转通过 -->
   <state g="96,96,92,52" name="state1">
      <transition g="-60,-22" name="to task1" to="task1"/>
   </state>
   <!-- task活动是等待活动,在这里被分配给用户Spring Chang办理,Spring Chang办理完成提交任务后才能流转通过 -->
   <task assignee="Spring Chang" g="96,180,92,52" name="task1">
      <transition g="-57,-22" name="to end1" to="end1"/>
   </task>
   <end g="118,264,48,48" name="end1"/>
</process>

采取jBPM Service API发起并就地方名也process的流程定义。代码如下:

采用jBPM Service API发起并成功地方名也process的流程定义。代码如下:

package com.springchang.jbpm01;

import static org.junit.Assert.*;

import org.jbpm.api.Configuration;
import org.jbpm.api.Execution;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.api.history.HistoryTask;
import org.jbpm.api.task.Task;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class ProcessTest {

    private ProcessEngine processEngine;

    private String deploymentId;

    @Before
    public void setUp() throws Exception {
        processEngine = Configuration.getProcessEngine();
        deploymentId = processEngine.getRepositoryService().createDeployment()
                     .addResourceFromClasspath("com/springchang/jbpm01/process.jpdl.xml")
                     .addResourceFromClasspath("com/springchang/jbpm01/process.png")
                     .deploy();
    }

    @After
    public void tearDown() throws Exception {
        processEngine.getRepositoryService().deleteDeploymentCascade(deploymentId);
    }

    @Test
    public void test() {
        //使用执行任务,根据已经部署的名陈process,发起流程实例
        ProcessInstance processInstance = processEngine.getExecutionService().startProcessInstanceByKey("process");
        //获取流程实例id
        String pid = processInstance.getId();
        System.out.println("pid:" + pid);
        //获取当前活动的执行对象
        Execution executionInState = processInstance.findActiveExecutionIn("state1");
        //断言当前活动是state1
        assertNotNull(executionInState);
        //使用执行服务:发出执行信号结束当前活动,继续流程的执行
        String executionId = executionInState.getId();
        System.out.println("executionId:" + executionId);
        processEngine.getExecutionService().signalExecutionById(executionId);
        //使用执行服务:从持久化层中获取“最新”的流程实例对象
        processInstance = processEngine.getExecutionService().findProcessInstanceById(pid);
        //获取当前活动的执行对象
        Execution executionInTask = processInstance.findActiveExecutionIn("task1");
        //断言当前活动即为task
        assertNotNull(executionInTask);
        //使用任务服务:获取用户Spring Chang的任务,即task活动产生的任务
        Task task = processEngine.getTaskService().findPersonalTasks("Spring Chang").get(0);
        assertEquals("Spring Chang", task.getAssignee());
        //使用任务服务,完成任务
        processEngine.getTaskService().completeTask(task.getId());
        //使用历史服务:创建历史任务查询
        HistoryTask historyTask = processEngine.getHistoryService().createHistoryTaskQuery()
                                  .taskId(task.getId()).uniqueResult();
        //断言上一步完成的任务已经成为历史,即可通过历史任务查询获取到它
        assertNotNull(historyTask);
        //断言该流程已经结束
        //assertProcessInstanceEnded(pid);
        //使用历史服务:创建历史流程实例查询
        HistoryProcessInstance historyProcessInst = processEngine.getHistoryService()
                                                    .createHistoryProcessInstanceQuery()
                                                    .processInstanceId(pid)
                                                    .uniqueResult();
        //断言该流程已经成为历史,即可通过历史流程实例查询获取它
        assertNotNull(historyProcessInst);
    }
}
package com.springchang.jbpm01;

import static org.junit.Assert.*;

import org.jbpm.api.Configuration;
import org.jbpm.api.Execution;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.api.history.HistoryTask;
import org.jbpm.api.task.Task;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class ProcessTest {

    private ProcessEngine processEngine;

    private String deploymentId;

    @Before
    public void setUp() throws Exception {
        processEngine = Configuration.getProcessEngine();
        deploymentId = processEngine.getRepositoryService().createDeployment()
                     .addResourceFromClasspath("com/springchang/jbpm01/process.jpdl.xml")
                     .addResourceFromClasspath("com/springchang/jbpm01/process.png")
                     .deploy();
    }

    @After
    public void tearDown() throws Exception {
        processEngine.getRepositoryService().deleteDeploymentCascade(deploymentId);
    }

    @Test
    public void test() {
        //使用执行任务,根据已经部署的名陈process,发起流程实例
        ProcessInstance processInstance = processEngine.getExecutionService().startProcessInstanceByKey("process");
        //获取流程实例id
        String pid = processInstance.getId();
        System.out.println("pid:" + pid);
        //获取当前活动的执行对象
        Execution executionInState = processInstance.findActiveExecutionIn("state1");
        //断言当前活动是state1
        assertNotNull(executionInState);
        //使用执行服务:发出执行信号结束当前活动,继续流程的执行
        String executionId = executionInState.getId();
        System.out.println("executionId:" + executionId);
        processEngine.getExecutionService().signalExecutionById(executionId);
        //使用执行服务:从持久化层中获取“最新”的流程实例对象
        processInstance = processEngine.getExecutionService().findProcessInstanceById(pid);
        //获取当前活动的执行对象
        Execution executionInTask = processInstance.findActiveExecutionIn("task1");
        //断言当前活动即为task
        assertNotNull(executionInTask);
        //使用任务服务:获取用户Spring Chang的任务,即task活动产生的任务
        Task task = processEngine.getTaskService().findPersonalTasks("Spring Chang").get(0);
        assertEquals("Spring Chang", task.getAssignee());
        //使用任务服务,完成任务
        processEngine.getTaskService().completeTask(task.getId());
        //使用历史服务:创建历史任务查询
        HistoryTask historyTask = processEngine.getHistoryService().createHistoryTaskQuery()
                                  .taskId(task.getId()).uniqueResult();
        //断言上一步完成的任务已经成为历史,即可通过历史任务查询获取到它
        assertNotNull(historyTask);
        //断言该流程已经结束
        //assertProcessInstanceEnded(pid);
        //使用历史服务:创建历史流程实例查询
        HistoryProcessInstance historyProcessInst = processEngine.getHistoryService()
                                                    .createHistoryProcessInstanceQuery()
                                                    .processInstanceId(pid)
                                                    .uniqueResult();
        //断言该流程已经成为历史,即可通过历史流程实例查询获取它
        assertNotNull(historyProcessInst);
    }
}

上诉单元测试的代码setUp方法是布置流程定义,并调用addResourceFromClasspath方法加载流程实例文档ca88官方会员登录来部署流程定义。tearDown方法作用是剔除刚才部署的流水线定义,并将跟那个系的关联表的情节千篇一律并清空,主要的代码放在test测试方法里面。

上诉单元测试的代码setUp方法是部署流程定义,并调用addResourceFromClasspath方法加载流程实例文档来布局流程定义。tearDown方法作用是抹刚才部署之流程定义,并以和那个有关的关联表的情节一律连清空,主要的代码放在test测试方法里面。

相关文章

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图