package com.vci.server.workflow.event; import org.jbpm.api.listener.EventListenerExecution; import com.vci.corba.common.VCIError; import com.vci.corba.omd.data.BusinessObject; import com.vci.corba.omd.lcm.LifeCycle; import com.vci.corba.omd.lcm.TransitionVO; import com.vci.server.base.utility.ServerServiceProvider; /** * 业务对象生命周期状态跃迁事件 *
主逻辑:从流程事件的参数列表中提取出 targetLCStatus 作为要跃迁到的生命周期状态
* @author xiongchao * */ public class TransferStatus extends BaseEvent { /** * */ private static final long serialVersionUID = -8638494241304071397L; /** * 事件参数 目标生命周期状态 */ private String targetStatus = ""; /** * 本地成员变量,目标发布状态,默认为空,即不发布(仅跃迁) */ private String releaseStatus = ""; public String getTargetStatus() { return targetStatus; } public void setTargetStatus(String targetStatus) { this.targetStatus = targetStatus; } public String getReleaseStatus() { return releaseStatus; } public void setReleaseStatus(String releaseStatus) { this.releaseStatus = releaseStatus; } /** * 返回是否是流程终止而触发当前事件 * @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{ /** * 1、取出当前任务名称 * 2、取出本事件在当前任务里的参数 * 3、从参数中提取 targetLCStatus 参数值,如果没有则抛出异常,阻止流程继续提交 * 4、检查 targetLCStatus 是否当前业务类型生命周期有效的状态 */ if(getTargetStatus() == null || "".equals(getTargetStatus())){ throw new IllegalArgumentException("跃迁业务对象生命周期状态异常:'targetStatus' 的参数值为 null 或 空"); } // 取出流程里关联的数据 BusinessObject[] bos = super.getBusinessObjects(); // 取出生命周期名称 String lcName = bos[0].lctId; // 构建跃迁数据 TransitionVO[] vos = new TransitionVO[bos.length]; String[] releaseStatus = new String[bos.length]; for (int i = 0; i < releaseStatus.length; i++) { TransitionVO targetTVO = getTransitionVO(lcName, bos[i].lcStatus, getTargetStatus()); if(targetTVO == null){ throw new IllegalArgumentException("跃迁业务对象生命周期状态异常:'targetStatus' 的参数值 '" + getTargetStatus() + "' 无效,在生命周期 '" + lcName + "' 里不存在。" + " 或者是生命周期里从 '" + bos[i].lcStatus + "' 到 '" + getTargetStatus() + "' 之间的连线不存在,无法进行跃迁!"); } vos[i] = targetTVO; // 设置发发布状态值,此事件里值为空(即,不发布,仅做跃迁 releaseStatus[i] = getReleaseStatus(); } // 执行跃迁及发布 ServerServiceProvider.getBOFService().batchTransferBusinessObjectAndRelease(bos, vos, releaseStatus); } /** * 查询生命周期节点 * @param lcName 生命周期名称 * @param lcDestStatus 状态 * @return */ protected TransitionVO getTransitionVO(String lcName, String lcSrcStatus,String lcDestStatus) { if (lcSrcStatus == null || lcDestStatus == null) { return null; } lcSrcStatus = lcSrcStatus.trim(); lcDestStatus = lcDestStatus.trim(); try { LifeCycle lc = ServerServiceProvider.getOMDService().getLifeCycleService().getLifeCycle(lcName); if(lc == null) { return null; } for (int i = 0; i < lc.routes.length; ++i) { TransitionVO route = lc.routes[i]; if (route.destination.equals(lcDestStatus) && route.source.equals(lcSrcStatus)){ return route; } } } catch (VCIError e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }