ProcessDefCache.java
2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* Copyright © 2015-2018 ODM All rights reserved.
*/
package com.thinkgem.jeesite.modules.act.utils;
import java.util.List;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.repository.ProcessDefinition;
import org.apache.commons.lang3.ObjectUtils;
import com.thinkgem.jeesite.common.utils.CacheUtils;
import com.thinkgem.jeesite.common.utils.SpringContextHolder;
/**
* 流程定义缓存
* @author ThinkGem
* @version 2013-12-05
*/
public class ProcessDefCache {
private static final String ACT_CACHE = "actCache";
private static final String ACT_CACHE_PD_ID_ = "pd_id_";
/**
* 获得流程定义对象
* @param procDefId
* @return
*/
public static ProcessDefinition get(String procDefId) {
ProcessDefinition pd = (ProcessDefinition)CacheUtils.get(ACT_CACHE, ACT_CACHE_PD_ID_ + procDefId);
if (pd == null) {
RepositoryService repositoryService = SpringContextHolder.getBean(RepositoryService.class);
// pd = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(pd);
pd = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult();
if (pd != null) {
CacheUtils.put(ACT_CACHE, ACT_CACHE_PD_ID_ + procDefId, pd);
}
}
return pd;
}
/**
* 获得流程定义的所有活动节点
* @param procDefId
* @return
*/
public static List<ActivityImpl> getActivitys(String procDefId) {
ProcessDefinition pd = get(procDefId);
if (pd != null) {
return ((ProcessDefinitionEntity) pd).getActivities();
}
return null;
}
/**
* 获得流程定义活动节点
* @param procDefId
* @param activityId
* @return
*/
public static ActivityImpl getActivity(String procDefId, String activityId) {
ProcessDefinition pd = get(procDefId);
if (pd != null) {
List<ActivityImpl> list = getActivitys(procDefId);
if (list != null){
for (ActivityImpl activityImpl : list) {
if (activityId.equals(activityImpl.getId())){
return activityImpl;
}
}
}
}
return null;
}
/**
* 获取流程定义活动节点名称
* @param procDefId
* @param activityId
* @return
*/
@SuppressWarnings("deprecation")
public static String getActivityName(String procDefId, String activityId) {
ActivityImpl activity = getActivity(procDefId, activityId);
if (activity != null) {
return ObjectUtils.toString(activity.getProperty("name"));
}
return null;
}
}