zoukankan      html  css  js  c++  java
  • JBPM工作流(六)——流程变量

    1.启动流程实例

    1
    2
    3
    4
    5
    6
    7
    // 启动流程实例
    @Test
    public void startProcessInstance() {
        // 使用指定key的最新版本的流程定义启动流程实例
        ProcessInstance pi = processEngine.getExecutionService().startProcessInstanceByKey("test");
        System.out.println("processInstanceId=" + pi.getId());
    }

      

    2.设置流程变量

    a) 一个设置流程变量实例

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    //设置流程变量
    @Test
    public void setVariable() {
        String executionId = "test.140001";
        String name = "请假天数";
        Integer value = 3;
     
        //将name为"请假天数",value=3的流程变量设置到executionId为test.140001的执行对象上
        processEngine.getExecutionService().setVariable(executionId, name, value);
    }

    b) 所有设置流程变量方法

    用到变量的类型:

    1
    2
    3
    4
    5
    6
    7
    8
    Object value = "";
    String executionId = "";
    String taskId = "";
    String name = "";
    String processDefinitionKey = "";
    String variableName = "";
    Set<String> variableNames = new HashSet<String>();
    Map<String, Object> variablesMap = new HashMap<String, Object>();

      具体方法:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    // 根据Execution设置一个流程变量
    processEngine.getExecutionService().setVariable(executionId, name, value);
    // 根据Execution设置多个流程变量(需要先把流程变量放到一个Map中)
    processEngine.getExecutionService().setVariables(executionId, variablesMap);
     
    // 根据Task设置多个流程变量(需要先把流程变量放到一个Map中,通过Task方法,它会先找到它所属的Execution然后设置流程变量)
    processEngine.getTaskService().setVariables(taskId, variablesMap);
     
    // 使用指定key的最新版本的流程定义启动流程实例,并设置一些流程变量
    processEngine.getExecutionService().startProcessInstanceByKey(processDefinitionKey, variablesMap);
    // 办理完指定的任务,并设置一些流程变量
    processEngine.getTaskService().completeTask(taskId, variablesMap);

      

    3.获取流程变量

    a) 一个获取流程变量实例

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    //获取流程变量
    @Test
    public void getVariable() {
        String executionId = "test.140001";
        String variableName = "请假天数";
     
        //从executionId为test.140001的执行对象上取出流程变量名为"请假天数"的流程变量的value
        Integer value = (Integer) processEngine.getExecutionService().getVariable(executionId, variableName);
        System.out.println(variableName + " = " + value);
    }

      

    b) 所有获取流程变量方法

    用到变量的类型:

    1
    2
    3
    4
    String executionId = "";
    String taskId = "";
    String variableName = "";
    Set<String> variableNames = new HashSet<String>();

      具体方法:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    // 根据Execution获取指定名称的一个流程变量
    processEngine.getExecutionService().getVariable(executionId, variableName);
    // 根据Execution获取所有流程变量的名称
    processEngine.getExecutionService().getVariableNames(executionId);
    // 根据Execution获取指定名称的所有流程变量
    processEngine.getExecutionService().getVariables(executionId, variableNames);
     
    // 根据Task获取指定名称的一个流程变量
    processEngine.getTaskService().getVariable(taskId, variableName);
    // 根据Task获取所有流程变量的名称
    processEngine.getTaskService().getVariableNames(taskId);
    // 根据Task获取指定名称的所有流程变量
    processEngine.getTaskService().getVariables(taskId, variableNames);

      

    4.流程变量所支持的值的类型(jBPM User Guide,7.2. Variable types)

    jBPM supports following Java types as process variables:

    • java.lang.String 
    • java.lang.Long 
    • java.lang.Double 
    • java.util.Date 
    • java.lang.Boolean 
    • java.lang.Character 
    • java.lang.Byte 
    • java.lang.Short 
    • java.lang.Integer 
    • java.lang.Float 
    • byte[] (byte array) 
    • char[] (char array) 
    • hibernate entity with a long id 
    • hibernate entity with a string id 
    • serializable

    For persistence of these variable, the type of the variable is checked in the order of this list. The first match will determine how the variable is stored.

  • 相关阅读:
    使用 MDT 2010 进行可伸缩部署
    Windows Phone 7 WebBrowser 中文乱码问题
    如何安装Windows Phone SDK 7.1 Release Candidate (RC)
    Windows Phone应用 博客园阅读器
    将WindowsPhoneApp部署到HTC Surround,兄弟们支个招如何进行Debug
    私有代码存放仓库 BitBucket
    入门:添加一个支持获取单一资源以及支持POST,PUT和DELETE方法
    Html5 学习利器 Web Standards Update for Microsoft Visual Studio 2010 SP1
    在启用了IPV6的机器上获取客户端ipv4地址
    EMA算法的C#实现
  • 原文地址:https://www.cnblogs.com/HHR-SUN/p/7235862.html
Copyright © 2011-2022 走看看