工作流JBPM_day01:7-使用流程变量

工作流就像流水线

对应数据库中的一张表

ProcessVariableTest.Java

import java.util.List;

import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.task.Task;
import org.junit.Test; public class ProcessVariableTest {
private ProcessEngine processEngine = Configuration.getProcessEngine(); // 启动流程实例
// jbpm4_execution
@Test
public void testStartProcessInstance() {
ProcessInstance pi = processEngine.getExecutionService().startProcessInstanceByKey("helloworld");
System.out.println("流程实例启动成功:id=" + pi.getId());// 所使用的流程定义的Id
}
//设置流程变量
@Test
public void testSetVariable() {
String executionId = "helloworld.170001";
processEngine.getExecutionService().setVariable(executionId, "请假天数", 15);
} //获取流程变量
@Test
public void testGetVariable() {
String executionId = "helloworld.170001";
Integer days = (Integer) processEngine.getExecutionService().getVariable(executionId, "请假天数");
System.out.println("请假天数=" + executionId);
} /**
{
ExecutionService executionService = processEngine.getExecutionService();
TaskService taskService = processEngine.getTaskService(); // ============ 设置变量 ========================
executionService.setVariable(executionId, name, value); // 设置一个变量
executionService.setVariables(executionId, variablesMap); // 设置多个变量
taskService.setVariables(taskId, variables); // 设置多个变量 executionService.startProcessInstanceByKey(processDefinitionKey, variablesMap); // 启动流程实例时,先设置一些变量
taskService.completeTask(taskId, variablesMap); // 真正办理完任务前先设置一些变量 // ============ 获取变量 ========================
executionService.getVariable(executionId, variableName); // 获取一个变量
executionService.getVariableNames(executionId); // 返回Set<String>,是所有变量的名称集合
executionService.getVariables(executionId, variableNames); //获取多个变量,返回Map<String,Object>,表示指定名称的变量信息 taskService.getVariable(taskId, variableName);
taskService.getVariableNames(taskId);
taskService.getVariables(taskId, variableNames);
}
*/
}

Form.java

public class Form /* implements java.io.Serializable */{

    private Long id;
private String title; // ... public Form() {
} public Form(String title) {
this.title = title;
} public Form(Long id, String title) {
this.id = id;
this.title = title;
} public Long getId() {
return id;
} public void setId(Long id) {
this.id = id;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} @Override
public String toString() {
return "[Form: id=" + id + ", title=" + title + "]";
}
}

Form.hbm.xml

<hibernate-mapping package="cn.itcast.d_processvariable">

    <class name="Form" table="itcast_form" lazy="false">
<id name="id">
<generator class="native"/>
</id>
<property name="title"/>
</class> </hibernate-mapping>

ProcessVariableTest2.Java

import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.junit.Test; public class ProcessVariableTest2 {
private ProcessEngine processEngine = Configuration.getProcessEngine(); // 启动流程实例
@Test
public void testStartProcessInstance() throws Exception {
ProcessInstance pi = processEngine.getExecutionService().startProcessInstanceByKey("helloworld");
System.out.println("流程实例启动成功:id=" + pi.getId());
} // 设置流程变量
@Test
public void testSetVariable() throws Exception {
String executionId = "helloworld.190001";
Form form = new Form(1L, "我要请假,我是张三"); // 通过指定id来模拟一个游离状态的对象
processEngine.getExecutionService().setVariable(executionId, "form", form);
} // 获取流程变量
@Test
public void testGetVariable() throws Exception {
String executionId = "helloworld.190001";
Form form = (Form) processEngine.getExecutionService().getVariable(executionId, "form");
System.out.println(form);
}
}

