Jbpm4.3 学习笔记一

Jbpm4.3 学习笔记(一)

 

 

1.       jbpm创建数据库

package com.langsi.jbpm;

 

import org.jbpm.api.Configuration;

import org.jbpm.api.ProcessEngine;

 

public class Test1 {

       /**

        * 创建JBPM数据库表

        */

       public static void main(String[] args) {

             

              Configuration configuration = new Configuration();

              //创建流程引擎

              @SuppressWarnings("unused")

              ProcessEngine processEngine = configuration.buildProcessEngine();

       }

 

}

 

2 流程一first.jpdl.xml

2.1 流程定义文件

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

<process name="first" xmlns="http://jbpm.org/4.3/jpdl">

   <start g="222,38,48,48" name="start1">

      <transition g="-59,-17" name="to state1" to="state1"/>

   </start>

   <state g="197,174,92,52" name="state1">

      <transition name="to end1" to="end1" g="-47,-17"/>

   </state>

   <end g="220,350,48,48" name="end1"/>

</process>

2.2 流程图first.png

2.3 部署程序

package com.langsi.jbpm;

 

import org.jbpm.api.Configuration;

import org.jbpm.api.NewDeployment;

import org.jbpm.api.ProcessEngine;

import org.jbpm.api.RepositoryService;

 

public class Test2 {

 

       /**

        * 完成流程的部署功能

        */

       public static void main(String[] args) {

              //1、创建JBPM配置对象

              Configuration configuration = new Configuration();

              //2、创建流程引擎

              ProcessEngine processEngine = configuration.buildProcessEngine();

              //3、获得数据仓库服务对象

              RepositoryService repositoryService =  processEngine.getRepositoryService();

              //4、创建部署实例对象

              NewDeployment newDeployment  = repositoryService.createDeployment();

              //5、从类路径下面增加流程部署文件到部署实例对象

              newDeployment = newDeployment.addResourceFromClasspath("first.jpdl.xml");

              //6完成流程的部署

              String processNameString = newDeployment.deploy();            

              System.out.println(processNameString);            

       }

}

 

2.4 获取流程定义

package com.langsi.jbpm;

 

import java.util.Iterator;

import java.util.List;

 

import org.jbpm.api.Configuration;

import org.jbpm.api.NewDeployment;

import org.jbpm.api.ProcessDefinition;

import org.jbpm.api.ProcessEngine;

import org.jbpm.api.RepositoryService;

 

public class Test3 {

       /**

        * 完成流程的执行

        */

       public static void main(String[] args) {

              // 1、创建JBPM配置对象

              Configuration configuration = new Configuration();

              // 2、创建流程引擎

              ProcessEngine processEngine = configuration.buildProcessEngine();

              // 3、获得数据仓库服务对象

              RepositoryService repositoryService = processEngine

                            .getRepositoryService();

              // 4、创建部署实例对象

              NewDeployment newDeployment = repositoryService.createDeployment();

              // 5、从类路径下面增加流程部署文件到部署实例对象

              newDeployment = newDeployment

                            .addResourceFromClasspath("first.jpdl.xml");

              // 6完成流程的部署

              newDeployment.deploy();

              //7RepositoryService创建流程定义查询接口

              List<ProcessDefinition> list = repositoryService

                            .createProcessDefinitionQuery().list();

              for (Iterator<ProcessDefinition> iterator = list.iterator(); iterator.hasNext();) {

                     ProcessDefinition processDefinition = (ProcessDefinition) iterator

                                   .next();

                     System.out.println(processDefinition.getDeploymentId()+"---"

                                   +processDefinition.getId()+"---"+processDefinition.getName());

              }

       }

}

 

2.5 流程开始执行

package com.langsi.jbpm;

 

import org.jbpm.api.Configuration;

import org.jbpm.api.ExecutionService;

import org.jbpm.api.ProcessEngine;

import org.jbpm.api.ProcessInstance;

 

public class Test4 {

       public static void main(String[] args) {

              // 1、创建JBPM配置对象

              Configuration configuration = new Configuration();

              // 2、创建流程引擎

              ProcessEngine processEngine = configuration.buildProcessEngine();

              //3、获得流程执行服务对象

              ExecutionService executionService = processEngine.getExecutionService();

              //4、流程执行服务对象根据流程定义执行,获得流程实例

              ProcessInstance processInstance = executionService.startProcessInstanceByKey("first");

              System.out.println("processInstance Id " +processInstance.getId());

       }

}

 

2.6 流程执行下一步

package com.langsi.jbpm;

import org.jbpm.api.Configuration;

import org.jbpm.api.ExecutionService;

import org.jbpm.api.NewDeployment;

import org.jbpm.api.ProcessEngine;

import org.jbpm.api.ProcessInstance;

import org.jbpm.api.RepositoryService;

 

public class Test5 {

