https://community.alfresco.com/thread/221280-business-key-in-a-call-activity

这个帖子有一些讨论和回复。

https://community.alfresco.com/thread/218788-call-activity-and-businesskey#

这个帖子一直没人回答。

https://stackoverflow.com/questions/26497569/activity-how-to-know-if-an-execution-is-linked-to-an-instance-of-subprocess

https://community.alfresco.com/thread/221348-get-all-active-tasks-including-sub-process-tasks

这篇文章比较中肯,社区分享了两种(潜在的)WorkAround的方案,详见下边解决方案部分。

http://blog.csdn.net/lovemenghaibin/article/details/50608300

这个帖子是讲business key的用户的入门文章,和本问题无关。

act_ru_execution表的BUSINESS_KEY_ 字段,在使用call activiti时,子流程的BUSINESS_KEY_会丢失,而不能从父流程继承过来。

解决方案:

1.《Activiti权威指南》作者冀正,给的建议的解决办法:修改源代码,一行代码就能把丢失的BUSINESS_KEY_拷贝过来。

2.用ExecutionListener或者ActivitiEventListener监听CallActiviti的创建过程,然后把父流程实例的Business存入流程变量中。

社区网友由ExecutionListener到ActivitiEventListener逐步讨论。

a) ExecutionListener

/**
* BusinessKeyInjectionListener.java
* com.yuanchuangyun.workflow.listener
*
* Function: TODO
*
* ver date author
* ──────────────────────────────────
* 2017年12月1日 renguoqiang
*
* Copyright (c) 2017, yuanchuangyun All Rights Reserved.
*/ package com.yuanchuangyun.workflow.listener; import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity; /**
* ClassName:BusinessKeyInjectionExecutionListener
* @author renguoqiang
* @version
* @since Ver 1.1
* @Date 2017年12月1日 下午4:10:37
*
* @see
*/
public class BusinessKeyInjectionExecutionListener implements ExecutionListener{ /**
* serialVersionUID:TODO(用一句话描述这个变量表示什么)
*
* @since Ver 1.1
*/ private static final long serialVersionUID = 1L; @Override
public void notify(DelegateExecution exec) throws Exception {
System.out.println("In BusinessKey Injection Listener"); ExecutionEntity thisEntity = (ExecutionEntity)exec;
ExecutionEntity superExecEntity = thisEntity.getSuperExecution(); String key = ""; // Check if this is the main process.
if( superExecEntity == null ){
// If it is, get the business key the main process was launched with.
key = thisEntity.getBusinessKey();
}else{
// We are a subprocess so get the BusinessKey variable set by the caller.
// This should work for N level deep sub processes.
key = (String)superExecEntity.getVariable("BusinessKey");
} // Set a process variable with the business key. Can't actually set business key because business keys
// have to be unique per process instance.
thisEntity.setVariable("BusinessKey", key);
} }

b) ActivitiEventListener

/**
* BusinessKeyInjectionActivitiEventListener.java
* com.yuanchuangyun.workflow.listener
*
* Function: TODO
*
* ver date author
* ──────────────────────────────────
* 2017年12月1日 renguoqiang
*
* Copyright (c) 2017, yuanchuangyun All Rights Reserved.
*/ package com.yuanchuangyun.workflow.listener; import org.activiti.engine.delegate.event.ActivitiEntityEvent;
import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.persistence.entity.TaskEntity; /**
* ClassName:BusinessKeyInjectionActivitiEventListener
* @author renguoqiang
* @version
* @since Ver 1.1
* @Date 2017年12月1日 下午5:03:29
*
* @see
*/
public class BusinessKeyInjectionActivitiEventListener implements ActivitiEventListener {
private String getSuperProcessInstanceId(ExecutionEntity exEntity) {
if (exEntity != null && exEntity.getSuperExecution() != null) {
return getSuperProcessInstanceId(exEntity.getSuperExecution());
} else if (exEntity != null) {
return exEntity.getProcessInstanceId();
} return null;
} @Override
public void onEvent(ActivitiEvent event) {
switch (event.getType()) {
case TASK_CREATED:
if (event instanceof ActivitiEntityEvent) {
ActivitiEntityEvent activityEntityEvent = (ActivitiEntityEvent) event; TaskEntity taskEntity = (TaskEntity) activityEntityEvent
.getEntity();
ExecutionEntity exEntity = taskEntity.getExecution();
String superExId = getSuperProcessInstanceId(exEntity != null ? exEntity
.getSuperExecution() : null); if (superExId != null) {
taskEntity.setAssignee(superExId);
} try {
@SuppressWarnings("null")
ExecutionEntity executionEntity = (ExecutionEntity) activityEntityEvent
.getEntity(); ExecutionEntity superExecEntity = executionEntity
.getSuperExecution();
String key = ""; // Check if this is the main process.
if (superExecEntity == null) {
// key = executionEntity.getBusinessKey();
key = (String) executionEntity
.getVariable("BusinessKey");
} else {
key = (String) superExecEntity
.getVariable("BusinessKey");
} executionEntity.setVariable("BusinessKey", key); } catch (Exception e) {
// System.out.println("ENTITY CAST ERROR !!!!!!!!");
} break;
// ...
}
default:
break;
}
} @Override
public boolean isFailOnException() {
// TODO Auto-generated method stub
return false;
}
}

TIP:从Activiti的官方文档,可知BusinessKey这个列,预留只是为了兼容一些历史问题。系统设计时,应该避免使用此值,这样Activiti就更独立一下(耦合小),也就是把业务的主键与ProcessInstanceId的关联记录,放入自定义的业务表中存储。

源码附件:https://files.cnblogs.com/files/rgqancy/BusinessKey.zip

Issue: business key in a call activiti的更多相关文章

  1. Activiti第一篇【介绍、配置开发环境、快速入门】

    Activiti介绍 什么是Activiti? Activiti5是由Alfresco软件在2010年5月17日发布的业务流程管理(BPM)框架,它是覆盖了业务流程管理.工作流.服务协作等领域的一个开 ...

  2. Activiti就是这么简单

    Activiti介绍 什么是Activiti? Activiti5是由Alfresco软件在2010年5月17日发布的业务流程管理(BPM)框架,它是覆盖了业务流程管理.工作流.服务协作等领域的一个开 ...

  3. activiti工作流框架简介

    常见的工作流框架:activiti, JBPM, OSWorkflow activiti框架基于23张基础的表数据, 基于Mybatis操作数据库. JBPM框架基于18张基础的表数据, 基于hibe ...

  4. Activiti工作流学习-----基于5.19.0版本(5)

    五.与Spring集成 实际项目中一般都有Spring的身影,与Spring集成使得Activiti的实用性得到提高.activiti和Spring整合需要activiti-spring的jar在类路 ...

  5. 六、activiti工作流-流程定义查询

    本节主要讲流程定义查询.查询某个流程设计图片并保存到本地中.查询最新版本的流程定义集合.删除所有key相同的定义 先创建一个java类 package com.java.procdef; import ...

  6. activiti整合开发实例总结

    参考手册:http://www.mossle.com/docs/activiti/ 一.applicationContext.xml中引入activiti相关配置的xml文件 <!-- begi ...

  7. Project Management Process

    Project Management ProcessDescription .............................................................. ...

  8. jbpm 6 vs activities 5评估(持续更新、亲测实际项目评估)

    最近我们有个使用了jbpm 6.2(6.2是一个较大的里程碑)的批处理模块,因为大BOSS一直觉得太重了,希望有更加轻量级的解决方案,因为我们基本上没有真正意义上流程的概念,只有静态的流程图,因为一直 ...

  9. 2017.11.2 Talk to customers for an hour

    yesterday::: Hi Huang, For the better performance of the test the Con 6 should be connected all the ...

随机推荐

  1. MongoDB基础教程系列--目录结构

    最近对 MongoDB 产生兴趣,在网上找的大部分都是 2.X 版本,由于 2.X 与 3.X 差别还是很大的,所以自己参考官网,写了本系列.MongoDB 的知识还是很多的,本系列会持续更新,本文作 ...

  2. luogu P4718 【模板】Pollard-Rho算法(贴代码)

    嘟嘟嘟 从标题中能看出来,我只是想贴一个代码. 先扯一会儿. 前几天模拟考到了这东西,今天有空就学了一下. 到网上找资料,发现前置技能是miller-rabin筛法,于是我还得先学这么个东西. 学mi ...

  3. oracle 11gR2 ASM添加和删除磁盘

    一.环境 oracle 11gR2 RAC + Oracle Linux Server release 5.9 二.实施 备注:安全起见,操作之前停数据库实例.ASM实例 1.节点1.2磁盘信息 -- ...

  4. vue.js 防暴力点击方案

    import lodash from 'lodash' <input v-on:onclick ="doStuff">methods: { doStuff:loadsh ...

  5. 老男孩Python全栈视频

    链接:https://pan.baidu.com/s/1c1JOCL1w-vnYGkrhElk_GQ 密码私聊我

  6. VsCode插件开发之入门示例

    主要参考官网:https://code.visualstudio.com/api/get-started/your-first-extension 其实也就三步 一.安装环境 npm install ...

  7. WordPress研究心得

    WordPress,当初之所以研究这个,目的是在于开发一个多租户系统应用.总的来说,WordPress给了我不少启发和影响.为此,我决定这个研究心得分享出去. 总的来说,这篇文章参考了很多朋友们的博客 ...

  8. 1896 互不侵犯 洛谷 luogu

    题目描述 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. 注:数据有加强(2018/4/25) ...

  9. IDEA学生免费申请教程

    1.点击网址,进入申请页面https://www.jetbrains.com/zh/student/ 2.由于网页是全英文的,可以用浏览器将页面翻译成中文版,更方便操作 3.因为没有大学的邮箱地址,所 ...

  10. 深入浅出的webpack构建工具---webpack3版本的CommonsChunkPlugin详解(六)

    阅读目录 一:什么是CommonsChunkPlugin, 它的作用是什么? 二:webpack3中CommonsChunkPlugin配置项及含义? 回到顶部 一:什么是CommonsChunkPl ...