• activiti基础--1------------------------生成.bpmn和.png以及部署流程定义


    helloworld.dbmn

    <?xml version="1.0" encoding="UTF-8"?>
    <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
      <process id="helloworld" name="helloworldProcess" isExecutable="true">
        <startEvent id="startevent1" name="Start"></startEvent>
        <endEvent id="endevent1" name="End"></endEvent>
        <userTask id="usertask1" name="提交申请" activiti:assignee="张三"></userTask>
        <userTask id="usertask2" name="审批【部门经理】" activiti:assignee="李四"></userTask>
        <userTask id="usertask3" name="审批【总经理】" activiti:assignee="王五"></userTask>
        <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
        <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
        <sequenceFlow id="flow3" sourceRef="usertask2" targetRef="usertask3"></sequenceFlow>
        <sequenceFlow id="flow4" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow>
      </process>
      <bpmndi:BPMNDiagram id="BPMNDiagram_helloworld">
        <bpmndi:BPMNPlane bpmnElement="helloworld" id="BPMNPlane_helloworld">
          <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
            <omgdc:Bounds height="35.0" width="35.0" x="610.0" y="30.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
            <omgdc:Bounds height="35.0" width="35.0" x="610.0" y="600.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
            <omgdc:Bounds height="55.0" width="105.0" x="575.0" y="150.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
            <omgdc:Bounds height="55.0" width="105.0" x="575.0" y="300.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
            <omgdc:Bounds height="55.0" width="105.0" x="575.0" y="470.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
            <omgdi:waypoint x="627.0" y="65.0"></omgdi:waypoint>
            <omgdi:waypoint x="627.0" y="150.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
            <omgdi:waypoint x="627.0" y="205.0"></omgdi:waypoint>
            <omgdi:waypoint x="627.0" y="300.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
            <omgdi:waypoint x="627.0" y="355.0"></omgdi:waypoint>
            <omgdi:waypoint x="627.0" y="470.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
            <omgdi:waypoint x="627.0" y="525.0"></omgdi:waypoint>
            <omgdi:waypoint x="627.0" y="600.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
        </bpmndi:BPMNPlane>
      </bpmndi:BPMNDiagram>
    </definitions>

    helloworld.png

    第一个测试小程序helloworld

    package com.xingshang.helloworld;
    
    import java.util.List;
    
    import org.activiti.engine.ProcessEngine;
    import org.activiti.engine.ProcessEngines;
    import org.activiti.engine.repository.Deployment;
    import org.activiti.engine.runtime.ProcessInstance;
    import org.activiti.engine.task.Task;
    import org.junit.Test;
    
    public class HelloWorld {
        
        //工作引擎
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        
        /**
         * 部署流程定义
         */
        @Test
        public void deploymentProcessDefinition(){
            Deployment deployment = processEngine.getRepositoryService()//与流程定义和部署相关的service
                            .createDeployment()//创建一个部署对象
                            .name("HelloWorld入门程序")//添加部署的名字
                            .addClasspathResource("diagrams/HelloWorld.bpmn")//从classpath下的资源中加载,一次只能加载一个文件
                            .addClasspathResource("diagrams/HelloWorld.png")//从classpath下的资源中加载,一次只能加载一个文件
                            .deploy();//完成部署
            System.out.println("部署ID: " + deployment.getId());//1
            System.out.println("部署名称: " + deployment.getName());//HelloWorld入门程序
        }
        
        /**
         * 启动流程实例
         */
        @Test
        public void startProcessInstance(){
            //流程定义的key
            String processDefinitionKey = "helloworld";
            ProcessInstance pi = processEngine.getRuntimeService()//与正在执行的流程实例和执行对象相关的service
                                    .startProcessInstanceByKey(processDefinitionKey);//使用流程定义的key启动流程实例,key对应HelloWorld.bpmn文件中id的属性值,使用key值启动,默认是按照最新版本的流程定义启动
            
            System.out.println("流程实例ID: " + pi.getId());//流程实例ID   101
            System.out.println("流程定义ID: " + pi.getProcessDefinitionId());//流程定义ID   helloworld:1:4
        }
        
        /**
         * 查询当前人的个人任务
         */
        @Test
        public void findMyPersonalTask(){
            String assignee = "张三";
            
            List<Task> list = processEngine.getTaskService()//与正在执行的任务管理相关的Sercice
                            .createTaskQuery()//创建任务查询对象
                            .taskAssignee(assignee)//指定个人任务查询,指定办理人
                            .list();
            
            if(list != null && list.size() > 0){
                for(Task task : list){
                    System.out.println("任务ID: " + task.getId()); //104
                    System.out.println("任务名称: " + task.getName());//提交申请
                    System.out.println("任务的创建时间: " + task.getCreateTime());// Mon Dec 11 10:20:46 CST 2017
                    System.out.println("任务的办理人:" + task.getAssignee());//张三
                    System.out.println("流程实例ID: " + task.getProcessInstanceId());//101
                    System.out.println("执行对象ID: " + task.getExecutionId());//101
                    System.out.println("流程定义ID: " + task.getProcessDefinitionId());//helloworld:1:4
                }
            }
        }
        
        /**
         * 完成我的任务
         */
        @Test
        public void completeMyPersonalTask(){
            
            String taskId = "104";
            
            processEngine.getTaskService()//与正在执行的任务管理相关的Sercice
                            .complete(taskId);
            System.out.println("任务完成: 任务Id: " + taskId);
        }
    }
  • 相关阅读:
    Qt's Undo Framework
    linux-ftp
    Linux Terminator
    linux wc
    Linux卷配置管理
    vmware workstation LINUX磁盘扩容
    Oracle linux6.1配置yum本地源
    安装jdk java -version 不是自己所需要的版本
    aix下oracle数据库创建表空间和用户
    Linux命令 find和mv的结合使用:查找文件,移动到某个目录
  • 原文地址:https://www.cnblogs.com/sutao/p/8022993.html
Copyright © 2020-2023  润新知