- 浏览: 26078 次
- 性别:
- 来自: 济南
最新评论
-
raykcn:
垃圾死了标题是 ss3, 内容的xml是“spring-sec ...
spring security 3.0 的 用户详细信息的 session 扩展 (基于rapid framework) -
boy in the road:
C:\Documents and Settings\Admin ...
JAVA命令参数学习
---------------------------------
jbpm4.1应用接口定义与实现
---------------------------------
GenericProcessEngine.java
package workflow.engine.service;
public interface GenericProcessEngine {
/**
* 创建流程引擎并返回流程引擎
*
* @return
*/
public ProcessEngine getCreateProcessEngine();
/**
* 创建流程引擎并返回流程引擎
*
* @param configurationResource
* 文件jbpm.cfg.xml的路径
* @return
*/
public ProcessEngine getCreateProcessEngine(String configurationResource);
/**
* 不创建流程引擎并返回当前线程中的流程引擎
*
* @return
*/
public ProcessEngine getCurrentProcessEngine();
/**
* 发布流程文件(流程定义)
*
* @param url
* @return
*/
public String createDeployment(String url);
/**
*
* 上传文件,部署流程文件
*
* @param fileItem
* @return
*/
public String createDeployment(FileItem fileItem);
/**
*
* 删除流程文件(流程定义)
*
* @param processDefinitionId
*/
public boolean deleteDeploymenFileByProcessDefinitionId(
String processDefinitionId);
/**
*
* 删除流程文件(流程定义)
*
* @param deploymentId
*/
public boolean deleteDeploymentFile(String deploymentId);
/**
* 显示所有的流程文件(流程定义)
*
* @return
*/
public List<ProcessDefinition> listProcessDefinitions();
/**
*
* 根据流程定义的ID取得流程定义
*
* @param processDefinitionId
* @return
*/
public ProcessDefinition getProcessDefinitionByProcessDefinitionId(
String processDefinitionId);
/**
*
*
* 根据流程名字得到流程定义
*
* @param processDefinitionName
* @return
*/
public ProcessDefinition getProcessDefinitionByName(
String processDefinitionName);
/**
*
* 根据流程定义的ID启动流程实例
*
* @param processDefinitionId
* @return
*/
public ProcessInstance startProcess(String processDefinitionId);
public ProcessInstance startProcess(String processDefinitionId,
Map<String, Object> variables);
/**
* 根据流程定义的ID显示所有的流程实例
*
* @param processDefinitionId
* @return
*/
public List<ProcessInstance> listProcessInstanceByProcessDefinitionId(
String processDefinitionId);
/**
*
* 显示所有的流程实例
*
* @return
*/
public List<ProcessInstance> listProcessInstance();
/**
*
* 根据流程实例的ID取得流程实例
*
* @param processInstanceId
* @return
*/
public ProcessInstance getProcessInstance(String processInstanceId);
/**
* 根据流程实例的ID取得流程定义
*
* @param processInstanceId
* @return
*/
public ProcessDefinition getProcessDefinitionByProcessInstanceId(
String processInstanceId);
/**
*
* 停止流程实例
*
* @param processInstanceId
*/
public void endProcessInstance(String processInstanceId);
/**
* 根据流程实例的ID取得当前节点
*
* @param processInstanceId
* @return
*/
public Activity getCurrentNode(String processInstanceId);
/**
* 根据流程实例的ID取得当前节点名字
*
* @param processInstanceId
* @return
*/
public String getCurrentNodeName(String processInstanceId);
/**
* 根据流程实例的ID取得当前节点坐标值
*
* @param processInstanceId
* @return
*/
public ActivityCoordinates getActivityCoordinates(String processInstanceId);
/**
*
* 根据流程实例的ID取得缺省的流向
*
* @param processInstanceId
* @return
*/
public Transition getDefaultOutgoingTransition(String processInstanceId);
/**
*
* 根据流程实例的ID取得该节点的所有流向,查看流向
*
* @param processInstanceId
* @return
*/
public List<Transition> getTransitions(String processInstanceId);
/**
* 根据流程实例的ID发送信号
*
* @param executionId
*/
public void signal(String executionId);
/**
* 根据流程实例的ID发送信号
*
* @param executionId
* @param signalName
*/
public void signal(String executionId, String signalName);
/**
*
* 根据流程定义获得InputStream
*
* @param processDefinitionId
* @param jpdlResourceName
* @return
*/
public InputStream getInputStreamBytProcessDefinitionId(
String processDefinitionId, String jpdlResourceName);
/**
*
* 根据部署ID获得InputStream
*
* @param deploymentId
* @param jpdlResourceName
* @return
*/
public InputStream getInputStreamByDeploymentId(String deploymentId,
String jpdlResourceName);
/**
*
* 取得管理 流程定义的资源的储存库服务
*
* @return
*/
public RepositoryService getRepositoryService();
/**
*
* 取得管理 运行时的执行服务
*
* @return
*/
public ExecutionService getExecutionService();
/**
*
* 历史服务
*
* @return
*/
public HistoryService getHistoryService();
public ManagementService getManagementService();
/**
*
* 任务服务
*
* @return
*/
public TaskService getTaskService();
/**
* 身份服务
*
* @return
*/
public IdentityService getIdentityService();
/**
*
* 根据部署ID得到流程定义
*
* @param deploymentId
* @return
*/
public ProcessDefinition getProcessDefinitionByDeploymentId(
String deploymentId);
/**
*
* 根据部署ID得到部署
*
* @param deploymentId
* @return
*/
public Deployment getDeployment(long deploymentId);
/**
*
* 显示所有的历史流程实例
*
* @return
*/
public List<HistoryProcessInstance> ListHistoryProcessInstance();
/**
*
* 初使化
*/
public void init();
/**
* 流程实例是否结束
*
* @param processInstanceId
* @return
*/
public boolean processInstancIsEND(String processInstanceId);
/**
*
* 流程实例是否结束(保留方法)
*
* @param processInstanceId
* @return
*/
public boolean processInstancIsEND_reserve(String processInstanceId);
/**
*
* 结束任务
*
* @param taskId
* @throws Exception
*/
public void taskEnd(String taskId);
/**
* 结束任务,并流向指定的路径
*
* @param taskId
* @param availableTransitionsName
* @throws Exception
*/
public void taskEnd(String taskId, String availableTransitionsName);
/**
*
* 任务是否结束
*
* @param taskId
* @return
* @throws Exception
*/
public boolean taskIsEnd(String taskId) throws Exception;
/**
* 某人所有的任务列表,查看任务状态
*
* @param taskActorName
* @return
* @throws Exception
*/
public List<Task> listTasksByActorName(String taskActorName);
/**
*
* 查看变量
*
* @param processInstanceId
* @return
*/
public Map<String, Object> getVariables(String processInstanceId);
public List<VariablesBean> getVariablesList(String processInstanceId);
/**
*
* 查找所有的任务
*
* @return
*/
public List<Task> listAllTasks();
/**
*
* 查找该流程实例所有的任务
*
* @param processInstanceId
* @return
*/
public List<Task> listAllTasksByProcessInstanceId(String processInstanceId);
/**
* 所有的用户列表
*
* @return
*/
public List<User> listUsers();
/**
*
* 通过用户ID显示所有的分组列表
*
* @param userId
* @return
*/
public List<Group> listGroupsByUser(String userId);
/**
*
* 保存变量
* @param executionId
* @param variables
*/
public void saveVariables(String executionId, Map<String, ?> variables);
/**
*
* 取得开始节点
*
* @param processDefinitionId
* @return
*/
public ActivityImpl getStartNodeByProcessDefinitionId(
String processDefinitionId);
/**
*
* 取得开始节点下一个节点
*
* @param processDefinitionId
* @return
*/
public ActivityImpl getNextNodeFromStartNodeByProcessDefinitionId(
String processDefinitionId) ;
/**
* 取得开始节点下一个节点
*
* @param processInstanceId
* @return
*/
public ActivityImpl getNextNodeFromStartNodeByProcessInstanceId(
String processInstanceId) ;
/**
* 取得decision节点表达式的值
*/
public String getExprByProcessInstanceId(String processInstanceId) ;
/**
*
* 取得decision节点表达式的值
*/
public String getExprByProcessDefinitionId(String processDefinitionId) ;
/**
*
* 流程下一步,执行任务 Map<String, Object> variables = new HashMap<String,
* Object>();
* variables.put(this.getGenericProcessEngine().getExpr("leave.11"), "是");
* this.getGenericProcessEngine().nextToSaveVar("emp", "leave.11",
* variables); String
* name=this.getGenericProcessEngine().getCurrentNodeName("leave.11");
*/
public void nextToSaveVar(String userName, String processInstanceId,
Map<String, ?> variables) ;
/**
*
* 当下一节点是decision节点时,启动流程
*/
public ProcessInstance startProcessToSaveVar(String processDefinitionId);
}
---------------------------------
GenericProcessEngineImpl.java
package workflow.engine.service.impl;
@Component("genericProcessEngineImpl")
public class GenericProcessEngineImpl implements GenericProcessEngine {
@Resource(name = "historyService")
private HistoryService historyService;
@Resource(name = "managementService")
private ManagementService managementService;
@Resource(name = "taskService")
private TaskService taskService;
@Resource(name = "identityService")
private IdentityService identityService;
private String configurationResource = "jbpm4/jbpm.cfg.xml";
private static Log log = LogFactory.getLog(GenericProcessEngineImpl.class);
@Resource(name = "processEngine")
private ProcessEngine processEngine;
@Resource(name = "repositoryService")
private RepositoryService repositoryService;
@Resource(name = "executionService")
private ExecutionService executionService;
public String createDeployment(String url) {
EnvironmentFactory environmentFactory = (EnvironmentFactory) processEngine;
Environment environment = environmentFactory.openEnvironment();
NewDeployment newDeployment = null;
try {
newDeployment = repositoryService.createDeployment()
.addResourceFromClasspath(url);
newDeployment.setName(url);
// return newDeployment.deploy();
} catch (Exception ex) {
ex.printStackTrace();
}
finally {
// environment.close();
return newDeployment.deploy();
}
}
public String createDeployment(FileItem fileItem) {
String fileItemName = fileItem.getName();
try {
NewDeployment newDeployment =
repositoryService.createDeployment().addResourceFromInputStream(
fileItemName, fileItem.getInputStream());
newDeployment.setName(fileItemName);
String deploymentId = newDeployment.deploy();
log.debug("Created a processdefinition : " + deploymentId);
return "上传" + fileItemName + "成功";
} catch (IOException e) {
return "IOException";
}
}
public boolean deleteDeploymenFileByProcessDefinitionId(
String processDefinitionId) {
boolean flag = false;
String deploymentId = this.getProcessDefinitionByProcessDefinitionId(
processDefinitionId).getDeploymentId();
List<ProcessInstance> pis = this.executionService
.createProcessInstanceQuery().processDefinitionId(
processDefinitionId).list();
if (pis.size() == 0)
flag = true;
else
flag = false;
if (flag)
repositoryService.deleteDeployment(deploymentId);
return flag;
}
public boolean deleteDeploymentFile(String deploymentId) {
boolean flag = false;
ProcessDefinition pd = this
.getProcessDefinitionByDeploymentId(deploymentId);
if (pd == null)
return false;
List<ProcessInstance> pis = this.executionService
.createProcessInstanceQuery().processDefinitionId(pd.getId())
.list();
for (ProcessInstance pi : pis) {
if (pi.isEnded())
flag = true;
else
flag = false;
}
if (pis.size() == 0)
flag = true;
else
flag = false;
if (flag)
repositoryService.deleteDeployment(deploymentId);
return flag;
}
public void endProcessInstance(String processInstanceId) {
this.executionService.endProcessInstance(processInstanceId,
ProcessInstance.STATE_ENDED);
}
public ActivityCoordinates getActivityCoordinates(String processInstanceId) {
String pdId = this.getProcessDefinitionByProcessInstanceId(
processInstanceId).getId();
String nodeName = this.getCurrentNodeName(processInstanceId);
if (nodeName == null) {
return null;
}
ActivityCoordinates coordinates = this.repositoryService
.getActivityCoordinates(pdId, nodeName);
return coordinates;
}
public ProcessEngine getCreateProcessEngine() {
Configuration configuration = new Configuration();
configuration.setResource(configurationResource);
processEngine = configuration.buildProcessEngine();
repositoryService = processEngine.getRepositoryService();
return processEngine;
}
public String getCurrentNodeName(String processInstanceId) {
Set<String> activeActivityNames = null;
String nodeName = null;
ProcessInstance pi = this.getProcessInstance(processInstanceId);
if (pi == null)
return null;
ProcessDefinition pd = this
.getProcessDefinitionByProcessInstanceId(processInstanceId);
if (pi == null) {
List<HistoryProcessInstance> list = this.historyService
.createHistoryProcessInstanceQuery().processInstanceId(
processInstanceId).list();
HistoryProcessInstanceImpl hpii = null;
if (list.size() >= 0) {
hpii = (HistoryProcessInstanceImpl) list.get(0);
}
nodeName = hpii.getEndActivityName();
} else {
activeActivityNames = pi.findActiveActivityNames();
if (activeActivityNames.size() >= 1) {
for (String activeActivityName : activeActivityNames) {
nodeName = activeActivityName;
break;
}
}
}
return nodeName;
}
public ProcessEngine getCurrentProcessEngine() {
return this.processEngine;
}
public Transition getDefaultOutgoingTransition(String processInstanceId) {
Transition transition = null;
// ProcessEngine processEngine = this.getCreateProcessEngine();
EnvironmentFactory environmentFactory = (EnvironmentFactory) processEngine;
Environment environment = environmentFactory.openEnvironment();
try {
ExecutionService executionService = processEngine
.getExecutionService();
ProcessInstance pi = executionService.createProcessInstanceQuery()
.processInstanceId
(processInstanceId).uniqueResult();
if (pi == null) {
return transition;
}
ExecutionImpl executionImpl = (ExecutionImpl) pi;
Activity activity = executionImpl.getActivity();
transition = activity.getDefaultOutgoingTransition();
} catch (Exception ex) {
ex.printStackTrace();
}
finally {
// environment.close();
}
return transition;
}
public Deployment getDeployment(long deploymentId) {
return repositoryService.createDeploymentQuery().deploymentDbid(
deploymentId).uniqueResult();
}
public ExecutionService getExecutionService() {
return this.executionService;
}
public InputStream getInputStreamByDeploymentId(String deploymentId,
String jpdlResourceName) {
return repositoryService.getResourceAsStream(deploymentId,
jpdlResourceName);
}
public InputStream getInputStreamBytProcessDefinitionId(
String processDefinitionId, String jpdlResourceName) {
String deploymentId = this.getProcessDefinitionByProcessDefinitionId(
processDefinitionId).getDeploymentId();
return repositoryService.getResourceAsStream(deploymentId,
jpdlResourceName);
}
public ProcessDefinition getProcessDefinitionByDeploymentId(
String deploymentId) {
ProcessDefinitionQuery query = repositoryService
.createProcessDefinitionQuery().deploymentId(deploymentId);
ProcessDefinition pd = null;
if (query != null) {
pd = query.uniqueResult();
}
return pd;
}
public ProcessDefinition getProcessDefinitionByName(
String processDefinitionName) {
ProcessDefinitionQuery query = this.repositoryService
.createProcessDefinitionQuery().processDefinitionName(
processDefinitionName).orderDesc(
ProcessDefinitionQuery.PROPERTY_VERSION);
List<ProcessDefinition> list = query.list();
if (list == null) {
return null;
}
if (list.size() >= 1) {
return (ProcessDefinition) list.get(0);
} else {
return null;
}
}
public ProcessDefinition getProcessDefinitionByProcessDefinitionId(
String processDefinitionId) {
return repositoryService.createProcessDefinitionQuery()
.processDefinitionId(processDefinitionId).uniqueResult();
}
public ProcessDefinition getProcessDefinitionByProcessInstanceId(
String processInstanceId) {
HistoryProcessInstance hpi = this.historyService
.createHistoryProcessInstanceQuery().processInstanceId(
processInstanceId).uniqueResult();
if (hpi == null)
return null;
return this.getProcessDefinitionByProcessDefinitionId(hpi
.getProcessDefinitionId());
}
public ProcessInstance getProcessInstance(String processInstanceId) {
return executionService.createProcessInstanceQuery().processInstanceId(
processInstanceId).uniqueResult();
}
public RepositoryService getRepositoryService() {
return this.repositoryService;
}
public List<Transition> getTransitions(String processInstanceId) {
List<Transition> transitions = null;
// ProcessEngine processEngine = this.getCreateProcessEngine();
EnvironmentFactory environmentFactory = (EnvironmentFactory) processEngine;
Environment environment = environmentFactory.openEnvironment();
try {
ProcessInstance pi = executionService.createProcessInstanceQuery()
.processInstanceId
(processInstanceId).uniqueResult();
ExecutionImpl executionImpl = (ExecutionImpl) pi;
Activity activity = executionImpl.getActivity();
transitions = activity.getOutgoingTransitions();
} catch (Exception ex) {
ex.printStackTrace();
}
finally {
// environment.close();
}
return transitions;
}
public List<ProcessDefinition> listProcessDefinitions() {
List<ProcessDefinition> list = repositoryService
.createProcessDefinitionQuery().list();
return list;
}
public List<ProcessInstance> listProcessInstance() {
List<ProcessInstance> list = executionService
.createProcessInstanceQuery().list();
return list;
}
public List<ProcessInstance> listProcessInstanceByProcessDefinitionId(
String processDefinitionId) {
List<ProcessInstance> list = executionService
.createProcessInstanceQuery().processDefinitionId(
processDefinitionId).list();
return list;
}
public boolean processInstancIsEND(String processInstanceId) {
ProcessInstance pi = this.getProcessInstance(processInstanceId);
if (pi == null) {
return true;
} else
return false;
}
public boolean processInstancIsEND_reserve(String processInstanceId) {
HistoryProcessInstance hpi = this.historyService
.createHistoryProcessInstanceQuery().processInstanceId(
processInstanceId).uniqueResult();
String state = "";
if (hpi == null) {
return true;
} else {
state = hpi.getState();
}
if (HistoryProcessInstance.STATE_ENDED.equals(state)) {
return true;
} else {
return false;
}
}
public void signal(String executionId) {
ProcessInstance pi = this.getProcessInstance(executionId);
if (pi != null) {
Transition tr = this.getDefaultOutgoingTransition(executionId);
if (tr != null) {
String signalName = tr.getName();
this.signal(executionId, signalName);
}
}
}
public void signal(String executionId, String signalName) {
this.executionService.signalExecutionById(executionId, signalName);
}
public ProcessInstance startProcess(String processDefinitionId) {
String trName = this.getNextNodeFromStartNodeByProcessDefinitionId(
processDefinitionId).getDefaultOutgoingTransition().getName();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put(this.getExprByProcessDefinitionId(processDefinitionId),
trName);
ProcessInstance pi = executionService.startProcessInstanceById(
processDefinitionId, variables);
return pi;
}
public ProcessInstance startProcess(String processDefinitionId,
Map<String, Object> variables) {
ProcessInstance pi = executionService.startProcessInstanceById(
processDefinitionId, variables);
return pi;
}
public List<HistoryProcessInstance> ListHistoryProcessInstance() {
return this.historyService.createHistoryProcessInstanceQuery().list();
}
public ProcessEngine getCreateProcessEngine(String resource) {
configurationResource = resource;
Configuration configuration = new Configuration();
configuration.setResource(configurationResource);
processEngine = configuration.buildProcessEngine();
repositoryService = processEngine.getRepositoryService();
return processEngine;
}
public Activity getCurrentNode(String processInstanceId) {
Activity activity = null;
// ProcessEngine processEngine = this.getCreateProcessEngine();
EnvironmentFactory environmentFactory = (EnvironmentFactory) processEngine;
Environment environment = environmentFactory.openEnvironment();
environmentFactory.openEnvironment();
try {
ProcessInstance pi = executionService.createProcessInstanceQuery()
.processInstanceId(processInstanceId).uniqueResult();
ExecutionImpl executionImpl = (ExecutionImpl) pi;
activity = executionImpl.getActivity();
} catch (Exception ex) {
ex.printStackTrace();
}
finally {
// environment.close();
}
return activity;
}
public void init() {
log.info("historyService=" + historyService);
log.info("managementService=" + managementService);
log.info("taskService=" + taskService);
log.info("identityService=" + identityService);
}
public HistoryService getHistoryService() {
return this.historyService;
}
public IdentityService getIdentityService() {
return this.identityService;
}
public ManagementService getManagementService() {
return this.managementService;
}
public TaskService getTaskService() {
return this.taskService;
}
public Map<String, Object> getVariables(String processInstanceId) {
Set<String> variableNames = executionService
.getVariableNames(processInstanceId);
return executionService.getVariables(processInstanceId, variableNames);
}
// 查看变量
public List<VariablesBean> getVariablesList(String processInstanceId) {
Map<String, Object> map = this.getVariables(processInstanceId);
ArrayList arraylist = new ArrayList();
if (map == null) {
return arraylist;
}
Set set = map.keySet();
Iterator it = set.iterator();
while (it.hasNext()) {
String variableName = (String) it.next();
// String[] variableValue = (String[]) map.get(variableName);
Object variableValue = map.get(variableName);
VariablesBean bean = new VariablesBean();
bean.setProcessInstanceId(processInstanceId);
bean.setProcessInstanceName("");
bean.setName(variableName);
// bean.setValue(variableValue);
bean.setValue(null);
arraylist.add(bean);
}
return arraylist;
}
public List<Task> listAllTasks() {
List<Task> list = this.taskService.createTaskQuery().list();
return list;
}
public List<Task> listTasksByActorName(String taskActorName) {
List<Task> list = this.taskService.createTaskQuery().assignee(
taskActorName).list();
return list;
}
public void taskEnd(String taskId) {
this.taskService.completeTask(taskId);
}
public void taskEnd(String taskId, String availableTransitionsName) {
this.taskService.completeTask(taskId, availableTransitionsName);
}
public void saveVariables(String executionId, Map<String, ?> variables) {
this.executionService.setVariables(executionId, variables);
}
public ActivityImpl getStartNodeByProcessDefinitionId(
String processDefinitionId) {
JpdlProcessDefinition jpdlProcessDefinition = (JpdlProcessDefinition) this
.getProcessDefinitionByProcessDefinitionId(processDefinitionId);
return jpdlProcessDefinition.getInitial();
}
@Override
public List<Task> listAllTasksByProcessInstanceId(String processInstanceId) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<Group> listGroupsByUser(String userId) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<User> listUsers() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean taskIsEnd(String taskId) throws Exception {
// TODO Auto-generated method stub
return false;
}
/**
*
* 取得开始节点下一个节点
*
* @param processDefinitionId
* @return
*/
public ActivityImpl getNextNodeFromStartNodeByProcessDefinitionId(
String processDefinitionId) {
ActivityImpl start = this
.getStartNodeByProcessDefinitionId(processDefinitionId);
ActivityImpl end = start.getDefaultOutgoingTransition()
.getDestination();
return end;
}
/**
* 取得开始节点下一个节点
*
* @param processInstanceId
* @return
*/
public ActivityImpl getNextNodeFromStartNodeByProcessInstanceId(
String processInstanceId) {
ProcessDefinition pd = this
.getProcessDefinitionByProcessInstanceId(processInstanceId);
ActivityImpl start = this.getStartNodeByProcessDefinitionId(pd.getId());
ActivityImpl end = start.getDefaultOutgoingTransition()
.getDestination();
return end;
}
/**
* 取得decision节点表达式的值
*/
public String getExprByProcessInstanceId(String processInstanceId) {
String expr = null;
ExecutionImpl executionImpl = (ExecutionImpl) this
.getProcessInstance(processInstanceId);
String type = executionImpl.getActivity().getType();
if (type.equals("state")) {
return expr;
}
if (type.equals("task")) {
return expr;
}
if (type.equals("decision")) {
ProcessDefinition pd = this
.getProcessDefinitionByProcessInstanceId(processInstanceId);
Deployment d = this.getDeployment(Long
.valueOf(pd.getDeploymentId()));
InputStream is = this.getInputStreamBytProcessDefinitionId(pd
.getId(), d.getName());
XmlUtil xu = new XmlUtil();
try {
expr = xu.getExpr(is, "decision");
if (expr != null) {
expr = xu.getExprFromPattern(expr);
}
} catch (DocumentException e) {
e.printStackTrace();
}
return expr;
}
return expr;
}
/**
*
* 取得decision节点表达式的值
*/
public String getExprByProcessDefinitionId(String processDefinitionId) {
ProcessDefinition pd = this
.getProcessDefinitionByProcessDefinitionId(processDefinitionId);
Deployment d = this.getDeployment(Long.valueOf(pd.getDeploymentId()));
InputStream is = this.getInputStreamBytProcessDefinitionId(
processDefinitionId, d.getName());
XmlUtil xu = new XmlUtil();
String expr = null;
try {
expr = xu.getExpr(is, "decision");
if (expr != null) {
expr = xu.getExprFromPattern(expr);
}
} catch (DocumentException e) {
e.printStackTrace();
}
return expr;
}
/**
*
* 流程下一步,执行任务 Map<String, Object> variables = new HashMap<String,
* Object>();
* variables.put(this.getGenericProcessEngine().getExpr("leave.11"), "是");
* this.getGenericProcessEngine().nextToSaveVar("emp", "leave.11",
* variables); String
* name=this.getGenericProcessEngine().getCurrentNodeName("leave.11");
*/
public void nextToSaveVar(String userName, String processInstanceId,
Map<String, ?> variables) {
ExecutionImpl executionImpl = (ExecutionImpl) this
.getProcessInstance(processInstanceId);
String type = executionImpl.getActivity().getType();
if (type.equals("state")) {
this.signal(processInstanceId);
}
if (type.equals("decision")) {
}
if (type.equals("task")) {
this.saveVariables(processInstanceId, variables);
Task task = this.getTaskService().createTaskQuery()
.processInstanceId(processInstanceId).assignee(userName)
.uniqueResult();
this.taskEnd(task.getId());
}
}
/**
*
* 当下一节点是decision节点时,启动流程
*/
public ProcessInstance startProcessToSaveVar(String processDefinitionId) {
String trName = this.getNextNodeFromStartNodeByProcessDefinitionId(
processDefinitionId).getDefaultOutgoingTransition().getName();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put(this.getExprByProcessDefinitionId(processDefinitionId),
trName);
return this.startProcess(processDefinitionId, variables);
}
}
jbpm4.1应用接口定义与实现
---------------------------------
GenericProcessEngine.java
package workflow.engine.service;
public interface GenericProcessEngine {
/**
* 创建流程引擎并返回流程引擎
*
* @return
*/
public ProcessEngine getCreateProcessEngine();
/**
* 创建流程引擎并返回流程引擎
*
* @param configurationResource
* 文件jbpm.cfg.xml的路径
* @return
*/
public ProcessEngine getCreateProcessEngine(String configurationResource);
/**
* 不创建流程引擎并返回当前线程中的流程引擎
*
* @return
*/
public ProcessEngine getCurrentProcessEngine();
/**
* 发布流程文件(流程定义)
*
* @param url
* @return
*/
public String createDeployment(String url);
/**
*
* 上传文件,部署流程文件
*
* @param fileItem
* @return
*/
public String createDeployment(FileItem fileItem);
/**
*
* 删除流程文件(流程定义)
*
* @param processDefinitionId
*/
public boolean deleteDeploymenFileByProcessDefinitionId(
String processDefinitionId);
/**
*
* 删除流程文件(流程定义)
*
* @param deploymentId
*/
public boolean deleteDeploymentFile(String deploymentId);
/**
* 显示所有的流程文件(流程定义)
*
* @return
*/
public List<ProcessDefinition> listProcessDefinitions();
/**
*
* 根据流程定义的ID取得流程定义
*
* @param processDefinitionId
* @return
*/
public ProcessDefinition getProcessDefinitionByProcessDefinitionId(
String processDefinitionId);
/**
*
*
* 根据流程名字得到流程定义
*
* @param processDefinitionName
* @return
*/
public ProcessDefinition getProcessDefinitionByName(
String processDefinitionName);
/**
*
* 根据流程定义的ID启动流程实例
*
* @param processDefinitionId
* @return
*/
public ProcessInstance startProcess(String processDefinitionId);
public ProcessInstance startProcess(String processDefinitionId,
Map<String, Object> variables);
/**
* 根据流程定义的ID显示所有的流程实例
*
* @param processDefinitionId
* @return
*/
public List<ProcessInstance> listProcessInstanceByProcessDefinitionId(
String processDefinitionId);
/**
*
* 显示所有的流程实例
*
* @return
*/
public List<ProcessInstance> listProcessInstance();
/**
*
* 根据流程实例的ID取得流程实例
*
* @param processInstanceId
* @return
*/
public ProcessInstance getProcessInstance(String processInstanceId);
/**
* 根据流程实例的ID取得流程定义
*
* @param processInstanceId
* @return
*/
public ProcessDefinition getProcessDefinitionByProcessInstanceId(
String processInstanceId);
/**
*
* 停止流程实例
*
* @param processInstanceId
*/
public void endProcessInstance(String processInstanceId);
/**
* 根据流程实例的ID取得当前节点
*
* @param processInstanceId
* @return
*/
public Activity getCurrentNode(String processInstanceId);
/**
* 根据流程实例的ID取得当前节点名字
*
* @param processInstanceId
* @return
*/
public String getCurrentNodeName(String processInstanceId);
/**
* 根据流程实例的ID取得当前节点坐标值
*
* @param processInstanceId
* @return
*/
public ActivityCoordinates getActivityCoordinates(String processInstanceId);
/**
*
* 根据流程实例的ID取得缺省的流向
*
* @param processInstanceId
* @return
*/
public Transition getDefaultOutgoingTransition(String processInstanceId);
/**
*
* 根据流程实例的ID取得该节点的所有流向,查看流向
*
* @param processInstanceId
* @return
*/
public List<Transition> getTransitions(String processInstanceId);
/**
* 根据流程实例的ID发送信号
*
* @param executionId
*/
public void signal(String executionId);
/**
* 根据流程实例的ID发送信号
*
* @param executionId
* @param signalName
*/
public void signal(String executionId, String signalName);
/**
*
* 根据流程定义获得InputStream
*
* @param processDefinitionId
* @param jpdlResourceName
* @return
*/
public InputStream getInputStreamBytProcessDefinitionId(
String processDefinitionId, String jpdlResourceName);
/**
*
* 根据部署ID获得InputStream
*
* @param deploymentId
* @param jpdlResourceName
* @return
*/
public InputStream getInputStreamByDeploymentId(String deploymentId,
String jpdlResourceName);
/**
*
* 取得管理 流程定义的资源的储存库服务
*
* @return
*/
public RepositoryService getRepositoryService();
/**
*
* 取得管理 运行时的执行服务
*
* @return
*/
public ExecutionService getExecutionService();
/**
*
* 历史服务
*
* @return
*/
public HistoryService getHistoryService();
public ManagementService getManagementService();
/**
*
* 任务服务
*
* @return
*/
public TaskService getTaskService();
/**
* 身份服务
*
* @return
*/
public IdentityService getIdentityService();
/**
*
* 根据部署ID得到流程定义
*
* @param deploymentId
* @return
*/
public ProcessDefinition getProcessDefinitionByDeploymentId(
String deploymentId);
/**
*
* 根据部署ID得到部署
*
* @param deploymentId
* @return
*/
public Deployment getDeployment(long deploymentId);
/**
*
* 显示所有的历史流程实例
*
* @return
*/
public List<HistoryProcessInstance> ListHistoryProcessInstance();
/**
*
* 初使化
*/
public void init();
/**
* 流程实例是否结束
*
* @param processInstanceId
* @return
*/
public boolean processInstancIsEND(String processInstanceId);
/**
*
* 流程实例是否结束(保留方法)
*
* @param processInstanceId
* @return
*/
public boolean processInstancIsEND_reserve(String processInstanceId);
/**
*
* 结束任务
*
* @param taskId
* @throws Exception
*/
public void taskEnd(String taskId);
/**
* 结束任务,并流向指定的路径
*
* @param taskId
* @param availableTransitionsName
* @throws Exception
*/
public void taskEnd(String taskId, String availableTransitionsName);
/**
*
* 任务是否结束
*
* @param taskId
* @return
* @throws Exception
*/
public boolean taskIsEnd(String taskId) throws Exception;
/**
* 某人所有的任务列表,查看任务状态
*
* @param taskActorName
* @return
* @throws Exception
*/
public List<Task> listTasksByActorName(String taskActorName);
/**
*
* 查看变量
*
* @param processInstanceId
* @return
*/
public Map<String, Object> getVariables(String processInstanceId);
public List<VariablesBean> getVariablesList(String processInstanceId);
/**
*
* 查找所有的任务
*
* @return
*/
public List<Task> listAllTasks();
/**
*
* 查找该流程实例所有的任务
*
* @param processInstanceId
* @return
*/
public List<Task> listAllTasksByProcessInstanceId(String processInstanceId);
/**
* 所有的用户列表
*
* @return
*/
public List<User> listUsers();
/**
*
* 通过用户ID显示所有的分组列表
*
* @param userId
* @return
*/
public List<Group> listGroupsByUser(String userId);
/**
*
* 保存变量
* @param executionId
* @param variables
*/
public void saveVariables(String executionId, Map<String, ?> variables);
/**
*
* 取得开始节点
*
* @param processDefinitionId
* @return
*/
public ActivityImpl getStartNodeByProcessDefinitionId(
String processDefinitionId);
/**
*
* 取得开始节点下一个节点
*
* @param processDefinitionId
* @return
*/
public ActivityImpl getNextNodeFromStartNodeByProcessDefinitionId(
String processDefinitionId) ;
/**
* 取得开始节点下一个节点
*
* @param processInstanceId
* @return
*/
public ActivityImpl getNextNodeFromStartNodeByProcessInstanceId(
String processInstanceId) ;
/**
* 取得decision节点表达式的值
*/
public String getExprByProcessInstanceId(String processInstanceId) ;
/**
*
* 取得decision节点表达式的值
*/
public String getExprByProcessDefinitionId(String processDefinitionId) ;
/**
*
* 流程下一步,执行任务 Map<String, Object> variables = new HashMap<String,
* Object>();
* variables.put(this.getGenericProcessEngine().getExpr("leave.11"), "是");
* this.getGenericProcessEngine().nextToSaveVar("emp", "leave.11",
* variables); String
* name=this.getGenericProcessEngine().getCurrentNodeName("leave.11");
*/
public void nextToSaveVar(String userName, String processInstanceId,
Map<String, ?> variables) ;
/**
*
* 当下一节点是decision节点时,启动流程
*/
public ProcessInstance startProcessToSaveVar(String processDefinitionId);
}
---------------------------------
GenericProcessEngineImpl.java
package workflow.engine.service.impl;
@Component("genericProcessEngineImpl")
public class GenericProcessEngineImpl implements GenericProcessEngine {
@Resource(name = "historyService")
private HistoryService historyService;
@Resource(name = "managementService")
private ManagementService managementService;
@Resource(name = "taskService")
private TaskService taskService;
@Resource(name = "identityService")
private IdentityService identityService;
private String configurationResource = "jbpm4/jbpm.cfg.xml";
private static Log log = LogFactory.getLog(GenericProcessEngineImpl.class);
@Resource(name = "processEngine")
private ProcessEngine processEngine;
@Resource(name = "repositoryService")
private RepositoryService repositoryService;
@Resource(name = "executionService")
private ExecutionService executionService;
public String createDeployment(String url) {
EnvironmentFactory environmentFactory = (EnvironmentFactory) processEngine;
Environment environment = environmentFactory.openEnvironment();
NewDeployment newDeployment = null;
try {
newDeployment = repositoryService.createDeployment()
.addResourceFromClasspath(url);
newDeployment.setName(url);
// return newDeployment.deploy();
} catch (Exception ex) {
ex.printStackTrace();
}
finally {
// environment.close();
return newDeployment.deploy();
}
}
public String createDeployment(FileItem fileItem) {
String fileItemName = fileItem.getName();
try {
NewDeployment newDeployment =
repositoryService.createDeployment().addResourceFromInputStream(
fileItemName, fileItem.getInputStream());
newDeployment.setName(fileItemName);
String deploymentId = newDeployment.deploy();
log.debug("Created a processdefinition : " + deploymentId);
return "上传" + fileItemName + "成功";
} catch (IOException e) {
return "IOException";
}
}
public boolean deleteDeploymenFileByProcessDefinitionId(
String processDefinitionId) {
boolean flag = false;
String deploymentId = this.getProcessDefinitionByProcessDefinitionId(
processDefinitionId).getDeploymentId();
List<ProcessInstance> pis = this.executionService
.createProcessInstanceQuery().processDefinitionId(
processDefinitionId).list();
if (pis.size() == 0)
flag = true;
else
flag = false;
if (flag)
repositoryService.deleteDeployment(deploymentId);
return flag;
}
public boolean deleteDeploymentFile(String deploymentId) {
boolean flag = false;
ProcessDefinition pd = this
.getProcessDefinitionByDeploymentId(deploymentId);
if (pd == null)
return false;
List<ProcessInstance> pis = this.executionService
.createProcessInstanceQuery().processDefinitionId(pd.getId())
.list();
for (ProcessInstance pi : pis) {
if (pi.isEnded())
flag = true;
else
flag = false;
}
if (pis.size() == 0)
flag = true;
else
flag = false;
if (flag)
repositoryService.deleteDeployment(deploymentId);
return flag;
}
public void endProcessInstance(String processInstanceId) {
this.executionService.endProcessInstance(processInstanceId,
ProcessInstance.STATE_ENDED);
}
public ActivityCoordinates getActivityCoordinates(String processInstanceId) {
String pdId = this.getProcessDefinitionByProcessInstanceId(
processInstanceId).getId();
String nodeName = this.getCurrentNodeName(processInstanceId);
if (nodeName == null) {
return null;
}
ActivityCoordinates coordinates = this.repositoryService
.getActivityCoordinates(pdId, nodeName);
return coordinates;
}
public ProcessEngine getCreateProcessEngine() {
Configuration configuration = new Configuration();
configuration.setResource(configurationResource);
processEngine = configuration.buildProcessEngine();
repositoryService = processEngine.getRepositoryService();
return processEngine;
}
public String getCurrentNodeName(String processInstanceId) {
Set<String> activeActivityNames = null;
String nodeName = null;
ProcessInstance pi = this.getProcessInstance(processInstanceId);
if (pi == null)
return null;
ProcessDefinition pd = this
.getProcessDefinitionByProcessInstanceId(processInstanceId);
if (pi == null) {
List<HistoryProcessInstance> list = this.historyService
.createHistoryProcessInstanceQuery().processInstanceId(
processInstanceId).list();
HistoryProcessInstanceImpl hpii = null;
if (list.size() >= 0) {
hpii = (HistoryProcessInstanceImpl) list.get(0);
}
nodeName = hpii.getEndActivityName();
} else {
activeActivityNames = pi.findActiveActivityNames();
if (activeActivityNames.size() >= 1) {
for (String activeActivityName : activeActivityNames) {
nodeName = activeActivityName;
break;
}
}
}
return nodeName;
}
public ProcessEngine getCurrentProcessEngine() {
return this.processEngine;
}
public Transition getDefaultOutgoingTransition(String processInstanceId) {
Transition transition = null;
// ProcessEngine processEngine = this.getCreateProcessEngine();
EnvironmentFactory environmentFactory = (EnvironmentFactory) processEngine;
Environment environment = environmentFactory.openEnvironment();
try {
ExecutionService executionService = processEngine
.getExecutionService();
ProcessInstance pi = executionService.createProcessInstanceQuery()
.processInstanceId
(processInstanceId).uniqueResult();
if (pi == null) {
return transition;
}
ExecutionImpl executionImpl = (ExecutionImpl) pi;
Activity activity = executionImpl.getActivity();
transition = activity.getDefaultOutgoingTransition();
} catch (Exception ex) {
ex.printStackTrace();
}
finally {
// environment.close();
}
return transition;
}
public Deployment getDeployment(long deploymentId) {
return repositoryService.createDeploymentQuery().deploymentDbid(
deploymentId).uniqueResult();
}
public ExecutionService getExecutionService() {
return this.executionService;
}
public InputStream getInputStreamByDeploymentId(String deploymentId,
String jpdlResourceName) {
return repositoryService.getResourceAsStream(deploymentId,
jpdlResourceName);
}
public InputStream getInputStreamBytProcessDefinitionId(
String processDefinitionId, String jpdlResourceName) {
String deploymentId = this.getProcessDefinitionByProcessDefinitionId(
processDefinitionId).getDeploymentId();
return repositoryService.getResourceAsStream(deploymentId,
jpdlResourceName);
}
public ProcessDefinition getProcessDefinitionByDeploymentId(
String deploymentId) {
ProcessDefinitionQuery query = repositoryService
.createProcessDefinitionQuery().deploymentId(deploymentId);
ProcessDefinition pd = null;
if (query != null) {
pd = query.uniqueResult();
}
return pd;
}
public ProcessDefinition getProcessDefinitionByName(
String processDefinitionName) {
ProcessDefinitionQuery query = this.repositoryService
.createProcessDefinitionQuery().processDefinitionName(
processDefinitionName).orderDesc(
ProcessDefinitionQuery.PROPERTY_VERSION);
List<ProcessDefinition> list = query.list();
if (list == null) {
return null;
}
if (list.size() >= 1) {
return (ProcessDefinition) list.get(0);
} else {
return null;
}
}
public ProcessDefinition getProcessDefinitionByProcessDefinitionId(
String processDefinitionId) {
return repositoryService.createProcessDefinitionQuery()
.processDefinitionId(processDefinitionId).uniqueResult();
}
public ProcessDefinition getProcessDefinitionByProcessInstanceId(
String processInstanceId) {
HistoryProcessInstance hpi = this.historyService
.createHistoryProcessInstanceQuery().processInstanceId(
processInstanceId).uniqueResult();
if (hpi == null)
return null;
return this.getProcessDefinitionByProcessDefinitionId(hpi
.getProcessDefinitionId());
}
public ProcessInstance getProcessInstance(String processInstanceId) {
return executionService.createProcessInstanceQuery().processInstanceId(
processInstanceId).uniqueResult();
}
public RepositoryService getRepositoryService() {
return this.repositoryService;
}
public List<Transition> getTransitions(String processInstanceId) {
List<Transition> transitions = null;
// ProcessEngine processEngine = this.getCreateProcessEngine();
EnvironmentFactory environmentFactory = (EnvironmentFactory) processEngine;
Environment environment = environmentFactory.openEnvironment();
try {
ProcessInstance pi = executionService.createProcessInstanceQuery()
.processInstanceId
(processInstanceId).uniqueResult();
ExecutionImpl executionImpl = (ExecutionImpl) pi;
Activity activity = executionImpl.getActivity();
transitions = activity.getOutgoingTransitions();
} catch (Exception ex) {
ex.printStackTrace();
}
finally {
// environment.close();
}
return transitions;
}
public List<ProcessDefinition> listProcessDefinitions() {
List<ProcessDefinition> list = repositoryService
.createProcessDefinitionQuery().list();
return list;
}
public List<ProcessInstance> listProcessInstance() {
List<ProcessInstance> list = executionService
.createProcessInstanceQuery().list();
return list;
}
public List<ProcessInstance> listProcessInstanceByProcessDefinitionId(
String processDefinitionId) {
List<ProcessInstance> list = executionService
.createProcessInstanceQuery().processDefinitionId(
processDefinitionId).list();
return list;
}
public boolean processInstancIsEND(String processInstanceId) {
ProcessInstance pi = this.getProcessInstance(processInstanceId);
if (pi == null) {
return true;
} else
return false;
}
public boolean processInstancIsEND_reserve(String processInstanceId) {
HistoryProcessInstance hpi = this.historyService
.createHistoryProcessInstanceQuery().processInstanceId(
processInstanceId).uniqueResult();
String state = "";
if (hpi == null) {
return true;
} else {
state = hpi.getState();
}
if (HistoryProcessInstance.STATE_ENDED.equals(state)) {
return true;
} else {
return false;
}
}
public void signal(String executionId) {
ProcessInstance pi = this.getProcessInstance(executionId);
if (pi != null) {
Transition tr = this.getDefaultOutgoingTransition(executionId);
if (tr != null) {
String signalName = tr.getName();
this.signal(executionId, signalName);
}
}
}
public void signal(String executionId, String signalName) {
this.executionService.signalExecutionById(executionId, signalName);
}
public ProcessInstance startProcess(String processDefinitionId) {
String trName = this.getNextNodeFromStartNodeByProcessDefinitionId(
processDefinitionId).getDefaultOutgoingTransition().getName();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put(this.getExprByProcessDefinitionId(processDefinitionId),
trName);
ProcessInstance pi = executionService.startProcessInstanceById(
processDefinitionId, variables);
return pi;
}
public ProcessInstance startProcess(String processDefinitionId,
Map<String, Object> variables) {
ProcessInstance pi = executionService.startProcessInstanceById(
processDefinitionId, variables);
return pi;
}
public List<HistoryProcessInstance> ListHistoryProcessInstance() {
return this.historyService.createHistoryProcessInstanceQuery().list();
}
public ProcessEngine getCreateProcessEngine(String resource) {
configurationResource = resource;
Configuration configuration = new Configuration();
configuration.setResource(configurationResource);
processEngine = configuration.buildProcessEngine();
repositoryService = processEngine.getRepositoryService();
return processEngine;
}
public Activity getCurrentNode(String processInstanceId) {
Activity activity = null;
// ProcessEngine processEngine = this.getCreateProcessEngine();
EnvironmentFactory environmentFactory = (EnvironmentFactory) processEngine;
Environment environment = environmentFactory.openEnvironment();
environmentFactory.openEnvironment();
try {
ProcessInstance pi = executionService.createProcessInstanceQuery()
.processInstanceId(processInstanceId).uniqueResult();
ExecutionImpl executionImpl = (ExecutionImpl) pi;
activity = executionImpl.getActivity();
} catch (Exception ex) {
ex.printStackTrace();
}
finally {
// environment.close();
}
return activity;
}
public void init() {
log.info("historyService=" + historyService);
log.info("managementService=" + managementService);
log.info("taskService=" + taskService);
log.info("identityService=" + identityService);
}
public HistoryService getHistoryService() {
return this.historyService;
}
public IdentityService getIdentityService() {
return this.identityService;
}
public ManagementService getManagementService() {
return this.managementService;
}
public TaskService getTaskService() {
return this.taskService;
}
public Map<String, Object> getVariables(String processInstanceId) {
Set<String> variableNames = executionService
.getVariableNames(processInstanceId);
return executionService.getVariables(processInstanceId, variableNames);
}
// 查看变量
public List<VariablesBean> getVariablesList(String processInstanceId) {
Map<String, Object> map = this.getVariables(processInstanceId);
ArrayList arraylist = new ArrayList();
if (map == null) {
return arraylist;
}
Set set = map.keySet();
Iterator it = set.iterator();
while (it.hasNext()) {
String variableName = (String) it.next();
// String[] variableValue = (String[]) map.get(variableName);
Object variableValue = map.get(variableName);
VariablesBean bean = new VariablesBean();
bean.setProcessInstanceId(processInstanceId);
bean.setProcessInstanceName("");
bean.setName(variableName);
// bean.setValue(variableValue);
bean.setValue(null);
arraylist.add(bean);
}
return arraylist;
}
public List<Task> listAllTasks() {
List<Task> list = this.taskService.createTaskQuery().list();
return list;
}
public List<Task> listTasksByActorName(String taskActorName) {
List<Task> list = this.taskService.createTaskQuery().assignee(
taskActorName).list();
return list;
}
public void taskEnd(String taskId) {
this.taskService.completeTask(taskId);
}
public void taskEnd(String taskId, String availableTransitionsName) {
this.taskService.completeTask(taskId, availableTransitionsName);
}
public void saveVariables(String executionId, Map<String, ?> variables) {
this.executionService.setVariables(executionId, variables);
}
public ActivityImpl getStartNodeByProcessDefinitionId(
String processDefinitionId) {
JpdlProcessDefinition jpdlProcessDefinition = (JpdlProcessDefinition) this
.getProcessDefinitionByProcessDefinitionId(processDefinitionId);
return jpdlProcessDefinition.getInitial();
}
@Override
public List<Task> listAllTasksByProcessInstanceId(String processInstanceId) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<Group> listGroupsByUser(String userId) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<User> listUsers() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean taskIsEnd(String taskId) throws Exception {
// TODO Auto-generated method stub
return false;
}
/**
*
* 取得开始节点下一个节点
*
* @param processDefinitionId
* @return
*/
public ActivityImpl getNextNodeFromStartNodeByProcessDefinitionId(
String processDefinitionId) {
ActivityImpl start = this
.getStartNodeByProcessDefinitionId(processDefinitionId);
ActivityImpl end = start.getDefaultOutgoingTransition()
.getDestination();
return end;
}
/**
* 取得开始节点下一个节点
*
* @param processInstanceId
* @return
*/
public ActivityImpl getNextNodeFromStartNodeByProcessInstanceId(
String processInstanceId) {
ProcessDefinition pd = this
.getProcessDefinitionByProcessInstanceId(processInstanceId);
ActivityImpl start = this.getStartNodeByProcessDefinitionId(pd.getId());
ActivityImpl end = start.getDefaultOutgoingTransition()
.getDestination();
return end;
}
/**
* 取得decision节点表达式的值
*/
public String getExprByProcessInstanceId(String processInstanceId) {
String expr = null;
ExecutionImpl executionImpl = (ExecutionImpl) this
.getProcessInstance(processInstanceId);
String type = executionImpl.getActivity().getType();
if (type.equals("state")) {
return expr;
}
if (type.equals("task")) {
return expr;
}
if (type.equals("decision")) {
ProcessDefinition pd = this
.getProcessDefinitionByProcessInstanceId(processInstanceId);
Deployment d = this.getDeployment(Long
.valueOf(pd.getDeploymentId()));
InputStream is = this.getInputStreamBytProcessDefinitionId(pd
.getId(), d.getName());
XmlUtil xu = new XmlUtil();
try {
expr = xu.getExpr(is, "decision");
if (expr != null) {
expr = xu.getExprFromPattern(expr);
}
} catch (DocumentException e) {
e.printStackTrace();
}
return expr;
}
return expr;
}
/**
*
* 取得decision节点表达式的值
*/
public String getExprByProcessDefinitionId(String processDefinitionId) {
ProcessDefinition pd = this
.getProcessDefinitionByProcessDefinitionId(processDefinitionId);
Deployment d = this.getDeployment(Long.valueOf(pd.getDeploymentId()));
InputStream is = this.getInputStreamBytProcessDefinitionId(
processDefinitionId, d.getName());
XmlUtil xu = new XmlUtil();
String expr = null;
try {
expr = xu.getExpr(is, "decision");
if (expr != null) {
expr = xu.getExprFromPattern(expr);
}
} catch (DocumentException e) {
e.printStackTrace();
}
return expr;
}
/**
*
* 流程下一步,执行任务 Map<String, Object> variables = new HashMap<String,
* Object>();
* variables.put(this.getGenericProcessEngine().getExpr("leave.11"), "是");
* this.getGenericProcessEngine().nextToSaveVar("emp", "leave.11",
* variables); String
* name=this.getGenericProcessEngine().getCurrentNodeName("leave.11");
*/
public void nextToSaveVar(String userName, String processInstanceId,
Map<String, ?> variables) {
ExecutionImpl executionImpl = (ExecutionImpl) this
.getProcessInstance(processInstanceId);
String type = executionImpl.getActivity().getType();
if (type.equals("state")) {
this.signal(processInstanceId);
}
if (type.equals("decision")) {
}
if (type.equals("task")) {
this.saveVariables(processInstanceId, variables);
Task task = this.getTaskService().createTaskQuery()
.processInstanceId(processInstanceId).assignee(userName)
.uniqueResult();
this.taskEnd(task.getId());
}
}
/**
*
* 当下一节点是decision节点时,启动流程
*/
public ProcessInstance startProcessToSaveVar(String processDefinitionId) {
String trName = this.getNextNodeFromStartNodeByProcessDefinitionId(
processDefinitionId).getDefaultOutgoingTransition().getName();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put(this.getExprByProcessDefinitionId(processDefinitionId),
trName);
return this.startProcess(processDefinitionId, variables);
}
}
相关推荐
- **插件系统**:jBPM4.1支持插件机制,可以通过实现特定接口来扩展其功能。 - **事件监听器**:利用事件监听器可以捕捉到流程执行过程中发生的各种事件,并在适当的时候执行相应的逻辑。 **5. 高级特性** - **...
流程定义与执行 - **流程定义语言**:jBPM 4.1支持使用多种格式来定义流程,其中XML是一种常用的方式。文档中提到的“899:;:<=>51旧书网w w w.51jiushu.com”等内容虽然看起来无关,但如果这部分内容原本是关于XML...
总之,jBPM4.1用户指南是一本全面介绍如何使用jBPM 4.1版本的中文参考书,涵盖了从基础概念到高级特性的各个方面,对于想要深入理解和应用jBPM的开发者和业务人员来说,是一份不可或缺的资源。通过阅读这份指南,...
1. **流程定义与建模**: - 支持通过XML格式定义业务流程模型,同时提供了图形化的设计工具,方便非技术人员参与流程设计。 - 具备高级的流程建模能力,如循环、条件分支等复杂逻辑的实现。 2. **任务管理**: -...
JBPM4.1是该系统的一个重要版本,它为开发者提供了丰富的功能,以实现复杂业务流程的建模、执行和监控。本手册将深入探讨JBPM4.1.3的核心特性,帮助读者掌握这一强大的流程管理工具。 1. **基本概念** - **流程...
它深入探讨了jBPM的内部机制和编程模型,涵盖了流程定义语言(如BPMN 2.0)、工作流引擎的使用、事件处理、规则集成(与Drools规则引擎的配合)、异常处理和事务管理等内容。开发者可以通过学习开发指南,了解如何...
jbPM4的任务管理功能允许用户通过任务服务接口与任务进行交互,如领取、完成、委托任务。同时,它支持自定义任务监听器,以便在任务生命周期的不同阶段执行特定操作。 **5. 数据集成** jbPM4集成了JPA(Java ...
- **创建Action类**:在Java项目中新建一个类,实现特定接口以定义动作的行为。 - **集成Action**:在流程定义中调用该Action,从而实现具体的业务逻辑处理。 ##### 6.2 集成Hello World Action 接下来,需要在...
6. **工作流服务**:提供API和Web服务接口,方便与其他系统集成,实现跨系统的流程协作。 7. **监控和报表**:提供丰富的监控工具和报表,帮助企业分析流程性能,发现瓶颈并进行优化。 8. **可扩展性**:JBPM的...
本文详细介绍了JBPM中事件与动作的基本概念及其实现方法,重点讲解了如何利用Action实现自动节点以及结束流程的操作,并给出了使用Beanshell脚本替代传统Action类的方法。通过学习本文的内容,相信读者可以更好地...
- **数据库集成**:介绍如何将jBPM与数据库集成,实现持久化存储。 - **技术要点**:使用JPA或Hibernate等ORM框架。 #### 3.3 Context example: process variables - **上下文变量**:在流程执行过程中,如何管理和...
4.1 jBPM API 16 4.11 Knowledge Base 17 4.12 会话 17 4.13 事件 19 4.2. Knowledge-based API 21 第五章 核心引擎:基础 21 5.1 创建一个流程 21 5.1.1 Eclipse BPMN2.0图形编辑器插件 22 5.1.2 使用XML定义流程 ...
jBPM4.1和4.0的中文用户手册将详细介绍如何配置和使用这个平台,包括如何定义流程、设置业务规则、管理任务以及监控流程执行情况。手册中可能会涵盖如何使用多线程来优化流程执行,以及jBPM在实现过程中如何巧妙地...
核心API是jBPM的基础,提供了与jBPM核心引擎交互的接口。 ##### 4.1.1 KnowledgeBase 知识库用于管理业务知识,包括流程定义和规则。 ##### 4.1.2 Session 会话对象允许用户与jBPM引擎交互,例如启动和管理流程...
- **定义**: JBPM 是一款高度灵活的业务流程管理(Business Process Management, BPM)组件,其设计初衷是为用户提供一套完整的业务流程建模、执行与监控的解决方案。 - **特点**: - **轻量级**: 架构设计简洁,...
根据给定的文件信息,我们可以深入探讨JBPM-v3.2-userguide中涵盖的关键知识点,主要聚焦于JBPM(Java Business Process Management)的核心组件、功能、应用领域以及配置与部署等层面。 ### 一、JBPM简介 #### ...