zoukankan      html  css  js  c++  java
  • 工作流JBPM_day01:7-使用流程变量

    工作流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);
        }
    }

  • 相关阅读:
    css实现鼠标悬浮字体流光背景模糊效果
    原生JS实现省市区(县)三级联动选择
    多线程的对象锁和类锁
    session、cookie与“记住我的登录状态”的功能的实现
    Java NIO FileVisitor 高效删除文件
    mysql 服务启动失败
    Http 协议详解
    设计模式 之 策略模式
    简单探讨 javascript 闭包
    数据库SQL优化大总结之 百万级数据库优化方案
  • 原文地址:https://www.cnblogs.com/justdoitba/p/8012668.html
Copyright © 2011-2022 走看看