JBPM使用总结!

一、流程设计器的安装
1 启动myeclipse10 ---- 选择help-->MyEclipse Configuration Center-->Software;
2 左边Browse Software选择add site---->Add from Archive File
3 name写jbpm4.4 , url 写 ${jbpm4.4 解压目录}/install/src/jpd/jbpm-gpd-site.zip 文件路径 ,点击OK
4 左边Browse Software下会出现Personal Sites , 下面有个jbpm4 ,将下面8个组件分别右键 add to profile
5 这时候右下角Software Updates Available会出现你要安装的插件 ,拔掉网线后点击Apply change
6 安装完成后,会提醒是否重启Myeclipse
7 重启后在你的 window - preferences 中 多了一个JBoss jBPM

二、 整合Struts2.3.8 + Spring3.2 + Hibernate3.6 
默认版本hibernate3.3.1
配置文件 :
jbpm.cfg.xml、
logging.properties(拷贝hibernate包下/project/etc/log4j.properties即可)
jbpm.hibernate.cfg.xml。

hibernate3.6 dtd
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

hibernate3.3.1 dtd
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

*** jar包 整合,将ssh整合之外的jar包 导入
 
三、初始化 JBPM的数据表 
配置 jbpm.hibernate.cfg.xml 修改数据库连接参数  
默认创建18张数据表

Hibernate创建方式 
org.hibernate.cfg.Configuration configuration = new org.hibernate.cfg.Configuration().configure("jbpm.hibernate.cfg.xml");
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session = sessionFactory.openSession();
session.close();
sessionFactory.close();

JBPM创建方式
原始方式:
ProcessEngine processEngine = new org.jbpm.api.Configuration().setResource("jbpm.cfg.xml").buildProcessEngine();
简化写法:
ProcessEngine processEngine = new org.jbpm.api.Configuration().buildProcessEngine();
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();

jBPM4.4的数据库表分成以下几类:
1)和系统相关:
这个只有JBPM4_PROPERTY
2)和ProcessDefinition相关的表:
有:JBPM4_DEPLOYMENT、JBPM4_DEPLOYPROP、JBPM4_LOB
3)和开启一个instance相关:
有JBPM4_EXECUTION、JBPM4_TASK、JBPM4_JOB、JBPM4_VARIABLE、JBPM4_SWIMLANE、 JBPM_PARTICIPATION
4)和历史相关的表:
JBPM4_HIS_ACTINST、JBPM4_HIS_DETAIL、JBPM4_HIS_PROCINST、JBPM4_HIS_TASK、JBPM4_HIS_VAR
5)和用户/组相关的表有:
JBPM4_ID_USER、JBPM4_ID_GROUP、JBPM4_ID_MEMBERSHIP

******** 第一次启动jbpm引擎时,向JBPM4_PROPERTY表插入一条数据

ProccessEngine 流程引擎对象是操作jBPM4 核心对象,通过它可以得到 ProcessService 、ExecutionService和 TaskService 等各种类型的操作 jBPM4的服务对象

四、 使用 流程设计器创建 JBPM 工作流程
发布流程 :
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
NewDeployment deployment = processEngine.getRepositoryService().createDeployment();
deployment.addResourceFromClasspath("helloworld.jpdl.xml");
deployment.addResourceFromClasspath("helloworld.png");
deployment.deploy();

******** 发布JBPM流程时,向 JBPM4_DEPLOYMENT 、JBPM4_DEPLOYPROP、JBPM4_LOB 三张表插入数据
jbmp4_deployment:流程定义的部署记录;
jbmp4_deployprop:已部署的流程定义的具体属性:
jbmp4_lob:流程定义的相关资源,包括jPDL XML、图片、用户代码Java类等,以二进制格式统一存储在此表中;

启动流程 :
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
ExecutionService executionService = processEngine.getExecutionService();
ProcessInstance processInstance = executionService.startProcessInstanceByKey("helloworld");
System.out.println("流程定义id:" + processInstance.getProcessDefinitionId() + ", 流程实例id : " + processInstance.getId());

******** 启动JBPM流程实例时,向 JBPM4_EXECUTION、JBPM4_HIS_PROCINST、JBPM4_TASK、JBPM4_HIS_TASK、JBPM4_HIS_ACTINST
jbpm4_executon:流程实例及执行对象
jbmp4_hist_procinst:保存历史的流程实例记录
jbpm4_task:流程实例的任务记录
jbpm4_hist_task:保存历史的任务实例记录
jbpm4_hist_actinst:保存历史的活动实例记录

