package com.vci.server.bof.delegate; import java.util.HashMap; import java.util.Map; import javax.xml.rpc.holders.LongHolder; import org.omg.CORBA.StringHolder; 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.TransitionVO; import com.vci.server.base.utility.OmdHelper; import com.vci.server.bof.server.create.BatchCUDBOLO; import com.vci.server.bof.server.create.BatchCreateBO; import com.vci.server.bof.server.create.BatchCreateBOLO; import com.vci.server.bof.server.create.BatchCreateBOLONoCheckLog; import com.vci.server.bof.server.create.BatchCreateBOLOTS; import com.vci.server.bof.server.create.BatchCreateDeleteBOLO; import com.vci.server.bof.server.create.CreateBO; import com.vci.server.bof.server.create.CreateBOLO; import com.vci.server.bof.server.create.CreateBOLOTS; import com.vci.server.bof.server.delete.BatchDeleteBO; import com.vci.server.bof.server.delete.DeleteBO; import com.vci.server.bof.server.transfer.BatchTransferBO; import com.vci.server.bof.server.transfer.TransferBO; import com.vci.server.bof.server.update.BatchChangeBOOwner; import com.vci.server.bof.server.update.BatchUpdateBO; import com.vci.server.bof.server.update.ChangeBOOwner; import com.vci.server.bof.server.update.UpdateBO; import com.vci.server.bof.server.update.check.BatchCheckInBO; import com.vci.server.bof.server.update.check.BatchCheckOutBO; import com.vci.server.bof.server.update.check.BatchUndoCheckOutBO; import com.vci.server.bof.server.update.check.CheckInBO; import com.vci.server.bof.server.update.check.CheckOutBO; import com.vci.server.bof.server.update.check.UndoCheckOutBO; import com.vci.server.bof.server.update.revision.BatchRevisionBO; import com.vci.server.bof.service.BOFactoryBatchServices; import com.vci.server.bof.service.BOFactoryServices; import com.vci.common.objects.UserEntity; import com.vci.corba.common.VCIError; import com.vci.corba.framework.data.UserInfo; public class BOFactoryServerDelegate extends FactoryBaseDelegate { private static BOFactoryServerDelegate instance = null; public static UserEntity userEntity = null; private BOFactoryServerDelegate() { userEntity = new UserEntity(); } public static synchronized BOFactoryServerDelegate getInstance() { if (instance == null) { instance = new BOFactoryServerDelegate(); } return instance; } /** * 存储单个BO对象 * @param bo * @param isRevision * @param isNewVersion * @return * @throws VCIError */ public BusinessObject createBusinessObject(BusinessObject bo, boolean isRevision, boolean isNewVersion) throws VCIError { return (BusinessObject) CreateBO.getInstance().doExecute(bo, isRevision, isNewVersion); } /** * 批量保持BO对象 * @param bos * @param isRevision * @param isNewVersion * @return * @throws VCIError */ public BusinessObject[] batchCreateBusinessObject(BusinessObject[] bos, boolean isRevision, boolean isNewVersion) throws VCIError { return (BusinessObject[]) BatchCreateBO.getInstance().doExecute(bos, isRevision, isNewVersion); } public boolean createBusinessObject(BusinessObject[] bos, LinkObject lo) throws VCIError { return (Boolean) CreateBOLO.getInstance().doExecute(bos, lo); } public boolean batchCreateBusinessObjectWithLink(BusinessObject[] bos, LinkObject[] los) throws VCIError { return (Boolean) BatchCreateBOLO.getInstance().doExecute(bos, los); } /** * 批量存储业务对象,不进行错误检查,不记录日志 * @param bos * @param los * @return * @throws VCIError */ public boolean batchCreateBOWithLinkNoCheckNoLog(BusinessObject[] bos, LinkObject[] los) throws VCIError { return (Boolean) BatchCreateBOLONoCheckLog.getInstance().doExecute(bos, los); } public boolean batchCreateDeleteBOLO(BusinessObject[] createBOs, LinkObject[] createLOs, BusinessObject[] deleteBOs, LinkObject[] deleteLOs) throws VCIError { return (Boolean) BatchCreateDeleteBOLO.getInstance(). doExecute(createBOs, createLOs, deleteBOs, deleteLOs); } public boolean batchCUDBOLO(BusinessObject[] createBOs, LinkObject[] createLOs, BusinessObject[] updateBOs, LinkObject[] updateLOs, BusinessObject[] deleteBOs, LinkObject[] deleteLOs) throws VCIError { return (Boolean) BatchCUDBOLO.getInstance(). doExecute(createBOs, createLOs, updateBOs, updateLOs, deleteBOs, deleteLOs); } public boolean CreateBusinessObjectWithLinkTS(BusinessObject[] bos, LinkObject lo, LongHolder ts) throws VCIError { return (Boolean) CreateBOLOTS.getInstance().doExecute(bos, lo, ts); } public boolean batchCreateBusinessObjectWithLinkTS(BusinessObject[] bos, LinkObject[] los, LongHolder ts) throws VCIError { return (Boolean) BatchCreateBOLOTS.getInstance().doExecute(bos, los, ts); } /** * 批量升版本 * @param oids * @param btmName * @return * @throws VCIError */ public boolean batchRevisonBusinessObject(String[] oids, String btmName) throws VCIError { return (Boolean) BatchRevisionBO.getInstance().doExecute(oids, btmName); } /** * 更改BO对象属性信息 * @param bo * @return * @throws VCIError */ public boolean updateBuinessObject(BusinessObject bo) throws VCIError { return (Boolean) UpdateBO.getInstance().doExecute(bo); } /** * 批量更改BO对象属性信息 * @param bos * @return * @throws VCIError */ public boolean batchUpdateBusinessObject(BusinessObject[] bos) throws VCIError { return (Boolean) BatchUpdateBO.getInstance().doExecute(bos); } /** * 按版本、版次、主对象等三种类型进行BO对象的删除 * @param bo * @param type * @return * @throws VCIError */ public boolean deleteBusinessObject(BusinessObject bo, int type) throws VCIError { return (Boolean) DeleteBO.getInstance().doExecute(bo, type); } public boolean batchDeleteBusinessObject(BusinessObject[] bos, int type) throws VCIError { return (Boolean) BatchDeleteBO.getInstance().doExecute(bos, type); } public BusinessObject getInfoBusinessObject(String oid, String btmName) throws VCIError { try { BOFactoryServices services = BOFactoryServices.getInstance(); BusinessObject bo = services.getInfoBusinessObject(oid, btmName); dealBusinessObjectNullValue(bo); return bo; } catch (Exception e) { e.printStackTrace(); throw this.getLocalString("P0010SOF-00004", e); } catch (Throwable t) { t.printStackTrace(); throw this.getLocalString("P0010SOF-00004", t); } } public BusinessObject[] getLastRevisionBusinessObject(String nameoid, String btmName) throws VCIError { try { BOFactoryServices services = BOFactoryServices.getInstance(); BusinessObject[] bos = services.getLastRevisionBusinessObject(nameoid, btmName); for (int i = 0; i < bos.length; i++) { dealBusinessObjectNullValue(bos[i]); } return bos; } catch (Exception e) { e.printStackTrace(); throw this.getLocalString("P0010SOF-00004", e); } catch (Throwable t) { t.printStackTrace(); throw this.getLocalString("P0010SOF-00004", t); } } public BusinessObject[] getBatchBusinessObject(String[] oids, String btmName) throws VCIError { try { BOFactoryBatchServices services = BOFactoryBatchServices.getInstance(); long stime = System.currentTimeMillis(); BusinessObject[] bos = services.getBatchBusinessObject(oids, btmName); long etime = System.currentTimeMillis(); System.out.printf("===============getBatchBusinessObject 执行时长:%d 毫秒.==================", (etime - stime)); stime = System.currentTimeMillis(); bos = services.getBatchBusinessObjectByTempOIDs(oids, btmName); etime = System.currentTimeMillis(); System.out.printf("===============getBatchBusinessObjectByTempOIDs 执行时长:%d 毫秒.==================", (etime - stime)); for (int i = 0; i < bos.length; i++) { dealBusinessObjectNullValue(bos[i]); } return bos; } catch (Exception e) { e.printStackTrace(); throw this.getLocalString("P0010SOF-00004", e); } catch (Throwable t) { t.printStackTrace(); throw this.getLocalString("P0010SOF-00004", t); } } public BusinessObject[] getBatchBusinessObjects(String btmName, int page, int pageSize) throws VCIError { try { BOFactoryBatchServices services = BOFactoryBatchServices.getInstance(); BusinessObject[] bos = services.getBatchBusinessObjects(btmName, page, pageSize); for (int i = 0; i < bos.length; i++) { dealBusinessObjectNullValue(bos[i]); } return bos; } catch (Exception e) { e.printStackTrace(); throw this.getLocalString("P0010SOF-00004", e); } catch (Throwable t) { t.printStackTrace(); throw this.getLocalString("P0010SOF-00004", t); } } /** * 检入对象 * @param bo * @return * @throws VCIError */ public boolean checkInBusinessObject(BusinessObject bo) throws VCIError { return (Boolean) CheckInBO.getInstance().doExecute(bo); } /** * 批量检入对象 * @param bos * @return * @throws VCIError */ public boolean batchCheckInBusinessObject(BusinessObject[] bos) throws VCIError { return (Boolean) BatchCheckInBO.getInstance().doExecute(bos); } /** * 检出对象 * @param bo * @return * @throws VCIError */ public boolean checkoutBusinessObject(BusinessObject bo) throws VCIError { return (Boolean) CheckOutBO.getInstance().doExecute(bo); } public boolean batchCheckoutBusinessObject(BusinessObject[] bos) throws VCIError { return (Boolean) BatchCheckOutBO.getInstance().doExecute(bos); } /** * 撤销检出对象 * @param bo * @return * @throws VCIError */ public boolean undoCheckoutBusinessObject(BusinessObject bo) throws VCIError { return (Boolean) UndoCheckOutBO.getInstance().doExecute(bo); } /** * 批量撤销检出对象 * @param bos * @return * @throws VCIError */ public boolean batchUnCheckOutBusinessObject(BusinessObject[] bos) throws VCIError { return (Boolean) BatchUndoCheckOutBO.getInstance().doExecute(bos); } /** * 跃迁对象,执行跃迁事件,并记录跃迁日志 * @param bo * @param vo * @return * @throws VCIError */ public boolean transferBusinessObject(BusinessObject bo, TransitionVO vo, String releaseStatus) throws VCIError { return (Boolean) TransferBO.getInstance().doExecute(bo, vo, releaseStatus); } /** * 批量跃迁对象 * @param bos * @param vos * @param releaseStatus * @return * @throws VCIError */ public boolean batchTransferBusinessObject(BusinessObject[] bos, TransitionVO[] vos, String[] releaseStatus) throws VCIError { return (Boolean) BatchTransferBO.getInstance().doExecute(bos, vos, releaseStatus); } /** * 变更对象所有者 * @param bo * @param userInfo * @return * @throws VCIError */ public boolean changeBusinessObjectOwner(BusinessObject bo, UserInfo userInfo) throws VCIError { return (Boolean) ChangeBOOwner.getInstance().doExecute(bo, userInfo); } /** * 批量变更对象所有者 * @param bos * @param userList * @return * @throws VCIError */ public boolean batchChangeBusinessObjectOwner(BusinessObject[] bos, UserInfo[] userList) throws VCIError { return (Boolean) BatchChangeBOOwner.getInstance().doExecute(bos, userList); } public RevisionDataInfo getNextRevisionValueObject(String btName, String nameOid, String revisionRule, boolean revInput, String revisionVal) throws VCIError { RevisionDataInfo info = null; try { BOFactoryServices services = BOFactoryServices.getInstance(); info = services.getNextRevisionValueObject(btName, nameOid, revisionRule, revInput, revisionVal); } catch (VCIError e) { throw this.getLocalString(e.code, e); } catch (Exception e) { e.printStackTrace(); throw this.getLocalString("P0010SOF-00010", e); } catch (Throwable t) { t.printStackTrace(); throw this.getLocalString("P0010SOF-00010", t); } finally { if (info == null) { info = new RevisionDataInfo(); info.revisionSeq = 0; info.revisionVal = ""; } else { if (info.revisionVal == null) { info.revisionVal = ""; } } } return info; } /** * 通过传入的参数和规则计算出下一个版本值 * @param revisonValue * @param revisionSeq * @param revisionRule * @return * @throws VCIError */ public RevisionDataInfo getNextRevisionValueObject(String revisonValue, short revisionSeq, String revisionRule) throws VCIError { RevisionDataInfo info = null; try { BOFactoryServices services = BOFactoryServices.getInstance(); info = services.getNextRevisionValue(revisonValue, revisionSeq, revisionRule); } catch (VCIError e) { throw this.getLocalString(e.code, e); } catch (Exception e) { e.printStackTrace(); throw this.getLocalString("P0010SOF-00010", e); } catch (Throwable t) { t.printStackTrace(); throw this.getLocalString("P0010SOF-00010", t); } finally { if (info == null) { info = new RevisionDataInfo(); info.revisionSeq = 0; info.revisionVal = ""; } else { if (info.revisionVal == null) { info.revisionVal = ""; } } } return info; } public VersionDataInfo getNextVersionValue(String btName, String revisionOid, String nameOid, int versionType) throws VCIError { String tableName = OmdHelper.getBTTableName(btName); VersionDataInfo info = null; try { BOFactoryServices services = BOFactoryServices.getInstance(); info = services.getNextVersionValue(tableName, revisionOid, nameOid, versionType); } catch (Exception e) { e.printStackTrace(); throw this.getLocalString("P0010SOF-00011", e); } catch (Throwable t) { t.printStackTrace(); throw this.getLocalString("P0010SOF-00011", t); } finally { if (info == null) { info = new VersionDataInfo(); info.versionSeq = 0; info.versionVal = ""; } else { if (info.versionVal == null) { info.versionVal = ""; } } } return info; } public String[] getClssficationValue(String sql, AttributeValue[] attrVals) throws VCIError { String[] values = null; try { BOFactoryServices services = BOFactoryServices.getInstance(); Map map = new HashMap(); for (int i = 0; i < attrVals.length; i++) { map.put(attrVals[i].attrName, attrVals[i].attrVal); } values = services.getClssficationValue(sql, map); } catch (Exception e) { e.printStackTrace(); throw this.getLocalString("P0010SOF-00021", e); } catch (Throwable t) { t.printStackTrace(); throw this.getLocalString("P0010SOF-00021", t); } finally { if (values == null) { values = new String[0]; } else { for (int i = 0; i < values.length; i++) { if (values[i] == null) { values[i] = ""; } } } } return values; } public String[][] getSqlQueryResult(String sql, AttributeValue[] attrVals) throws VCIError { String[][] values = null; try { BOFactoryServices services = BOFactoryServices.getInstance(); Map map = new HashMap(); for (int i = 0; i < attrVals.length; i++) { map.put(attrVals[i].attrName, attrVals[i].attrVal); } values = services.getSqlQueryResult(sql, map); } catch (Exception e) { e.printStackTrace(); throw this.getLocalString("P0010SOF-00021", e); } catch (Throwable t) { t.printStackTrace(); throw this.getLocalString("P0010SOF-00021", t); } finally { if (values == null) { values = new String[0][0]; } else { for (int i = 0; i < values.length; i++) { if (values[i] == null) { values[i] = new String[0]; } else { for (int j = 0; j < values[i].length; j++) { if (values[i][j] == null) { values[i][j] = ""; } } } } } } return values; } public String[][] getCustomSqlValue(String[] sqls) throws VCIError { String[][] values = null; try { BOFactoryServices services = BOFactoryServices.getInstance(); values = services.getCustomSqlValue(sqls); } catch (Exception e) { e.printStackTrace(); throw this.getLocalString("P0010SOF-00021", e); } catch (Throwable t) { t.printStackTrace(); throw this.getLocalString("P0010SOF-00021", t); } finally { if (values == null) { values = new String[0][0]; } else { for (int i = 0; i < values.length; i++) { if (values[i] == null) { values[i] = new String[0]; continue; } for (int j = 0; j < values[i].length; j++) { if (values[i][j] == null) { values[i][j] = ""; } } } } } return values; } // /** // * 日志记录 // * @param user:操作人 // * @param module:操作模块 // * @param ip:操作人所在IP地址 // * @param operation:操作类型 // * @param type:对象类型 // * @param objName:对象名称 // * @param oid:对象OID // * @throws VCIError // */ // private void recordLog(String user, String module, String ip, String operation, String type, String objName, String oid) throws VCIError { // userEntity.setUserName(user); // userEntity.setModule(module); // userEntity.setIp(ip); // // //记录日志 // LogRecordUtil.writeLog(userEntity, operation, type + ":" + objName, LogType.GeneralOperation, oid); // } // // /** // * 批量存储log // * @param bos // * @param ip // * @param operation // * @throws HibernateException // * @throws SQLException // */ // private void batchRecordLog(BusinessObject[] bos, String ip, String operation) throws HibernateException, SQLException { // if (bos == null || bos.length < 1) { // return; // } // boolean rs = true; // if (rs) { // return; // } // userEntity.setUserName(bos[0].creator); // userEntity.setIp(ip); // // String role = LogRecordUtil.getRoleName(userEntity); // if (role == null) { // role = ""; // } // ArrayList logList = new ArrayList(); // for (int i = 0; i < bos.length; i++) { // logList.add(LogRecordUtil.getLogSql(userEntity, operation, bos[i].btmName + ":" + bos[i].name, LogType.GeneralOperation, bos[i].oid, role, bos[i].btmName)); // if ((i + 1) % 200 == 0) { // LogRecordUtil.batchSaveLog(logList.toArray(new String[logList.size()])); // logList.clear(); // } // } // if (bos.length % 200 != 0) { // LogRecordUtil.batchSaveLog(logList.toArray(new String[logList.size()])); // logList.clear(); // } // } public String[] getLastReleasedBOId(String nameoid) { try { BOFactoryServices services = BOFactoryServices.getInstance(); return services.getLastReleasedBOId(nameoid); } catch (Exception e) { e.printStackTrace(); } return null; } public void dealBusinessObjectNullValue(BusinessObject bo) { bo.oid = bo.oid == null ? "" : bo.oid; bo.revisionid = bo.revisionid == null ? "" : bo.revisionid; bo.nameoid = bo.nameoid == null ? "" : bo.nameoid; bo.btName = bo.btName == null ? "" : bo.btName; bo.creator = bo.creator == null ? "" : bo.creator; //bo.createTime = bo.createTime; bo.modifier = bo.modifier == null ? "" : bo.modifier; //bo.modifyTime = bo.modifyTime; bo.revisionRule = bo.revisionRule == null ? "" : bo.revisionRule; bo.versionRule = bo.versionRule == null ? "" : bo.versionRule; bo.revisionValue = bo.revisionValue == null ? "" : bo.revisionValue; bo.versionValue = bo.versionValue == null ? "" : bo.versionValue; bo.lctId = bo.lctId == null ? "" : bo.lctId; bo.lcStatus = bo.lcStatus == null ? "" : bo.lcStatus; //bo.ts = bo.ts; bo.id = bo.id == null ? "" : bo.id; bo.name = bo.name == null ? "" : bo.name; bo.description = bo.description == null ? "" : bo.description; bo.owner = bo.owner == null ? "" : bo.owner; // bo.checkinBy = bo.checkinBy == null ? "" : bo.checkinBy; // bo.checkinTime = bo.checkinTime == null ? "" : bo.checkinTime; // bo.checkoutBy = bo.checkoutBy == null ? "" : bo.checkoutBy; // bo.checkoutTime = bo.checkoutTime == null ? "" : bo.checkoutTime; bo.fromVersion = bo.fromVersion == null ? "" : bo.fromVersion; if (bo.newAttrValList == null) { bo.newAttrValList = new AttributeValue[0]; } for (int i = 0; i < bo.newAttrValList.length; i++) { if (bo.newAttrValList[i].attrVal == null) { bo.newAttrValList[i].attrVal = ""; } } if (bo.hisAttrValList == null) { bo.hisAttrValList = new AttributeValue[0]; } for (int i = 0; i < bo.hisAttrValList.length; i++) { if (bo.hisAttrValList[i].attrVal == null) { bo.hisAttrValList[i].attrVal = ""; } } } }