工作流JBPM_day01:7-使用流程变量的更多相关文章

  1. JBPM工作流(六)——流程变量

    1.启动流程实例 ? 1 2 3 4 5 6 7 // 启动流程实例 @Test public void startProcessInstance() {     // 使用指定key的最新版本的流程 ...

  2. Activiti工作流(三)——流程变量

    流程变量可以是流程中一系列参数,比如办理人(Assignee),消息(message)等.这些流程变量使得activiti能够应用于更为复杂的业务中,使得流程变得更加灵活可控. 场景(一) 图一:没有 ...

  3. 工作流学习——Activiti流程变量五步曲 (zhuan)

    http://blog.csdn.net/zwk626542417/article/details/46648139 ***************************************** ...

  4. 工作流Activiti5流程变量 任务变量 setVariables 跟 setVariablesLocal区别

    工作流Activiti5流程变量 任务变量 setVariables 和 setVariablesLocal区别 因为网上的资料比较少.结合源码把相关API写下来. 设置流程级别变量: runtime ...

  5. 工作流JBPM_day01:6-执行流程实例

    工作流JBPM_day01:6-执行流程实例 执行流程 启动流程实例 查询任务列表 办理任务 向后执行一步 先部署流程定义在启动流程实例 Jbpm4_execution表表示正在执行的流程实例的的信息 ...

  6. 工作流JBPM_day01:5-管理流程定义3点改进

    工作流JBPM_day01:5-管理流程定义3点改进 1.打包多个文件上传 再部署一个 查询所有看看,旧版本也查出来了 2.查询时只查询所有最新的版本 3.删除指定名称指定key的所有的它的版本

  7. 工作流JBPM_day01:4-管理流程定义

    工作流JBPM_day01:4-管理流程定义 管理流程(流程定义) 部署(添加) 查询 删除 查看流程图(xxx.png) -- 修改 --> 没有真正的修改,而是使用“再次部署+使用最新版本启 ...

  8. 工作流JBPM_day01:3-使用JBPM的API添加与执行流程

    工作流JBPM_day01:3-使用JBPM的API添加与执行流程 流程定义画完得到压缩文件--->部署流程定义-->启动流程实例-->查询我的个人任务列表-->办理任务--& ...

  9. 工作流JBPM_day01:1-说明_MyProcessDesigner_流程设计器

    工作流JBPM_day01:1-说明 先只做请假功能,怎么做? (请假可以和考勤整合到一起) 1,银行(拿号---叫号---办理) 2,餐馆(点菜---上菜---结账) 3,网购(下订单--配送--收 ...

随机推荐

  1. 利用面向对象思想封装Konva动态进度条

    1.html代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  2. document对象和属性

    文档对象:整个Html都属于document,他封装了大量的功能: docum的属性: document.title //设置文档标题等价于HTML的<title>标签 document. ...

  3. CentOS 6.5 x64下Hadoop安装

    Apache Hadoop安装部署模式 单机(本地)模式(Standalone Mode) 伪分布模式(Pseudo-Distributed Mode) 完全分布模式(Fully Distribute ...

  4. C语言 · 字符串对比

    问题描述 给定两个仅由大写字母或小写字母组成的字符串(长度介于1到10之间),它们之间的关系是以下4中情况之一: 1:两个字符串长度不等.比如 Beijing 和 Hebei 2:两个字符串不仅长度相 ...

  5. protobuf--数据序列化及反序列化

    ProtoBuf是一种灵活高效的独立于语言平台的结构化数据表示方法,可用于表示通信协议和数据存储等各方面,与XML相比,ProtoBuF更小更快更简单.你可以用定义自己ProtoBuf的数据结构,用P ...

  6. DataTable使用技巧:DataRowState

    DataGridView:获取 DataRow 对象的状态,共有5个枚举值. Added 该行已添加到 DataRowCollection 中,AcceptChanges 尚未调用. Deleted ...

  7. jQuery EasyUI教程之datagrid应用-1

    一.利用jQuery EasyUI的DataGrid创建CRUD应用 对网页应用程序来说,正确采集和管理数据通常很有必要,DataGrid的CRUD功能允许我们创建页面来列表显示和编辑数据库记录.本教 ...

  8. jQuery EasyUI教程之datagrid应用

    一.利用jQuery EasyUI的DataGrid创建CRUD应用 对网页应用程序来说,正确采集和管理数据通常很有必要,DataGrid的CRUD功能允许我们创建页面来列表显示和编辑数据库记录.本教 ...

  9. WCF(一)

    摘自:http://www.cnblogs.com/yank/p/3653160.html WCF入门教程(一)简介 1.WCF是什么? WCF( Windows Communication Foun ...

  10. Graying the black box: Understanding DQNs

    Zahavy, Tom, Nir Ben-Zrihem, and Shie Mannor. "Graying the black box: Understanding DQNs." ...