Issue: business key in a call activiti
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的更多相关文章
- Activiti第一篇【介绍、配置开发环境、快速入门】
Activiti介绍 什么是Activiti? Activiti5是由Alfresco软件在2010年5月17日发布的业务流程管理(BPM)框架,它是覆盖了业务流程管理.工作流.服务协作等领域的一个开 ...
- Activiti就是这么简单
Activiti介绍 什么是Activiti? Activiti5是由Alfresco软件在2010年5月17日发布的业务流程管理(BPM)框架,它是覆盖了业务流程管理.工作流.服务协作等领域的一个开 ...
- activiti工作流框架简介
常见的工作流框架:activiti, JBPM, OSWorkflow activiti框架基于23张基础的表数据, 基于Mybatis操作数据库. JBPM框架基于18张基础的表数据, 基于hibe ...
- Activiti工作流学习-----基于5.19.0版本(5)
五.与Spring集成 实际项目中一般都有Spring的身影,与Spring集成使得Activiti的实用性得到提高.activiti和Spring整合需要activiti-spring的jar在类路 ...
- 六、activiti工作流-流程定义查询
本节主要讲流程定义查询.查询某个流程设计图片并保存到本地中.查询最新版本的流程定义集合.删除所有key相同的定义 先创建一个java类 package com.java.procdef; import ...
- activiti整合开发实例总结
参考手册:http://www.mossle.com/docs/activiti/ 一.applicationContext.xml中引入activiti相关配置的xml文件 <!-- begi ...
- Project Management Process
Project Management ProcessDescription .............................................................. ...
- jbpm 6 vs activities 5评估(持续更新、亲测实际项目评估)
最近我们有个使用了jbpm 6.2(6.2是一个较大的里程碑)的批处理模块,因为大BOSS一直觉得太重了,希望有更加轻量级的解决方案,因为我们基本上没有真正意义上流程的概念,只有静态的流程图,因为一直 ...
- 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 ...
随机推荐
- 使用KVM虚拟机遇到的问题(持续更新)
1.qemu-kvm.kvm.qemu 和 qemu-system-x86_64四种命令的差别 qemu 和 qemu-system-x86_64:启动qemu虚拟机的命令,x86_64为64位系统时 ...
- centos7下安装docker(11容器操作总结)
这段时间主要是学习了对容器的操作,包括:容器的状态:start,stop,restart,rename,pause,unpause,rm,attach,exec,kill,logs:还学习了对容器的资 ...
- 布隆过滤BitMap原理
一.问题引入 BitMap从字面的意思,很多人认为是位图,其实准确的来说,翻译成基于位的映射,怎么理解呢?举一个例子,有一个无序有界int数组{1,2,5,7},初步估计占用内存44=16字节,这倒是 ...
- 关于对浏览器发送POST请求的一点研究
网上对与HTTP的Method,GET和POST的区别,说得毕竟详细.然后提到一点,说浏览器对两者的还有一个比较容易让人忽略的区别就是:POST会分2次发送,而GET只1次. GET发送1次,这个没什 ...
- oracle 12C ORA-07445 12.1.0.2.0
Mon Jun 11 14:06:23 2018 Exception [type: SIGSEGV, SI_KERNEL(general_protection)] [ADDR:0x0] [PC:0xC ...
- js == 与 === 的区别[转]
we文章转自http://blog.sina.com.cn/s/blog_4b32835b01014iv9.html 1.对于string,number等基础类型,==和===是有区别的 1)不同类型 ...
- 使用js切割URL的参数
对于一些开发场景,不使用Jsp或freemarker及其其他的模板引擎时,通常通过切割url获得对应的参数,然后通过AJAX与后台交互得到对应的数据 下面是演示实例: test.html <!D ...
- Linux kernel Programming - Concurrency and Race Conditions
Concurrency and Its Management Race condition can often lead to system crashes, memory leak,corrupte ...
- docker执行第一个应用
概念科普 Docker image:镜像是只读的,镜像中包含有需要运行的文件.镜像用来创建container,一个镜像可以运行多个container:镜像可以通过Dockerfile创建,也可以从Do ...
- Multi-View Region Adaptive Multi-temporal DMM and RGB Action Recognition
论文标题:Multi-View Region Adaptive Multi-temporal DMM and RGB Action Recognition 来源/作者机构情况: 解决问题/主要思想贡献 ...