       public static void main(String[] args) {

              //1、创建JBPM配置对象

              Configuration configuration = new Configuration();

              //2、创建流程引擎

              ProcessEngine processEngine = configuration.buildProcessEngine();

              //3、获得数据仓库服务对象

              RepositoryService repositoryService =  processEngine.getRepositoryService();

              //4、创建部署实例对象

              NewDeployment newDeployment  = repositoryService.createDeployment();

              //5、从类路径下面增加流程部署文件到部署实例对象

              newDeployment = newDeployment.addResourceFromClasspath("first.jpdl.xml");

              //6完成流程的部署

              newDeployment.deploy();

              //7、获得流程执行服务对象

              ExecutionService executionService = processEngine.getExecutionService();

              //8、流程执行服务对象根据流程定义执行,得到流程实例

              ProcessInstance processInstance = executionService.startProcessInstanceByKey("first");

              //9、使用流程执行服务对象触发流程实例往下一节点走,产生一个新的流程实例对象

              ProcessInstance processInstance2 = executionService.signalExecutionById(processInstance.getId());       

              System.out.println(processInstance2.isEnded());

       }

}

 

3 secondprocess.jpdl.xml 第二个流程

3.1 流程定义文件secondprocess.jpdl.xml

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

<process name="secondprocess" xmlns="http://jbpm.org/4.3/jpdl">

   <start name="start1" g="272,38,48,48">

      <transition name="to state1" to="state1" g="-59,-17"/>

   </start>

   <state name="state1" g="419,90,92,52">

      <transition name="to state2" to="state2" g="-59,-17"/>

   </state>

   <state name="state2" g="526,202,92,52">

      <transition name="to state3" to="state3" g="-59,-17"/>

   </state>

   <state name="state3" g="440,355,92,52">

      <transition name="to end1" to="end1" g="-47,-17"/>

   </state>

    <end name="end1" g="339,428,48,48"/>

</process>

3.2 流程图

3.3 流程测试

package com.langsi.jbpm;

import org.jbpm.api.Configuration;

import org.jbpm.api.ExecutionService;

import org.jbpm.api.NewDeployment;

import org.jbpm.api.ProcessEngine;

import org.jbpm.api.ProcessInstance;

import org.jbpm.api.RepositoryService;

 

public class Test6 {

       public static void main(String[] args) {       

              //1、创建JBPM配置对象

              Configuration configuration = new Configuration();

              //2、创建流程引擎

              ProcessEngine processEngine = configuration.buildProcessEngine();

              //3、获得数据仓库服务对象

              RepositoryService repositoryService =  processEngine.getRepositoryService();

              //4、创建部署实例对象

              NewDeployment newDeployment  = repositoryService.createDeployment();

              //5、从类路径下面增加流程部署文件到部署实例对象

              newDeployment = newDeployment.addResourceFromClasspath("secondprocess.jpdl.xml");

              //6完成流程的部署

              newDeployment.deploy();

              //7、获得流程执行服务对象

              ExecutionService executionService = processEngine.getExecutionService();

              //8、流程执行服务对象根据流程定义执行,得到流程实例

              ProcessInstance processInstance = executionService.startProcessInstanceByKey("secondprocess");

              //9、使用流程执行服务对象触发流程实例往下一节点走,产生一个新的流程实例对象

              processInstance = executionService.signalExecutionById(processInstance.getId());

              processInstance = executionService.signalExecutionById(processInstance.getId());

              processInstance = executionService.signalExecutionById(processInstance.getId());         

              System.out.println(processInstance.isEnded());

       }

}

 

3.4 删除流程

package com.langsi.jbpm;

 

import org.jbpm.api.Configuration;

import org.jbpm.api.ExecutionService;

import org.jbpm.api.NewDeployment;

import org.jbpm.api.ProcessEngine;

import org.jbpm.api.ProcessInstance;

import org.jbpm.api.RepositoryService;

 

public class Test7 {

       /**

        * 流程实例的删除

        * @param args

        */

       public static void main(String[] args) {

              //1、创建JBPM配置对象

              Configuration configuration = new Configuration();

              //2、创建流程引擎

              ProcessEngine processEngine = configuration.buildProcessEngine();

              //3、获得数据仓库服务对象

              RepositoryService repositoryService =  processEngine.getRepositoryService();

              //4、创建部署实例对象

              NewDeployment newDeployment  = repositoryService.createDeployment();

              //5、从类路径下面增加流程部署文件到部署实例对象

              newDeployment = newDeployment.addResourceFromClasspath("secondprocess.jpdl.xml");

              //6完成流程的部署

              newDeployment.deploy();

              //7、获得流程执行服务对象

              ExecutionService executionService = processEngine.getExecutionService();

              //8、流程执行服务对象根据流程定义执行,得到流程实例

              ProcessInstance processInstance = executionService.startProcessInstanceByKey("secondprocess");        

              //删除流程实例对象

              executionService.deleteProcessInstance(processInstance.getId());             

       }

}

 

 

