package com.vci.server.bof.delegate;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
import com.vci.omd.utils.ObjectTool;
|
import com.vci.server.base.persistence.dao.HibernateSessionFactory;
|
import com.vci.server.cache.OMCacheProvider;
|
import com.vci.server.mw.ServerContextVariable;
|
import com.vci.corba.omd.atm.AttribItem;
|
import com.vci.corba.omd.btm.BtmItem;
|
import com.vci.corba.omd.data.AttributeValue;
|
import com.vci.corba.omd.data.BusinessObject;
|
import com.vci.corba.omd.data.LinkObject;
|
import com.vci.corba.omd.data.RevisionDataInfo;
|
import com.vci.corba.omd.data.VersionDataInfo;
|
import com.vci.corba.omd.lcm.LifeCycle;
|
import com.vci.corba.omd.ltm.LinkType;
|
import com.vci.corba.omd.vrm.VersionRule;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.common.data.VCIInvocationInfo;
|
import com.vci.common.objects.UserEntity;
|
import com.vci.common.utility.ObjectUtility;
|
|
/**
|
* 负责服务器段的初始对象构建,以及升版本、生版次对象的构建
|
* @author VCI_STGK_Lincq
|
*
|
*/
|
public class BOFactoryServerBODelegate extends FactoryBaseDelegate {
|
|
private static BOFactoryServerBODelegate instance = null;
|
public static UserEntity userEntity = null;
|
|
public BOFactoryServerBODelegate() {
|
userEntity = new UserEntity();
|
}
|
|
public static synchronized BOFactoryServerBODelegate getInstance() {
|
if (instance == null) {
|
instance = new BOFactoryServerBODelegate();
|
}
|
|
return instance;
|
}
|
|
public BusinessObject initBusinessObject(String btmName) throws VCIError {
|
try {
|
VCIInvocationInfo vii = HibernateSessionFactory.getVciSessionInfo();
|
if (vii == null)
|
vii = ServerContextVariable.getInvocationInfo();
|
|
BtmItem boItem = getBtmDefine(btmName);
|
BusinessObject bo = new BusinessObject();
|
bo.oid = ObjectUtility.getNewObjectID36();
|
bo.revisionid = ObjectUtility.getNewObjectID36();
|
bo.nameoid = ObjectUtility.getNewObjectID36();
|
bo.btName = btmName;
|
bo.isLastR = true;
|
bo.isFirstR = true;
|
bo.isFirstV = true;
|
bo.isLastV = true;
|
|
bo.creator = vii.userName;
|
bo.createTime = System.currentTimeMillis();
|
bo.modifier = vii.userName;
|
bo.modifyTime = System.currentTimeMillis();
|
bo.revisionRule = boItem.revRuleName;
|
bo.versionRule = String.valueOf(boItem.verRuleName);
|
|
RevisionDataInfo revisonObj = getRevisionSeqVal(boItem.revLevel, boItem.revRuleName, boItem.revInput);
|
VersionDataInfo versionObj = getVersionValue(boItem.verRuleName);
|
bo.revisionSeq = revisonObj.revisionSeq;
|
bo.revisionValue = revisonObj.revisionVal;
|
bo.versionSeq = versionObj.versionSeq;
|
bo.versionValue = versionObj.versionVal;
|
|
|
bo.lctId = boItem.lifeCycle;
|
bo.lcStatus = getLcFirstStatus(boItem.lifeCycle);
|
bo.id = "";
|
bo.name = "";
|
bo.description = "";
|
bo.owner = vii.userName;
|
//bo.checkinBy = vii.userName;
|
bo.fromVersion = "";
|
initTypeAttributeValue(bo);
|
|
BOFactoryServerDelegate.getInstance().dealBusinessObjectNullValue(bo);
|
return bo;
|
} catch (VCIError e) {
|
throw e;
|
} catch (Throwable e) {
|
e.printStackTrace();
|
throw this.getLocalString("P0010SOF-10002", e);
|
}
|
|
}
|
|
// public ClientBusinessObject cloneBusinessObject(ClientBusinessObject fromBo, BtmItem btmItem, AttribItem[] attrItems, boolean isNew, String userName) throws VCIError {
|
// if (isNew || userName == null || userName.trim().equals("")) {
|
// userName = fromBo.getCreator();
|
// }
|
//
|
// ClientBusinessObject toBo = new ClientBusinessObject();
|
// toBo.setOid(ObjectUtility.getNewObjectID36());
|
// toBo.setRevisionid(ObjectUtility.getNewObjectID36());
|
// toBo.setNameoid(ObjectUtility.getNewObjectID36());
|
// toBo.setBtmName(fromBo.getBtmName());
|
// toBo.setIsLastR(1);
|
// toBo.setIsFirstR(1);
|
// toBo.setIsFirstV(1);
|
// toBo.setIsLastV(1);
|
//
|
// toBo.setCreator(userName);
|
// toBo.setCreateTime(String.valueOf(System.currentTimeMillis()));
|
// toBo.setLastModifier(userName);
|
// toBo.setLastModifyTime(String.valueOf(System.currentTimeMillis()));
|
// toBo.setRevisionRule(btmItem.revRuleName);
|
// toBo.setVersionRule(String.valueOf(btmItem.verRuleName));
|
//
|
// if (isNew) {
|
// toBo.setRevisionSeq(fromBo.getRevisionSeq());
|
// toBo.setRevisionValue(fromBo.getRevisionValue());
|
// toBo.setVersionSeq(fromBo.getVersionSeq());
|
// toBo.setVersionValue(fromBo.getVersionValue());
|
// } else {
|
// RevisionDataInfo revisonObj = getRevisionSeqVal(btmItem.revLevel, btmItem.revRuleName, btmItem.revInput);
|
// VersionDataInfo versionObj = getVersionValue(btmItem.verRuleName);
|
// toBo.setRevisionSeq(revisonObj.revisionSeq);
|
// toBo.setRevisionValue(revisonObj.revisionVal);
|
// toBo.setVersionSeq(versionObj.versionSeq);
|
// toBo.setVersionValue(versionObj.versionVal);
|
// }
|
//
|
// toBo.setLctId(fromBo.getLctId());
|
// if (isNew) {
|
// toBo.setLcStatus(fromBo.getLcStatus());
|
// } else {
|
// toBo.setLcStatus(getLcFirstStatus(btmItem.lifeCycle));
|
// }
|
// toBo.setId(fromBo.getId());
|
// toBo.setName(fromBo.getName());
|
// toBo.setDescription(fromBo.getDescription());
|
// toBo.setOwner(userName);
|
// toBo.setCheckinBy(userName);
|
// toBo.setCopyFromVersion("");
|
// initRevisionTypeAttributeValue(fromBo, toBo, attrItems, isNew);
|
//
|
// return toBo;
|
// }
|
//
|
// private void initRevisionTypeAttributeValue(ClientBusinessObject fromBo, ClientBusinessObject toBo, AttribItem[] items, boolean isNew) throws VCIError {
|
// if(isNew){
|
// AttributeValue[] vals = fromBo.getBusinessObject().newAttrValList;
|
// AttributeValue[] valsCopy = new AttributeValue[vals.length];
|
// for (int i = 0; i < valsCopy.length; i++) {
|
// valsCopy[i] = new AttributeValue(vals[i].attrName, vals[i].attrVal);
|
// }
|
// toBo.getBusinessObject().newAttrValList = valsCopy;
|
// } else {
|
// for (AttribItem item : items) {
|
// toBo.setAttributeValue(item.name, fromBo.getAttributeValue(item.name));
|
// }
|
// }
|
// }
|
|
private BtmItem getBtmDefine(String btmName) throws VCIError {
|
try {
|
//BtmItem boItem = ServerServiceProvider.getOMDService().getBTMService().getBtmItemByName(btmName);
|
BtmItem boItem = OMCacheProvider.getBizType(btmName);
|
return boItem;
|
} catch (Throwable e) {
|
e.printStackTrace();
|
throw this.getLocalString("P0010SOF-10001", e);
|
}
|
}
|
|
/**
|
* 设置BO对象的初始属性值
|
* @param bo
|
* @throws VCIError
|
*/
|
private void initTypeAttributeValue(BusinessObject bo) throws VCIError {
|
try {
|
//String[] names = ServerServiceProvider.getOMDService().getBTMService().getBtmApNameArray(bo.btmName);
|
//AttribItem[] items = ServerServiceProvider.getOMDService().getAttributeService().getAttribItemsByNames(names);
|
AttribItem[] items = OMCacheProvider.getAttribItemsByBizType(bo.btName);
|
for (AttribItem item : items) {
|
ObjectTool.setBOAttributeValue(bo, item.name, item.defValue);
|
}
|
} catch (Throwable e) {
|
e.printStackTrace();
|
throw this.getLocalString("P0010SOF-10007", e);
|
}
|
}
|
|
/**
|
* 获取初始的版本信息
|
* @param revLevel, 版本类型
|
* @param revRuleName,版本规则名称
|
* @return
|
* @throws Exception
|
*/
|
private RevisionDataInfo getRevisionSeqVal(int revLevel, String revRuleName, boolean revInput) throws Exception {
|
RevisionDataInfo obj = new RevisionDataInfo();
|
obj.revisionSeq = 1;
|
if (revInput) {
|
obj.revisionVal = "";
|
return obj;
|
}
|
if (revLevel == 0) {
|
obj.revisionVal = "-";
|
} else {
|
obj.revisionVal = getFirstRevision(revRuleName);
|
}
|
|
return obj;
|
}
|
|
/**
|
* 获取第一个版本值
|
* @param revRuleName
|
* @return
|
* @throws Exception
|
*/
|
private String getFirstRevision(String revRuleName) throws Exception {
|
//VersionRule vr = ServerServiceProvider.getOMDService().getVerRuleService().getVersionRule(revRuleName);
|
VersionRule vr = OMCacheProvider.getVersionRule(revRuleName);
|
if(vr!=null){
|
return vr.initialValue;
|
}
|
return "";
|
// try {
|
// VersionRule[] vrs = VersionRuleProvider.getInstance().getVersionRules();
|
// for (VersionRule vr : vrs) {
|
// if (vr.name.equals(revRuleName)) {
|
// return vr.initialValue;
|
// }
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// throw new VCIError();
|
// } catch (Throwable e) {
|
// e.printStackTrace();
|
// throw new VCIError();
|
// }
|
// return "";
|
}
|
|
/**
|
* 获取去初始版本
|
* @param verRuleName
|
* @return
|
*/
|
private VersionDataInfo getVersionValue(int verRuleName) {
|
VersionDataInfo obj = new VersionDataInfo();
|
obj.versionSeq = 1;
|
if (verRuleName == 0) {
|
obj.versionVal = "1";
|
} else if (verRuleName == 1){
|
obj.versionVal = "a";
|
} else if (verRuleName == 2) {
|
obj.versionVal = "0";
|
}
|
|
return obj;
|
}
|
|
|
/**
|
* 根据生命周期名称获取第一个生命周期节点
|
* @param lifeCycleName
|
* @return
|
* @throws Exception
|
*/
|
private String getLcFirstStatus(String lifeCycleName) throws Exception {
|
//LifeCycle lifeCycle = ServerServiceProvider.getOMDService().getLifeCycleService().getLifeCycle(lifeCycleName);
|
LifeCycle lifeCycle = OMCacheProvider.getLifeCycle(lifeCycleName);
|
if(lifeCycle!=null){
|
return lifeCycle.startState;
|
}
|
return "";
|
|
// try {
|
// LifeCyle[] lifeCycls = LifeCycleProvider.getInstance().getLifeCyles();
|
//
|
// for (LifeCyle lifeCycle : lifeCycls) {
|
// if (lifeCycle.name.equals(lifeCycleName)) {
|
// return lifeCycle.startState;
|
// }
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// throw new VCIError();
|
// } catch (Throwable e) {
|
// e.printStackTrace();
|
// throw new VCIError();
|
// }
|
// return "";
|
|
}
|
|
|
/**
|
* 升版业务对象,并复制From端或To端的所有link
|
* @param bo,业务对象
|
* @param los,关联链接对象
|
* @param isRev,true代表升版本,false代表升版次
|
* @param isSave,true代表保存,false代表不保存
|
* @param isFromLinkCopy, true代表传入的业务对象作为link的from端进行link的复制
|
* @param isToLinkCopy,true代表传入的业务对象作为link的to端进行link的复制
|
* @return
|
* @throws VCIError
|
*/
|
public BusinessObject revisionBusinessObject(BusinessObject bo,
|
LinkObject[] los, boolean isRev, boolean isSave, boolean isFromLinkCopy, boolean isToLinkCopy) throws VCIError {
|
BusinessObject newBo = null;
|
boolean isRevision = false;
|
boolean isNewVersion = false;
|
bo = BOFactoryServerDelegate.getInstance().getInfoBusinessObject(bo.oid, bo.btName);
|
if (isRev) {
|
newBo = getNewRevisionBO(bo);
|
isRevision = true;
|
} else {
|
newBo = getNewVersionBO(bo);
|
isNewVersion = true;
|
}
|
BOFactoryServerDelegate.getInstance().dealBusinessObjectNullValue(newBo);
|
|
LinkObject[] revFromLos = null;
|
if (isFromLinkCopy) {
|
revFromLos = getFromLinkData(bo, newBo, true, null);
|
}
|
LinkObject[] revToLos = null;
|
if (isToLinkCopy) {
|
revToLos = getToLinkData(bo, newBo, true, null);
|
}
|
if (isSave) {
|
BOFactoryServerDelegate bofDelegate = BOFactoryServerDelegate.getInstance();
|
if (revFromLos != null) {
|
bofDelegate.batchCreateBusinessObjectWithLink(new BusinessObject[0], revFromLos);
|
}
|
if (revToLos != null) {
|
bofDelegate.batchCreateBusinessObjectWithLink(new BusinessObject[0], revToLos);
|
}
|
return bofDelegate.createBusinessObject(newBo, isRevision, isNewVersion);
|
}
|
|
return newBo;
|
}
|
|
/**
|
* 升版业务对象,并复制From端或To端指定类型的link
|
* @param bo,业务对象
|
* @param linkNames,需要复制的link名称
|
* @param isRev,true代表升版本,false代表升版次
|
* @param isSave,true代表保存,false代表不保存
|
* @param isFromLinkCopy, true代表传入的业务对象作为link的from端进行link的复制
|
* @param isToLinkCopy,true代表传入的业务对象作为link的to端进行link的复制
|
* @return
|
* @throws VCIError
|
*/
|
public BusinessObject revisionBusinessObject(BusinessObject bo,
|
String[] linkNames, boolean isRev, boolean isSave, boolean isFromLinkCopy, boolean isToLinkCopy) throws VCIError {
|
BusinessObject newBo = null;
|
boolean isRevision = false;
|
boolean isNewVersion = false;
|
bo = BOFactoryServerDelegate.getInstance().getInfoBusinessObject(bo.oid, bo.btName);
|
if (isRev) {
|
newBo = getNewRevisionBO(bo);
|
isRevision = true;
|
} else {
|
newBo = getNewVersionBO(bo);
|
isNewVersion = true;
|
}
|
BOFactoryServerDelegate.getInstance().dealBusinessObjectNullValue(newBo);
|
|
LinkObject[] revFromLos = null;
|
if (isFromLinkCopy) {
|
revFromLos = getFromLinkData(bo, newBo, false, linkNames);
|
}
|
LinkObject[] revToLos = null;
|
if (isToLinkCopy) {
|
revToLos = getToLinkData(bo, newBo, false, linkNames);
|
}
|
if (isSave) {
|
BOFactoryServerDelegate bofDelegate = BOFactoryServerDelegate.getInstance();
|
if (revFromLos != null) {
|
bofDelegate.batchCreateBusinessObjectWithLink(new BusinessObject[0], revFromLos);
|
}
|
if (revToLos != null) {
|
bofDelegate.batchCreateBusinessObjectWithLink(new BusinessObject[0], revToLos);
|
}
|
return bofDelegate.createBusinessObject(newBo, isRevision, isNewVersion);
|
}
|
|
return newBo;
|
}
|
|
private BusinessObject getNewRevisionBO(BusinessObject bo) throws VCIError {
|
try {
|
BtmItem boItem = getBtmDefine(bo.btName);
|
if (boItem.revLevel == 0) {
|
throw this.getLocalString("P0010SOF-00015", null);
|
}
|
BusinessObject revBO = new BusinessObject();
|
revBO.oid = ObjectUtility.getNewObjectID36();
|
revBO.revisionid = ObjectUtility.getNewObjectID36();
|
revBO.nameoid = bo.nameoid;
|
revBO.btName = bo.btName;
|
revBO.isLastR = true;
|
revBO.isFirstR = false;
|
revBO.isFirstV = true;
|
revBO.isLastV = true;
|
|
revBO.creator = HibernateSessionFactory.getVciSessionInfo().userName;
|
revBO.createTime = System.currentTimeMillis();
|
revBO.modifier = HibernateSessionFactory.getVciSessionInfo().userName;
|
revBO.modifyTime = System.currentTimeMillis();
|
revBO.revisionRule = boItem.revRuleName;
|
revBO.versionRule = String.valueOf(boItem.verRuleName);
|
|
BOFactoryServerDelegate bosDelegate = BOFactoryServerDelegate.getInstance();
|
RevisionDataInfo revisionInfo = bosDelegate.getNextRevisionValueObject(bo.btName, bo.nameoid, boItem.revRuleName, false, "");
|
revBO.revisionSeq = revisionInfo.revisionSeq;
|
revBO.revisionValue = revisionInfo.revisionVal;
|
|
VersionDataInfo versionObj = getVersionValue(boItem.verRuleName);
|
revBO.versionSeq = versionObj.versionSeq;
|
revBO.versionValue = versionObj.versionVal;
|
revBO.lctId = bo.lctId;
|
revBO.lcStatus = getLcFirstStatus(bo.lctId);
|
revBO.id = bo.id;
|
revBO.name = bo.name;
|
revBO.description = bo.description;
|
revBO.owner = HibernateSessionFactory.getVciSessionInfo().userName;
|
//revBO.checkinBy = HibernateSessionFactory.getVciSessionInfo().userName;
|
revBO.fromVersion = bo.oid;
|
initRevisionTypeAttributeValue(bo, revBO);
|
|
return revBO;
|
} catch (VCIError e) {
|
throw e;
|
} catch (Throwable e) {
|
e.printStackTrace();
|
throw this.getLocalString("P0010SOF-10003", e);
|
}
|
}
|
|
// private String getTableName(String btmName) {
|
// return OmdTools.getBTTableName(btmName);
|
// }
|
|
/**
|
* 初始升版本BO对象属性值
|
* @param fromBo
|
* @param toBo
|
* @throws VCIError
|
*/
|
private void initRevisionTypeAttributeValue(BusinessObject fromBo, BusinessObject toBo) throws VCIError {
|
AttribItem[] items;
|
try {
|
//String[] names = ServerServiceProvider.getOMDService().getBTMService().getBtmApNameArray(toBo.btmName);
|
//items = ServerServiceProvider.getOMDService().getAttributeService().getAttribItemsByNames(names);
|
//items = BtmProvider.getInstance().getBtAbItems(toBo.btmName);
|
items = OMCacheProvider.getAttribItemsByBizType(toBo.btName);
|
for (AttribItem item : items) {
|
ObjectTool.setBOAttributeValue(toBo, item.name, ObjectTool.getBOAttributeValue(fromBo, item.name));
|
}
|
} catch (Throwable e) {
|
e.printStackTrace();
|
throw this.getLocalString("P0010SOF-10006", e);
|
}
|
|
}
|
|
private BusinessObject getNewVersionBO(BusinessObject bo) throws VCIError {
|
try {
|
BtmItem boItem = getBtmDefine(bo.btName);
|
if (boItem.revLevel != 2) {
|
throw this.getLocalString("P0010SOF-00016", null);
|
}
|
BusinessObject revBO = new BusinessObject();
|
revBO.oid = ObjectUtility.getNewObjectID36();
|
revBO.revisionid = bo.revisionid;
|
revBO.nameoid = bo.nameoid;
|
revBO.btName = bo.btName;
|
revBO.isLastR = bo.isLastR;
|
revBO.isFirstR = bo.isFirstR;
|
revBO.isFirstV = false;
|
revBO.isLastV = true;
|
|
revBO.creator = HibernateSessionFactory.getVciSessionInfo().userName;
|
revBO.createTime = System.currentTimeMillis();
|
revBO.modifier = HibernateSessionFactory.getVciSessionInfo().userName;
|
revBO.modifyTime = System.currentTimeMillis();
|
revBO.revisionRule = boItem.revRuleName;
|
revBO.versionRule = String.valueOf(boItem.verRuleName);
|
|
revBO.revisionSeq = bo.revisionSeq;
|
revBO.revisionValue = bo.revisionValue;
|
|
BOFactoryServerDelegate bofDelegate = BOFactoryServerDelegate
|
.getInstance();
|
VersionDataInfo versionObj = bofDelegate.getNextVersionValue(bo.btName, bo.revisionid, bo.nameoid, boItem.verRuleName);
|
revBO.versionSeq = versionObj.versionSeq;
|
revBO.versionValue = versionObj.versionVal;
|
revBO.lctId = bo.lctId;
|
revBO.lcStatus = bo.lcStatus;
|
revBO.id = bo.id;
|
revBO.name = bo.name;
|
revBO.description = bo.description;
|
revBO.owner = HibernateSessionFactory.getVciSessionInfo().userName;
|
//revBO.checkinBy = HibernateSessionFactory.getVciSessionInfo().userName;
|
revBO.fromVersion = bo.oid;
|
initRevisionTypeAttributeValue(bo, revBO);
|
|
return revBO;
|
} catch (VCIError e) {
|
throw e;
|
} catch (Throwable e) {
|
e.printStackTrace();
|
throw this.getLocalString("P0010SOF-10003", e);
|
}
|
}
|
|
/**
|
* 根据业务对象获取其作为from端对象的所有link数据,并构建新版本的关系数据
|
* @param bo
|
* @param revBo
|
* @param isAll, 是否复制所有的link
|
* @param linkNames,需要复制的link名称
|
* @return
|
* @throws VCIError
|
*/
|
private LinkObject[] getFromLinkData(BusinessObject bo, BusinessObject revBo, boolean isAll, String[] linkNames) throws VCIError {
|
String[] links = getLinkTypeByFromType(bo.btName);
|
|
if (links == null || links.length == 0) {
|
return null;
|
}
|
Map<String, String> linkMap = new HashMap<String, String>();
|
if (!isAll) {
|
if (linkNames == null || linkNames.length == 0) {
|
return null;
|
}
|
for (int i = 0; i < linkNames.length; i ++) {
|
linkMap.put(linkNames[i], "");
|
}
|
}
|
|
List<LinkObject> linkList = new ArrayList<LinkObject>();
|
LOFactoryServerDelegate linkDelegate = LOFactoryServerDelegate.getInstance();
|
for (int i = 0; i < links.length; i++) {
|
if (!isAll && !linkMap.containsKey(links[i])) {
|
continue;
|
}
|
LinkObject[] los = linkDelegate.getLinkObjectByBO(bo, links[i], true);
|
for (int j = 0; j < los.length; j++) {
|
LinkObject revLo = revFromBOLinkObject(los[j], revBo);
|
linkList.add(revLo);
|
}
|
}
|
|
return linkList.toArray(new LinkObject[0]);
|
}
|
|
/**
|
* 根据from端的类型名称获取链接类型的名称
|
* @param fromType
|
* @return
|
* @throws VCIError
|
*/
|
private String[] getLinkTypeByFromType(String fromType) throws VCIError {
|
try {
|
return iteratorGetSingleLinkTypeByFromType(fromType);
|
} catch (Throwable e) {
|
e.printStackTrace();
|
throw this.getLocalString("P0010SOF-10004", e);
|
}
|
}
|
|
private String[] iteratorGetSingleLinkTypeByFromType(String fromType) throws Exception, Throwable {
|
String[] links = getSingleLinkTypeByFromType(fromType);
|
if (links == null || links.length == 0) {
|
//BtmItem item = ServerServiceProvider.getOMDService().getBTMService().getBtmItemByName(fromType);
|
BtmItem item = OMCacheProvider.getBizType(fromType);
|
links = iteratorGetSingleLinkTypeByFromType(item.fName);
|
}
|
return links;
|
}
|
|
private String[] getSingleLinkTypeByFromType(String fromType) throws Exception, Throwable {
|
//LinkType[] linkTypes = ServerServiceProvider.getOMDService().getLinkTypeService().getLinkTypes();
|
LinkType[] linkTypes = OMCacheProvider.getLinkTypes();
|
List<String> linkList = new ArrayList<String>();
|
|
for (LinkType linkType : linkTypes) {
|
if (ArrayUtils.contains(linkType.btmItemsFrom, fromType))
|
linkList.add(linkType.name);
|
}
|
|
return linkList.toArray(new String[0]);
|
}
|
|
/**
|
* 根据From端的新版本构建新的链接对象
|
* @param lo
|
* @param bo
|
* @return
|
*/
|
private LinkObject revFromBOLinkObject(LinkObject lo, BusinessObject bo) {
|
LinkObject revLO = new LinkObject();
|
revLO.oid = ObjectUtility.getNewObjectID36();;
|
revLO.creator = HibernateSessionFactory.getVciSessionInfo().userName;
|
revLO.createTime = System.currentTimeMillis();
|
revLO.modifier = HibernateSessionFactory.getVciSessionInfo().userName;
|
revLO.modifyTime = System.currentTimeMillis();
|
revLO.fromOid = bo.oid;
|
revLO.fromRevOid = bo.revisionid;
|
revLO.fromNameOid = bo.nameoid;
|
revLO.fromBTName = bo.btName;
|
revLO.ts = System.currentTimeMillis();
|
|
String[] toBos = BOFactoryServerDelegate.getInstance().getLastReleasedBOId(lo.toNameOid);
|
if (toBos != null && toBos.length != 0) {
|
revLO.toOid = toBos[0];
|
revLO.toRevOid = toBos[1];
|
revLO.toNameOid = toBos[2];
|
revLO.toBTName = toBos[3];
|
} else {
|
revLO.toOid = lo.toOid;
|
revLO.toRevOid = lo.toRevOid;
|
revLO.toNameOid = lo.toNameOid;
|
revLO.toBTName = lo.toBTName;
|
}
|
|
revLO.ts = System.currentTimeMillis();
|
|
revLO.ltName = lo.ltName;
|
revLO.newAttrValList = lo.hisAttrValList;
|
revLO.hisAttrValList = new AttributeValue[0];
|
|
return revLO;
|
}
|
|
/**
|
* 根据业务对象获取其作为to端对象的所有link数据,并构建新版本的关系数据
|
* @param bo
|
* @param revBo
|
* @param isAll, 是否复制所有的link
|
* @param linkNames,需要复制的link名称
|
* @return
|
* @throws VCIError
|
*/
|
private LinkObject[] getToLinkData(BusinessObject bo, BusinessObject revBo, boolean isAll, String[] linkNames) throws VCIError {
|
String[] links = getLinkTypeByToType(bo.btName);
|
if (links == null || links.length == 0) {
|
return null;
|
}
|
|
Map<String, String> linkMap = new HashMap<String, String>();
|
if (!isAll) {
|
if (linkNames == null || linkNames.length == 0) {
|
return null;
|
}
|
for (int i = 0; i < linkNames.length; i ++) {
|
linkMap.put(linkNames[i], "");
|
}
|
}
|
List<LinkObject> linkList = new ArrayList<LinkObject>();
|
LOFactoryServerDelegate linkDelegate = LOFactoryServerDelegate.getInstance();
|
for (int i = 0; i < links.length; i++) {
|
if (!isAll && !linkMap.containsKey(links[i])) {
|
continue;
|
}
|
LinkObject[] los = linkDelegate.getLinkObjectByBO(bo, links[i], false);
|
for (int j = 0; j < los.length; j++) {
|
LinkObject revLo = revToBOLinkObject(los[j], revBo);
|
linkList.add(revLo);
|
}
|
}
|
|
return linkList.toArray(new LinkObject[0]);
|
}
|
|
/**
|
* 根据from端的类型名称获取链接类型的名称
|
* @param fromType
|
* @return
|
* @throws VCIError
|
*/
|
private String[] getLinkTypeByToType(String toType) throws VCIError {
|
try {
|
|
//LinkType[] linkTypes = ServerServiceProvider.getOMDService().getLinkTypeService().getLinkTypes();
|
LinkType[] linkTypes = OMCacheProvider.getLinkTypes();
|
List<String> linkList = new ArrayList<String>();
|
|
for (LinkType linkType : linkTypes) {
|
if (ArrayUtils.contains(linkType.btmItemsTo, toType))
|
linkList.add(linkType.name);
|
}
|
|
return linkList.toArray(new String[0]);
|
} catch (Throwable e) {
|
e.printStackTrace();
|
throw this.getLocalString("P0010SOF-10005", e);
|
}
|
}
|
|
/**
|
* 根据TO端的新版本构建新的链接对象
|
* @param lo
|
* @param bo
|
* @return
|
*/
|
private LinkObject revToBOLinkObject(LinkObject lo, BusinessObject bo) {
|
LinkObject revLO = new LinkObject();
|
revLO.oid = ObjectUtility.getNewObjectID36();;
|
revLO.creator = HibernateSessionFactory.getVciSessionInfo().userName;
|
revLO.createTime = System.currentTimeMillis();
|
revLO.modifier = HibernateSessionFactory.getVciSessionInfo().userName;
|
revLO.modifyTime = System.currentTimeMillis();
|
revLO.fromOid = lo.fromOid;
|
revLO.fromRevOid = lo.fromRevOid;
|
revLO.fromNameOid = lo.fromNameOid;
|
revLO.fromBTName = lo.fromBTName;
|
revLO.toOid = bo.oid;
|
revLO.toRevOid = bo.revisionid;
|
revLO.toNameOid = bo.nameoid;
|
revLO.toBTName = bo.btName;
|
revLO.ts = System.currentTimeMillis();
|
|
revLO.ltName = lo.ltName;
|
revLO.newAttrValList = lo.hisAttrValList;
|
revLO.hisAttrValList = new AttributeValue[0];
|
|
return revLO;
|
}
|
}
|