查询个人代办任务:
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
TaskService taskService = processEngine.getTaskService();
List<Task> tasks = taskService.findPersonalTasks("员工");
for (Task task : tasks) {
System.out.println("任务id : " + task.getId());
System.out.println("任务名称: " + task.getName());
System.out.println("任务的办理人 : " + task.getAssignee());
System.out.println("执行流程实例id :" + task.getExecutionId());
System.out.println("----------------");
}

办理任务:
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
TaskService taskService = processEngine.getTaskService();
taskService.completeTask("任务id");

====================================================================================
五、流程定义管理 
流程定义信息的增删改查 
增加 : 
部署xml和png 
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
deployment.addResourceFromClasspath("helloworld.jpdl.xml");
deployment.addResourceFromClasspath("helloworld.png");
部署zip 
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
ZipInputStream zipinputstream = new ZipInputStream(this.getClass().getResourceAsStream("/helloworld.zip"));
processEngine.getRepositoryService().createDeployment().addResourcesFromZipInputStream(zipinputstream).deploy();

查询:
查询发布实例
List<Deployment> developmentList = processEngine.getRepositoryService().createDeploymentQuery().list();
for (Deployment deployment : developmentList) {
System.out.println("发布id:" + deployment.getId());
System.out.println("发布名称:" + deployment.getName());
System.out.println("发布流程状态:" + deployment.getState());
System.out.println("发布流程版本 :" + deployment.getTimestamp());
}
******** 查询 jbpm4_deployment

查询流程信息
List<ProcessDefinition> processDefinitionList = processEngine.getRepositoryService().createProcessDefinitionQuery().list();
for (ProcessDefinition processDefinition : processDefinitionList) {
System.out.println("流程id:" + processDefinition.getId());
System.out.println("流程name:" + processDefinition.getName());
System.out.println("流程key:" + processDefinition.getKey()); // 如果不写,值默认为name
System.out.println("流程版本 :" + processDefinition.getVersion());
}
******** 查询 jbpm4_deployprop

查询定义流程图
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
InputStream in = processEngine.getRepositoryService().getResourceAsStream("40001", "helloworld.png");
OutputStream out = new FileOutputStream("d:/proccess.png");
int b;
while ((b = in.read()) != -1) {
out.write(b);
}
in.close();
out.close();
******** 查询 jbpm4_lob

删除:
根据发布id 删除流程
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
processEngine.getRepositoryService().deleteDeployment("发布流程id"); // 如果流程有启动关联信息,无法删除 
processEngine.getRepositoryService().deleteDeploymentCascade("发布流程id");  // 对流程信息进行级联删除,删除所有相关定义和运行信息

根据发布key删除流程
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("holiday").list();
for (ProcessDefinition processDefinition : processDefinitions) {
processEngine.getRepositoryService().deleteDeploymentCascade(processDefinition.getDeploymentId());
}

******* 发布流程时,按照name 作为相同流程的标识,name和key都相同,版本+1 , name不同认为是新流程 , name相同key不同报错
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
ProcessDefinition processDefinition = processEngine.getRepositoryService().createProcessDefinitionQuery().orderDesc(ProcessDefinitionQuery.PROPERTY_VERSION).list().get(0);

六、流程执行管理
部署流程
启动流程
查看我的待办任务
办理任务

流程向后一步 
ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();
processEngine.getExecutionService().signalExecutionById("流程执行实例id", "下一个transition的name属性");

七、设置流程过程中的变量
节点中 设置获取 
executionService.setVariable(executionId, name, value);
executionService.setVariables(executionId, variablesMap);

executionService.getVariable(executionId, variableName); 返回 Object 
executionService.getVariableNames(executionId);  返回 Set<String>
executionService.getVariables(s, set) ; // 返回 Map<String,Object> 

**************  操作 jbpm4_variable 表

启动流程时设置
executionService.startProcessInstanceByKey(processDefinitionKey, variablesMap);

完成任务时设置
taskService.completeTask(taskId, variablesMap);

能否设置复杂对象 ???? 

你可能感兴趣的:(jbpm)