package com.vci.server.workflow.event;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
import org.jbpm.api.listener.EventListenerExecution;
|
|
import com.vci.corba.omd.data.BusinessObject;
|
import com.vci.corba.omd.lcm.LifeCycle;
|
import com.vci.corba.omd.lcm.LifeCycleServicePrx;
|
import com.vci.corba.omd.lcm.TransitionVO;
|
import com.vci.server.base.utility.ServerServiceProvider;
|
|
|
/// 返回编制中状态
|
public class ReturnInitialStatus extends TransferStatus {
|
|
private static final long serialVersionUID = -8416047141287575412L;
|
|
/**
|
* 返回是否是流程终止而触发当前事件
|
* @param e
|
* @return
|
*/
|
protected boolean isIntermitting(EventListenerExecution e){
|
boolean res = false;
|
String intermit = (String) e.getProcessInstance().getVariable("intermit");
|
// 平台规则:当全仅当 intermit 的值等于true时,才代表是执行‘流程中止’
|
if(intermit != null && !"".equals(intermit) && "true".equals(intermit)){
|
res = true;
|
}
|
return res;
|
}
|
|
@Override
|
public void doEvent(EventListenerExecution e) throws Exception {
|
// 普通跃迁事件,当且仅当是非‘流程终止’时才执行
|
if(isIntermitting(e)){
|
doEventDetail(e);
|
}
|
}
|
|
|
protected void doEventDetail(EventListenerExecution e) throws Exception{
|
// 设置目标跃迁状态
|
setTargetStatus("Editing");
|
|
// 取出流程里关联的数据
|
BusinessObject[] bos = super.getBusinessObjects();
|
// 取出生命周期名称
|
String lcName = bos[0].lctId;
|
// 构建跃迁数据
|
TransitionVO[] vos = new TransitionVO[bos.length];
|
String[] releaseStatus = new String[bos.length];
|
|
String tagStatus = "Editing";
|
|
LifeCycleServicePrx lcService = ServerServiceProvider.getOMDService().getLifeCycleService();
|
LifeCycle[] lcs = lcService.getLifeCycles();
|
|
Map<String, LifeCycle> mapLC = new HashMap<String, LifeCycle>();
|
for (LifeCycle lc : lcs) {
|
mapLC.put(lc.id, lc);
|
}
|
|
for (int i = 0; i < bos.length; i++) {
|
LifeCycle lc = mapLC.get(bos[i].lctId);
|
if(lc == null){
|
throw new IllegalArgumentException("对象生命周期模型定义异常,没找到对应的生命周期模型定义信息");
|
}
|
|
tagStatus = lc.startState;
|
|
TransitionVO targetTVO = getTransitionVO(lc, bos[i].lcStatus, tagStatus);
|
if(targetTVO == null){
|
throw new IllegalArgumentException("跃迁业务对象生命周期状态异常:'targetStatus' 的参数值 '" + tagStatus + "' 无效,在生命周期 '" + lcName + "' 里不存在。" +
|
" 或者是生命周期里从 '" + bos[i].lcStatus + "' 到 '" + tagStatus + "' 之间的连线不存在,无法进行跃迁!");
|
}
|
vos[i] = targetTVO;
|
// 设置发发布状态值,此事件里值为空(即,不发布,仅做跃迁
|
releaseStatus[i] = "";
|
}
|
|
// 执行跃迁及发布
|
ServerServiceProvider.getBOFService().batchTransferBusinessObjectAndRelease(bos, vos, releaseStatus);
|
}
|
|
|
/**
|
* 查询生命周期节点
|
* @param lcName 生命周期名称
|
* @param lcDestStatus 状态
|
* @return
|
*/
|
protected TransitionVO getTransitionVO(LifeCycle lc, String fromStatus,String toStatus) {
|
if (lc == null || fromStatus == null || toStatus == null) {
|
return null;
|
}
|
|
fromStatus = fromStatus.trim();
|
toStatus = toStatus.trim();
|
|
for (int i = 0; i < lc.routes.length; ++i) {
|
TransitionVO route = lc.routes[i];
|
if (route.destination.equals(toStatus) && route.source.equals(fromStatus)){
|
return route;
|
}
|
}
|
|
return null;
|
}
|
}
|