JBPM4.4笔记

来源:互联网 发布:java比较日期是否相同 编辑:程序博客网 时间:2024/05/16 15:58

             JBPM笔记


一、工作流概述及jBPM4.4安装应用

1、概念

A、流程定义--类模板

B、流程实例---对像

C、状态State---流程处于等等待环节,需要外部干预。

D、动作--->流程运转的过程中,特定事件发生时候,执行的程序。

E、流程上下文变量-->某一个流程实例流转的过程中,产生的特定数据。

F、 参与者actor-->什么人会参与到流程(角色/具体的人)--用户

G、活动

Acitivity-->流程中的一个步骤(自动,人工)

H、活动的所有者--》

I、工作项,任务Task。


2、jbpm4.4简单应用

ant的脚本文件buil.xml

A、确保ant能用,在命令行执行ant命令,通过设置path来实现.

B、把录前目录切换到E:\software\java\workflow\jbpm-4.4\jbpm-4.4\install

C、执行ant demo.setup.tomcat (之前需要修改build.xml文件,改成自己的tocmat版本号  <property name="tomcat.version" value="6.0.29" />,把对应的tomcat.zip包拷到download目录)

D、如果自动启动不了tomcat,则手动从解压tomcat目录中启动tomcat

E、http://localhost:8080/jbpm-console  进入控制台,体验jbpm的基本功能。

Username  Password

alex  password

mike  password

peter  password

mary  password


F、流程设置器 http://localhost:8080/jbpmeditor/p/explorer--体系jBPM流程图绘制


G、ant hsqldb.databasemanager  查看数据库信息



二、流程设计器GPD---把jPDL文件解析成图形化,量个eclipse插件。

1、安装gpd插件

2、配置gpd的shceme文件,实现智能提示。




三、在项目中使用(1)

把jBPM应用到我们项目中,画流程定义的图。


1、如何在项目在项目引入jbpm


ant create.user.webapp

生成jbpm最小的jar包及配置文件等等.


产生lib下的jar包

classes下的jbpm默认配置文件


jbpm.cfg.xml==>jbmp的配置文件

jbpm.hibernate.cfg.xml==>hibernata配置文件


2、初始化jbpm

@Test

 public void jbpmInit() {

   //获得JBPM流程引擎

   ProcessEngine engine=new Configuration().buildProcessEngine();

}



3、如何发布一个我们绘好的流程


//部署流程---

 @Test

 public void deployProcess(){

   //流程引擎

   ProcessEngine engine=new Configuration().buildProcessEngine();

   //得到一个流程定义管理的Service

   RepositoryService repositoryService= engine.getRepositoryService();

   //创建一个新的流程定义

   NewDeployment nd=repositoryService.createDeployment();

   nd.setName("请假流程");

   //指定流程定义文件

   nd.addResourceFromClasspath("leave.jpdl.xml");

   //把流程部署到系统

   nd.deploy();

   //System.out.println(nd.getName());

 }

 /**

  * 根据zip文件来部署流程

  */

 @Test

 public void deployProcess2(){

   //流程引擎

   ProcessEngine engine=new Configuration().buildProcessEngine();

   //得到一个流程定义管理的Service

   RepositoryService repositoryService= engine.getRepositoryService();

   //创建一个新的流程定义

   NewDeployment nd=repositoryService.createDeployment();

   nd.setName("请假流程");

   //指定流程定义文件

   nd.addResourcesFromZipInputStream(new ZipInputStream(this.getClass().getResourceAsStream("/leave.zip")));

   //把流程部署到系统

   nd.deploy();

   //System.out.println(nd.getName());

 }



4、如何起动(发起)一个流程

@Test

 public void startProcessInstance(){

   ProcessEngine engine=new Configuration().buildProcessEngine();

   ExecutionService eservice=engine.getExecutionService();

   eservice.startProcessInstanceById("kkk-1");

 }


四、jBPM在项目中的应用(2)

1、概念

部署Deployment==*.jpdl.xml文件及*.jpg文件.

流程定义(ProducessDefinition)===>流程定义xml文件中读取

几个属性:

name-->流程名称

key--->区别其它的流程开始实行

version-->流程版本号

流程id-->key-版本号,比如leave-1。系统中不有id相同的流程。



流程实例--->ProcessInstance---起动



 public String start() {

   ExecutionService executionService = JbpmUtil.getEngine().getExecutionService();

   executionService.startProcessInstanceByKey(pdkey);

   return "goList";

 }


流程执行executions --->每个流程实例至少会产生一个。



流程实例运行状态查询


public String view() {

   ExecutionService executionService = JbpmUtil.getEngine().getExecutionService();

   //根据流程实例的id获得流程实例

    ProcessInstance pi= executionService.findProcessInstanceById(id);

    RepositoryService reposSerivice= JbpmUtil.getEngine().getRepositoryService();

    //根据流程定义的id来获取流程定义对象

   ProcessDefinition  pd=reposSerivice.createProcessDefinitionQuery().processDefinitionId(pi.getProcessDefinitionId()).uniqueResult();



    //String state= pi.getState();

   //获得当前流程实例的位置,活动节点的名称

    String activityName= pi.findActiveActivityNames().iterator().next();

    System.out.println(activityName);

    //获得某一个活动的坐标值

    ActivityCoordinates ac= reposSerivice.getActivityCoordinates(pd.getId(), activityName);


    ActionContext.getContext().put("pi",pi);

    ActionContext.getContext().put("pd",pd);

    ActionContext.getContext().put("ac",ac);

   return "view";

 }

 public String showImg() throws Exception {

   ExecutionService executionService = JbpmUtil.getEngine().getExecutionService();

    RepositoryService reposSerivice= JbpmUtil.getEngine().getRepositoryService();


   //根据流程实例的id获得流程实例

   ProcessInstance pi= executionService.findProcessInstanceById(id);

   ProcessDefinition  pd=reposSerivice.createProcessDefinitionQuery().processDefinitionId(pi.getProcessDefinitionId()).uniqueResult();

   //获得流程部署包中的图片文件数据

   InputStream in= reposSerivice.getResourceAsStream(pd.getDeploymentId(), pd.getImageResourceName());


   HttpServletResponse response= ServletActionContext.getResponse();

   response.setContentType("image/png");

   //读出流中图片信息,并输出到客户端

   OutputStream out=response.getOutputStream();

   byte[] buffer=new byte[1024];

   int len=-1;

   while((len=in.read(buffer))>0){

   out.write(buffer, 0, len);  

   }

   in.close();

   out.close();


   return null;


 }


让流程往下一步走


public String next() {

   ExecutionService executionService = JbpmUtil.getEngine().getExecutionService();

    ProcessInstance pi= executionService.findProcessInstanceById(id);

    //给流程实例发送信号,他就往下走

   executionService.signalExecutionById(pi.getId());

   return "goList";

 }



0 0
原创粉丝点击