4 第三个流程 thirdprocess.jpdl.xml

4.1 流程定义

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

<process name="thirdprocess" xmlns="http://jbpm.org/4.3/jpdl">

   <start name="start1" g="332,116,48,48">

      <transition name="to state1" to="state1" g="-59,-17"/>

   </start>

   <end name="end1" g="333,364,48,48"/>

   <state name="state1" g="456,265,92,52">

      <on event="start">

         <event-listener class="com.langsi.event.MyEventListener"/>

      </on>

      <on event="end">

         <event-listener class="com.langsi.event.MyEventListener"/>

      </on>

      <transition name="to end1" to="end1" g="-47,-17"/>

   </state>

</process>

4.2 流程图

4.3 相关事件

package com.langsi.event;

import org.jbpm.api.listener.EventListener;

import org.jbpm.api.listener.EventListenerExecution;

 

@SuppressWarnings("serial")

public class MyEventListener implements EventListener {

       @Override

       public void notify(EventListenerExecution execution) throws Exception {

              System.out.println("-------------------------------------"+execution.getId());

       }

}

 

4.4 测试流程

package com.langsi.jbpm;

import org.jbpm.api.Configuration;

import org.jbpm.api.ExecutionService;

import org.jbpm.api.NewDeployment;

import org.jbpm.api.ProcessEngine;

import org.jbpm.api.ProcessInstance;

import org.jbpm.api.RepositoryService;

 

public class Test8 {

       /**

        * 增加事件

        * @param args

        */

       public static void main(String[] args) {

                     //1、创建JBPM配置对象

                     Configuration configuration = new Configuration();

                     //2、创建流程引擎

                     ProcessEngine processEngine = configuration.buildProcessEngine();

                     //3、获得数据仓库服务对象

                     RepositoryService repositoryService =  processEngine.getRepositoryService();

                     //4、创建部署实例对象

                     NewDeployment newDeployment  = repositoryService.createDeployment();

                     //5、从类路径下面增加流程部署文件到部署实例对象

                     newDeployment = newDeployment.addResourceFromClasspath("thirdprocess.jpdl.xml");

                     //6完成流程的部署

                     newDeployment.deploy();

                     //7、获得流程执行服务对象

                     ExecutionService executionService = processEngine.getExecutionService();

                     //8、流程执行服务对象根据流程定义执行,得到流程实例

                     ProcessInstance processInstance = executionService.startProcessInstanceByKey("thirdprocess");                  

                     executionService.signalExecutionById(processInstance.getId());

       }

}

 

5 流程四 fourthprocess.jpdl.xml

5.1 定义文件

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

 

<process name="fourthprocess" xmlns="http://jbpm.org/4.3/jpdl">

   <start name="start1" g="242,62,48,48">

      <transition name="to task1" to="task1" g="-53,-17"/>

   </start>

   <end name="end1" g="246,393,48,48"/>

   <task name="task1" g="237,220,92,52" assignee="zhangsan">

      <transition name="to end1" to="end1" g="-47,-17"/>

   </task>

 

</process>

 

5.2 流程图

5.3 测试流程

package com.langsi.jbpm;

 

import java.util.List;

 

import org.jbpm.api.Configuration;

import org.jbpm.api.ExecutionService;

import org.jbpm.api.NewDeployment;

import org.jbpm.api.ProcessEngine;

import org.jbpm.api.ProcessInstance;

import org.jbpm.api.RepositoryService;

import org.jbpm.api.TaskService;

import org.jbpm.api.task.Task;

 

//任务与事件

public class Test9 {

      

       public static void main(String[] args) {

             

              //1、创建JBPM配置对象

              Configuration configuration = new Configuration();

              //2、创建流程引擎

              ProcessEngine processEngine = configuration.buildProcessEngine();

              //3、获得数据仓库服务对象

              RepositoryService repositoryService =  processEngine.getRepositoryService();

              //4、创建部署实例对象

              NewDeployment newDeployment  = repositoryService.createDeployment();

              //5、从类路径下面增加流程部署文件到部署实例对象

              newDeployment = newDeployment.addResourceFromClasspath("fourthprocess.jpdl.xml");

              //6完成流程的部署

              newDeployment.deploy();

              //7、获得流程执行服务对象

              ExecutionService executionService = processEngine.getExecutionService();

              //8、流程执行服务对象根据流程定义执行,得到流程实例

              ProcessInstance processInstance = executionService.startProcessInstanceByKey("fourthprocess");

             

              System.out.println(processInstance.findActiveActivityNames());

             

              // 得到任务处理服务对象

              TaskService taskService = processEngine.getTaskService();

              List<Task> tasks = taskService.findPersonalTasks("zhangsan");

              System.out.println(tasks.size());

             

              //完成任务实例,taskService.completeTasktaskId

              Task task = tasks.iterator().next();

              taskService.completeTask(task.getId());

       }

}

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值