package com.vci.client.uif.actions.client; import java.awt.Component; import java.awt.Window; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.text.MessageFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import javax.swing.JOptionPane; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Workbook; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import com.vci.client.bof.ClientBusinessObject; import com.vci.client.bof.ClientBusinessObjectOperation; import com.vci.client.bof.ClientLinkObject; import com.vci.client.bof.ClientLinkObjectOperation; import com.vci.client.common.ConfigUtils; import com.vci.client.common.FreeMarkerCommon; import com.vci.client.common.FreemarkerParamObject; import com.vci.client.common.PositionMessager; import com.vci.client.common.oq.OQTool; import com.vci.client.common.providers.ServiceProvider; import com.vci.client.omd.attribpool.ui.APClient; import com.vci.client.omd.btm.ui.BtmClient; import com.vci.client.omd.lifecycle.LifeCycleStart; import com.vci.client.oq.QTClient; import com.vci.client.oq.QTDClient; import com.vci.client.portal.utility.PRM; import com.vci.client.portal.utility.PRMItem; import com.vci.client.ui.exception.VCIException; import com.vci.client.ui.locale.LocaleDisplay; import com.vci.client.ui.swing.VCIOptionPane; import com.vci.client.ui.swing.VCISwingUtil; import com.vci.client.ui.swing.components.VCIJOptionPane; import com.vci.client.uif.engine.client.IRegionPanel; import com.vci.client.uif.engine.client.combobox.IComboBoxDataProvider; import com.vci.client.uif.engine.common.IDataNode; import com.vci.client.uif.engine.common.UIFUtilsCommon; import com.vci.client.utils.excel.ExcelCellStyleSettingCallback; import com.vci.client.utils.excel.ExcelDocumentUtils; import com.vci.client.utils.excel.ExcelFileOperation; import com.vci.client.utils.excel.SheetDataSet; import com.vci.client.utils.excel.WorkboolStyleSetting; import com.vci.common.qt.object.Condition; import com.vci.common.qt.object.ConditionItem; import com.vci.common.qt.object.LeafInfo; import com.vci.common.qt.object.LeafValue; import com.vci.common.qt.object.Operator; import com.vci.common.qt.object.QueryTemplate; import com.vci.common.qt.object.Version; import com.vci.common.utility.ObjectUtility; import com.vci.corba.common.VCIError; import com.vci.corba.omd.atm.AttribItem; import com.vci.corba.omd.btm.BtmAndApName; 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.etm.EnumChild; import com.vci.corba.omd.etm.EnumItem; import com.vci.corba.omd.lcm.LifeCycle; import com.vci.corba.omd.lcm.TransitionVO; import com.vci.corba.omd.qtm.QTInfo; import com.vci.corba.query.ObjectQueryServicePrx; import com.vci.corba.query.data.BOAndLO; import com.vci.corba.omd.stm.StatePool; import com.vci.mw.ClientContextVariable; import com.vci.omd.constants.BusinessConstants; import com.vci.omd.constants.LinkConstants; import com.vci.omd.dataType.VTDataType; import com.vci.omd.utils.ObjectTool; /** * 业务对象及link对象操作类 * XXX 除了必要的异常处理,其他异常全部都抛出, * * @author VCI-STGK006 * */ public class UIFUtils extends UIFUtilsCommon{ /** * UIF 国际化文件资源文件名称 */ public final static String UIFMODEL_RESOURCE_FILE_NAME = "UIFModelAction"; /** * 业务对象操作方法 */ private ClientBusinessObjectOperation boOperation = new ClientBusinessObjectOperation(); /** * link对象操作方法 */ private ClientLinkObjectOperation loOperation = new ClientLinkObjectOperation(); /** * 业务对象操作类 */ public UIFUtils(){} /** * 获得cbo对象指定名称的属性值 * @param cbo 业务对象 * @param key 属性名称 * @return 属性值 */ public String getBusinessObejctAttrValue(ClientBusinessObject cbo, String key){ if(key == null){ return ""; } if(key.toUpperCase().startsWith("T_OID")){ if(key.indexOf(".") != -1){ key = key.substring(key.lastIndexOf(".") + 1); } else { key = key.substring(5); } } return cbo.getAttributeValue(key); } /** * 获得link对象或业务对象的属性值 * 此时如果是业务对象的属性值需要时t_oid开头的对象 * @param clo link对象 * @param cbo 业务对象 * @param key key * @return 属性值 */ public String getLinkObejctAttrValue(ClientLinkObject clo, ClientBusinessObject cbo, String key){ if(key == null){ return ""; } String value = ""; //判断是业务对象属性还是link属性 if(key.toUpperCase().startsWith("T_OID")){ if(key.indexOf(".") != -1){ key = key.substring(key.lastIndexOf(".") + 1); } else { key = key.substring(5); } //如果是系统属性 if (BusinessConstants.BO_CONSTANTS.containsKey(key.toUpperCase())) { if (key.equalsIgnoreCase(BusinessConstants.SELECT_NAME)){ value = cbo.getBusinessObject().name; } else if (key.equalsIgnoreCase(BusinessConstants.SELECT_ID)){ value = cbo.getBusinessObject().id; } else if (key.equalsIgnoreCase(BusinessConstants.SELECT_DESCRIPTION)){ value = cbo.getBusinessObject().description; } } else { AttributeValue[] attrVals = cbo.getBusinessObject().hisAttrValList; if(attrVals != null){ for(AttributeValue attr : attrVals){ if(key.toUpperCase().equals(attr.attrName)){ value = attr.attrVal; } } } } } else { //如果是系统属性 if (LinkConstants.LO_CONSTANTS.containsKey(key.toUpperCase())) { } else { AttributeValue[] attrVals = clo.getLinkObject().hisAttrValList; if(attrVals != null){ for(AttributeValue attr : attrVals){ if(key.toUpperCase().equals(attr.attrName)){ value = attr.attrVal; } } } } } return value; } /** * 创建一个空的业务对象 * @param parent 父窗口 * @param btmName 业务类型 * @return 创建失败时返回null */ public ClientBusinessObject createEmptyClientBusinessObject(Component parent, String btmName) { try { return boOperation.createBusinessObject(btmName); } catch (Exception e) { showErrorMessage(parent, e); } return null; } /** * 创建一个空的link对象 * @param parent 父窗口 * @param loName link类型 * @return */ public ClientLinkObject createEmptyClientLinkObject(Component parent, String loName) { try { return loOperation.createLinkObject(loName); } catch (Exception e) { showErrorMessage(parent, e); } return null; } /** * 组装业务对象 主要设置业务对象属性并进行属性的校验 * @param parent 父窗体 * @param cbo 业务对象 * @param attrMap 业务对象属性。map中需要包含业务对象所有属性 * @return 失败返回null */ public ClientBusinessObject assembleClientBusinessObject(Component parent, ClientBusinessObject cbo, Map attrMap) { // 设置验证业务对象属性值 if (attrMap != null && !attrMap.isEmpty()) { Set> set = attrMap.entrySet(); for (Entry entry : set) { String key = entry.getKey(); String value = entry.getValue(); try { //如果是系统属性 if (BusinessConstants.BO_CONSTANTS.containsKey(key.toUpperCase())) { cbo.setAttributeValue(key, value, true); } else { cbo.setAttributeValue(key, value); } } catch (Exception e) { showErrorMessage(parent, e); return null; } } } return cbo; } /** * 根据业务对象的OID和BTMNAME重新加载对象 * @param cbo 业务对象 * @throws VCIError */ public ClientBusinessObject reloadClientBusinessObject(ClientBusinessObject cbo)throws VCIError { return boOperation.readBusinessObjectById(cbo.getOid(), cbo.getBtmName()); } /** * 根据业务对象的OID和BTMNAME重新加载对象 * @param parent * @param oid * @param btmName * @return */ public ClientBusinessObject reloadClientBusinessObject(Component parent,String oid, String btmName){ ClientBusinessObject cbo = new ClientBusinessObject(); try{ cbo = boOperation.readBusinessObjectById(oid, btmName); } catch (Exception e){ e.printStackTrace(); } return cbo; } /** * 重新下载link对象 * @param oid link oid * @param loName link类型 * @return */ public ClientLinkObject reloadLinkObjectById(String oid, String loName){ ClientLinkObject clo = null; try { clo = loOperation.readLinkObjectById(oid, loName); } catch (Exception e){ e.printStackTrace(); return null; } return clo; } /** * 加载link对象 * @param cbo from端业务对象 * @param linkType link类型 * @return link对象集合 * @throws Exception */ public ClientLinkObject[] reloadClientLinkObject(ClientBusinessObject cbo, String linkType) throws Exception { return loOperation.readLinkObjectByFromBO(cbo, linkType); } /** * 升级业务对象版次 * @param parent 父窗体 * @param cbo 业务对象 * @return true 操作成功 */ public boolean upBusinessObjectVersion(Component parent, ClientBusinessObject cbo) throws Exception{ // 获得升级版次的业务对象 ClientBusinessObject to = boOperation.createBusinessObjectVersion(cbo); boOperation.saveVersionBuinessObject(to); return true; } /** * 跃迁 * @param parent 父窗体 * @param cbo 业务对象 * @param vo * @return true跃迁成功 */ public boolean transferBusinessObject(Component parent, ClientBusinessObject cbo,TransitionVO vo) { try { if (!boOperation.transferBusinessObject(cbo, vo)) { showMessage(parent, "uifmodel.plm.uif.actions.transferBOError", cbo.getName()); return false; } showMessage(parent, "uifmodel.plm.uif.actions.transfersuccessmsg", cbo.getName()); } catch (Exception e) { showErrorMessage(parent, e); return false; } return true; } /** * 修改业务对象 * @param parent 父窗体 * @param cbo 将要操作的业务对象 * @param attrMap 业务对象属性 * @return true 操作成功 */ public boolean updateBusinessObject(Component parent, ClientBusinessObject cbo, Map attrMap) { // 验证业务对象属性值 // 直接使用setAttributeValue方法中的校验 if (attrMap != null && !attrMap.isEmpty()) { // 设置业务对象属性 Set> set = attrMap.entrySet(); for (Entry entry : set) { String key = entry.getKey(); if(key.toUpperCase().startsWith("T_OID")){ if(key != null && key.indexOf(".") != -1){ key = key.substring(key.lastIndexOf(".") + 1); } else { key = key.substring(5); } } String value = entry.getValue(); try { //更新时直接将属性值设置到newAttrValList中即可 cbo.setAttributeValue(key, value); } catch (Exception e) { showErrorMessage(parent, e); return false; } } } // 更新业务对象 try { boOperation.updateBuinessObject(cbo); showMessage(parent, "uifmodel.plm.uif.actions.editsuccessmsg", cbo.getName()); } catch (Exception e1) { showErrorMessage(parent, e1); return false; } return true; } /** * 删除版本,版次,业务对象 * @param parent 父窗口 * @param cbo 将要操作的业务对象 * @param type 删除类型 1:版次对象;2:版本对象;3:主对象 * @return true 操作成功 */ public boolean deleteBusinessObject(Component parent, ClientBusinessObject cbo, int type) { try { // 删除业务对象 boolean issuccess = false; if(type == 1) { issuccess = boOperation.deleteBuinessObject(cbo); } else if(type == 2) { issuccess = boOperation.deleteBuinessObjectRevision(cbo); } else if(type == 3) { issuccess = boOperation.deleteBuinessObjectMaster(cbo); } else { showMessage(parent, "uifmodel.plm.uif.actions.delBOTypeError"); return false; } //删除失败 if(!issuccess){ showMessage(parent, "uifmodel.plm.uif.actions.deleteBOError"); return false; } showMessage(parent, "uifmodel.plm.uif.actions.deletesuccessmsg", cbo.getName()); } catch (Exception e) { showErrorMessage(parent, e); return false; } return true; } /** * 批量删除版本,版次,业务对象 * @param parent 父窗口 * @param cbos 将要操作的业务对象 * @param type 删除类型 1:版次对象;2:版本对象;3:主对象 * @return true 操作成功 */ public boolean batchDeleteBuinessObject(Component parent, ClientBusinessObject[] cbos, int type){ try { // 删除业务对象 boolean issuccess = false; if(type == 1) { issuccess = boOperation.batchDeleteBuinessObject(cbos); } else if(type == 2) { issuccess = boOperation.batchDeleteBuinessObjectRevision(cbos); } else if(type == 3) { issuccess = boOperation.batchDeleteBuinessObjectMaster(cbos); } else { showMessage(parent, "uifmodel.plm.uif.actions.delBOTypeError"); return false; } //删除失败 if(!issuccess){ showMessage(parent, "uifmodel.plm.uif.actions.deleteBOError"); return false; } showMessage(parent, "uifmodel.plm.uif.actions.deletesuccessmsg", ""); } catch (Exception e) { showErrorMessage(parent, e); return false; } return true; } /** * 启用业务对象 * @param parent,父窗口 * @param cbos,需要启用的数据 * @param vos,跃迁的起始与目标状态 * @return */ public boolean enableBusinessObject(Component parent, ClientBusinessObject[] cbos, TransitionVO[] vos) { try { // 删除业务对象 String[] releaseStatus = new String[vos.length]; for (int i = 0; i < releaseStatus.length; i++) { releaseStatus[i] = ""; } boolean issuccess = boOperation.batchTransferBusinessObject(cbos, vos, releaseStatus); //删除失败 if(!issuccess){ showMessage(parent, "uifmodel.plm.uif.actions.enableBOError"); return false; } showMessage(parent, "uifmodel.plm.uif.actions.enablesuccessmsg", ""); } catch (Exception e) { showErrorMessage(parent, e); return false; } return true; } /** * 停用业务对象 * @param parent,父窗口 * @param cbos,需要停用的数据 * @param vos,跃迁的起始与目标状态 * @return */ public boolean disableBusinessObject(Component parent, ClientBusinessObject[] cbos, TransitionVO[] vos) { try { // 删除业务对象 String[] releaseStatus = new String[vos.length]; for (int i = 0; i < releaseStatus.length; i++) { releaseStatus[i] = ""; } boolean issuccess = boOperation.batchTransferBusinessObject(cbos, vos, releaseStatus); //删除失败 if(!issuccess){ showMessage(parent, "uifmodel.plm.uif.actions.disableBOError"); return false; } showMessage(parent, "uifmodel.plm.uif.actions.disablesuccessmsg", ""); } catch (Exception e) { showErrorMessage(parent, e); return false; } return true; } /** * 保存link对象 * @param parent * @param clos * @return */ public boolean saveLinkObject(Component parent, ClientLinkObject[] clos) { if(clos == null || clos.length < 1){ return true; } try { return boOperation.batchSaveCreateBuinessObject(new ClientBusinessObject[0], clos); } catch (Exception e) { showErrorMessage(parent, e); return false; } } /** * 修改link对象 对于更改to端对象时,不保存to端业务对象 * @param parent 父窗体 * @param lo link对象 * @param to to端业务对象,当不需要修改to端业务对象时为null * @param attrMap link对象属性 * @return true 操作成功 */ public boolean updateLinkObject(Component parent, ClientLinkObject lo, ClientBusinessObject to, Map attrMap) { // 设置link对象属性 if (attrMap != null && !attrMap.isEmpty()) { Set> set = attrMap.entrySet(); for (Entry entry : set) { String key = entry.getKey(); String value = entry.getValue(); try { lo.setAttributeValue(key, value); } catch (Exception e) { showErrorMessage(parent, e); return false; } } } // 如果需要修改to端对象to端业务对象 if (to != null) { lo.setToBO(to); } // 更新link对象 try { return loOperation.updateLinkObject(lo); } catch (Exception e) { showErrorMessage(parent, e); return false; } } /** * 删除link对象 * @param parent 父窗体 * @param clos link对象 * @return true 操作成功 */ public boolean deleteLinkObject(Component parent, ClientLinkObject[] clos){ return deleteLinkObject(parent, clos, true); } /** * 删除link对象 * @param parent 父窗体 * @param clos link对象 * @param showMessage 是否显示异常信息 true显示 * @return true 操作成功 */ public boolean deleteLinkObject(Component parent, ClientLinkObject[] clos, boolean showMessage){ if(clos == null || clos.length < 1){ if(showMessage){ showMessage(parent, "uifmodel.plm.uif.actions.removenotexistmsg"); } return false; } if(clos.length == 1){ //删除单个link对象 try { if(!loOperation.deleteLinkObject(clos[0])){ if(showMessage){ showMessage(parent, "uifmodel.plm.uif.actions.deleteerror", clos[0].getLoName()); } return false; } } catch (Exception e) { if(showMessage){ showErrorMessage(parent, e); } return false; } } else { //批量删除 try { if(!loOperation.batchdDeleteLinkObject(clos)){ if(showMessage){ showMessage(parent, "uifmodel.plm.uif.actions.deletelinkerror"); } return false; } } catch (Exception e) { if(showMessage){ showErrorMessage(parent, e); } return false; } } return true; } /** * 从from端移除link对象 删除所有以此业务对象为from的link * @param parent 消息窗口的父窗口 * @param cbos 业务对象数组 * @param linkNameMap 每一个业务对象对应的link类型 key:cbos.OID,value:loName * @return true 操作成功 */ public boolean deleteLinkObjectByFromBO(Component parent,ClientBusinessObject[] cbos, Map linkNameMap) { if (cbos != null && linkNameMap != null) { List linkList = new ArrayList(); // 得到所有业务员对象的link对象 for (ClientBusinessObject cbo : cbos) { // 检查是否有业务对象对应的link名称 String loName = linkNameMap.get(cbo.getBusinessObject().oid); if (loName == null || loName.equals("")) { //没有设置对应的link名称不能删除相关link对象 //showMessage(parent, code, args); } else { try { // 查询所有以cbo为from端的link对象并添加到linkList ClientLinkObject[] los = loOperation .readLinkObjectByFromBO(cbo, loName); if (los != null) { for (ClientLinkObject clo : los) { linkList.add(clo); } } } catch (Exception e) { //TODO 对于在查找相关的link对象时出错的信息暂时没有处理 e.printStackTrace(); //showErrorMessage(parent, e); //return false; } } } // 批量删除所有LinkObject if (!linkList.isEmpty()) { try { loOperation .batchdDeleteLinkObject((ClientLinkObject[]) linkList .toArray()); } catch (Exception e) { showErrorMessage(parent, e); return false; } } } return true; } /** * 粘贴业务对象 * @param parent 父窗体 * @param from from端业务对象 * @param loName from端link类型 * @param tos 要粘贴的业务对象 * @return true 操作成功 */ public boolean pasteBusinessObjects(Component parent, ClientBusinessObject from, String loName, ClientBusinessObject[] tos) { if (tos == null || tos.length < 1) { // 剪切板中没有业务对象 showMessage(parent, "uifmodel.plm.uif.actions.ClipboardEmpty"); return false; } if (loName == null || loName.equals("")) { showMessage(parent, "uifmodel.plm.uif.actions.fromLinkNull"); } //获得from段所有的头端对象 Map toMap = new HashMap(); ClientLinkObject[] clos; try { clos = loOperation.readLinkObjectByFromBO(from, loName); if(clos != null && clos.length > 0){ for(int i = 0; i cloList = new ArrayList(); for (int i = 0; i < tos.length; i++) { if(toMap.containsKey(tos[i].getOid())){ int confirm = VCIOptionPane.showConfirmDialog( parent, "“" + tos[i].getName() +"”已经存在,继续粘贴将忽略“"+ tos[i].getName() +"”.\n是否继续执行粘贴操作?", "系统提示",JOptionPane.YES_NO_OPTION); if(confirm == JOptionPane.NO_OPTION){ return false; } continue; } ClientLinkObject clo = this.createEmptyClientLinkObject(parent, loName); clo.setFromBO(from); clo.setToBO(tos[i]); cloList.add(clo); } // 批量创建link try { //如果都存在不需要粘贴返回成功 if(cloList.isEmpty()){ return true; } boOperation.batchSaveCreateBuinessObject( new ClientBusinessObject[0], cloList.toArray(new ClientLinkObject[0])); } catch (Exception e) { showErrorMessage(parent, e); return false; } return true; } /** * 直接复制link对象 * @param parent 父窗体 * @param from from端业务对象 * @param loName from端link类型 * @param clos 复制的link对象 * @return true 操作成功 */ public boolean pasteBusinessObjects(Component parent, ClientBusinessObject from, String loName ,ClientLinkObject[] clos) { if (from == null) { showMessage(parent, "uifmodel.plm.uif.actions.ClipboardError"); return false; } if (loName == null || loName.equals("")) { showMessage(parent, "uifmodel.plm.uif.actions.fromLinkNull"); } if (clos == null || clos.length < 1) { // 剪切板中没有业务对象 showMessage(parent, "uifmodel.plm.uif.actions.ClipboardEmpty"); return false; } //获得from段所有的头端对象 Map toMap = new HashMap(); ClientLinkObject[] existClos; try { existClos = loOperation.readLinkObjectByFromBO(from, loName); if(existClos != null && existClos.length > 0){ for(int i = 0; i loList = new ArrayList(); for (int i = 0; i < clos.length; i++) { clos[i].getLinkObject().ltName = loName; ClientLinkObject clo = cloneClientLinkObject(clos[i]); //判断to端对象是否存在 if(toMap.containsKey(clo.getLinkObject().toOid)){ int confirm = VCIOptionPane.showConfirmDialog( parent, "“" + toMap.get(clo.getLinkObject().toOid).getBusinessObject().name +"”已经存在,继续粘贴将忽略“"+ toMap.get(clo.getLinkObject().toOid).getBusinessObject().name +"”.\n是否继续执行粘贴操作?", "系统提示",JOptionPane.YES_NO_OPTION); if(confirm == JOptionPane.NO_OPTION){ return false; } continue; } clo.setFromBO(from); loList.add(clo); } // 批量创建link try { if(!loList.isEmpty()){ boOperation.batchSaveCreateBuinessObject( new ClientBusinessObject[0], loList.toArray(new ClientLinkObject[0])); } } catch (Exception e) { showErrorMessage(parent, e); return false; } return true; } /** * 克隆一个LO对象 * @param source lo对象 * @return * @throws Exception */ public ClientLinkObject cloneClientLinkObject(LinkObject source){ if(source == null){ return null; } ClientLinkObject clo = new ClientLinkObject(); clo.setLinkObject(source); return cloneClientLinkObject(clo); } /** * 克隆一个LO对象,建立一个新的对象,只复制属性 * @param source lo对象 * @return * @throws Exception */ public ClientLinkObject cloneClientLinkObject(ClientLinkObject source){ if(source == null){ return null; } String loType = source.getLinkObject().ltName; if(loType == null || loType.equals("")){ return null; } //获得空的lo对象 ClientLinkObject newlo = null; try { newlo = loOperation.createLinkObject(loType); //lo对象所具有的属性 AttributeValue[] attrs = newlo.getLinkObject().newAttrValList; //设置新的LO的信息 newlo.setOid(ObjectUtility.getNewObjectID36()); newlo.setCreator(ClientContextVariable.getInvocationInfo().userName); newlo.setCreateTime(System.currentTimeMillis()); newlo.setLastModifier(ClientContextVariable.getInvocationInfo().userName); newlo.setLastModifyTime(System.currentTimeMillis()); newlo.setLoName(loType); newlo.setFromBTMName(source.getLinkObject().fromBTName); newlo.setFromNameOid(source.getLinkObject().fromNameOid); newlo.setFromOid(source.getLinkObject().fromOid); newlo.setFromRevisionOid(source.getLinkObject().fromRevOid); newlo.setToBTMName(source.getLinkObject().toBTName); newlo.setToNameOid(source.getLinkObject().toNameOid); newlo.setToOid(source.getLinkObject().toOid); newlo.setToRevisionOid(source.getLinkObject().toRevOid); newlo.setTs(source.getLinkObject().ts); //设置lo的属性 if(attrs != null && attrs.length > 0){ for(int i = 0; i < attrs.length; i++){ AttributeValue av = attrs[i]; String value = source.getAttributeValue(av.attrName); if(value == null){ value = ""; } av.attrVal = value; } } } catch (VCIError e) { e.printStackTrace(); } return newlo; } /** * 深度克隆lo对象 * @param lo 链接对象 * @return */ public static LinkObject cloneLinkObject(LinkObject lo) { LinkObject newLo = new LinkObject(); newLo.oid = lo.oid; newLo.creator = lo.creator; newLo.createTime = lo.createTime; newLo.modifier = lo.modifier; newLo.modifyTime = lo.modifyTime; newLo.fromOid = lo.fromOid; newLo.fromRevOid = lo.fromRevOid; newLo.fromNameOid = lo.fromNameOid; newLo.fromBTName = lo.fromBTName; newLo.toOid = lo.toOid; newLo.toRevOid = lo.toRevOid; newLo.toNameOid = lo.toNameOid; newLo.toBTName = lo.toBTName; newLo.ts = lo.ts; newLo.ltName = lo.ltName; if(lo.newAttrValList != null && lo.newAttrValList.length > 0){ AttributeValue[] avs = new AttributeValue[lo.newAttrValList.length]; for(int i = 0; i < lo.newAttrValList.length; i++){ AttributeValue boav = lo.newAttrValList[i]; AttributeValue av = new AttributeValue(); av.attrName = boav.attrName; av.attrVal = boav.attrVal; avs[i] = av; } newLo.newAttrValList = avs; } else { newLo.newAttrValList = new AttributeValue[0]; } if(lo.hisAttrValList != null && lo.hisAttrValList.length > 0){ AttributeValue[] avs = new AttributeValue[lo.hisAttrValList.length]; for(int i = 0; i < lo.hisAttrValList.length; i++){ AttributeValue boav = lo.hisAttrValList[i]; AttributeValue av = new AttributeValue(); av.attrName = boav.attrName; av.attrVal = boav.attrVal; avs[i] = av; } newLo.hisAttrValList = avs; } else { newLo.hisAttrValList = new AttributeValue[0]; } return newLo; } public ClientBusinessObject cloneDBBusinessObject(ClientBusinessObject cbo) throws VCIError { return boOperation.cloneBusinessObject(cbo); } /** * 深度克隆一个BO对象 * @param bo 业务对象 * @return */ public static BusinessObject cloneBusinessObject(BusinessObject bo) { BusinessObject newBo = new BusinessObject(); newBo.oid = bo.oid; newBo.revisionid = bo.revisionid; newBo.nameoid = bo.nameoid; newBo.btName = bo.btName; newBo.isLastR = bo.isLastR; newBo.isFirstR = bo.isFirstR; newBo.isLastV = bo.isLastV; newBo.isFirstV = bo.isFirstV; newBo.creator = bo.creator; newBo.createTime = bo.createTime; newBo.modifier = bo.modifier; newBo.modifyTime = bo.modifyTime; newBo.revisionRule = bo.revisionRule; newBo.versionRule = bo.versionRule; newBo.revisionSeq = bo.revisionSeq; newBo.revisionValue = bo.revisionValue; newBo.versionSeq = bo.versionSeq; newBo.versionValue = bo.versionValue; newBo.lctId = bo.lctId; newBo.lcStatus = bo.lcStatus; newBo.ts = bo.ts; newBo.id = bo.id; newBo.name = bo.name; newBo.description = bo.description; newBo.owner = bo.owner; // newBo.checkinBy = bo.checkinBy; // newBo.checkinTime = bo.checkinTime; // newBo.checkoutBy = bo.checkoutBy; // newBo.checkoutTime = bo.checkoutTime; newBo.fromVersion = bo.fromVersion; if(bo.newAttrValList != null && bo.newAttrValList.length > 0){ AttributeValue[] avs = new AttributeValue[bo.newAttrValList.length]; for(int i = 0; i < bo.newAttrValList.length; i++){ AttributeValue boav = bo.newAttrValList[i]; AttributeValue av = new AttributeValue(); av.attrName = boav.attrName; av.attrVal = boav.attrVal; avs[i] = av; } newBo.newAttrValList = avs; } else { newBo.newAttrValList = new AttributeValue[0]; } if(bo.hisAttrValList != null && bo.hisAttrValList.length > 0){ AttributeValue[] avs = new AttributeValue[bo.hisAttrValList.length]; for(int i = 0; i < bo.hisAttrValList.length; i++){ AttributeValue boav = bo.hisAttrValList[i]; AttributeValue av = new AttributeValue(); av.attrName = boav.attrName; av.attrVal = boav.attrVal; avs[i] = av; } newBo.hisAttrValList = avs; } else { newBo.hisAttrValList = new AttributeValue[0]; } return newBo; } /** * 克隆一个新的BO对象,不调用 * @param source 源对象 * @param isNew 是否生成新的对象, * 如果为true则为克隆的对象生成新的oid、Revisionid、Nameoid * @return */ public static BusinessObject cloneEmptyClientBusinessObject(BusinessObject source, boolean isNew){ ClientBusinessObject cbo = new ClientBusinessObject(); cbo.setBusinessObject(source); return cloneEmptyClientBusinessObject(cbo, isNew).getBusinessObject(); } /** * 克隆一个新的CBO对象,不调用 * @param source 源对象 * @param isNew 是否生成新的对象, * 如果为true则为克隆的对象生成新的oid、Revisionid、Nameoid * @return */ public static ClientBusinessObject cloneEmptyClientBusinessObject(ClientBusinessObject source, boolean isNew){ if(source == null){ return null; } ClientBusinessObject bo = new ClientBusinessObject(); if(isNew){ bo.setOid(ObjectUtility.getNewObjectID36()); bo.setRevisionid(ObjectUtility.getNewObjectID36()); bo.setNameoid(ObjectUtility.getNewObjectID36()); } else { bo.setOid(source.getOid()); bo.setRevisionid(source.getRevisionid()); bo.setNameoid(source.getNameoid()); } bo.setBtmName(source.getBtmName()); bo.setIsLastR(source.getIsLastR()); bo.setIsFirstR(source.getIsFirstR()); bo.setIsFirstV(source.getIsFirstV()); bo.setIsLastV(source.getIsLastV()); bo.setCreator(source.getCreator()); bo.setCreateTime(source.getCreateTime()); bo.setLastModifier(source.getLastModifier()); bo.setLastModifyTime(source.getLastModifyTime()); bo.setRevisionRule(source.getRevisionRule()); bo.setVersionRule(source.getVersionRule()); bo.setRevisionSeq(source.getRevisionSeq()); bo.setRevisionValue(source.getRevisionValue()); bo.setVersionSeq(source.getVersionSeq()); bo.setVersionValue(source.getVersionValue()); bo.setLctId(source.getLctId()); bo.setLcStatus(source.getLcStatus()); bo.setId(source.getId()); bo.setName(source.getName()); bo.setDescription(source.getDescription()); bo.setOwner(source.getOwner()); //bo.setCheckinBy(source.getCheckinBy()); bo.setCopyFromVersion(source.getCopyFromVersion()); //设置BO自定义属性 AttributeValue[] attrs = null; if(source.getBusinessObject().newAttrValList != null){ int size = source.getBusinessObject().newAttrValList.length; attrs = new AttributeValue[size]; AttributeValue[] sourceAttrs = source.getBusinessObject().newAttrValList; for(int i = 0; i < sourceAttrs.length; i++){ AttributeValue av = new AttributeValue(); av.attrName = sourceAttrs[i].attrName; av.attrVal = ""; attrs[i] = av; } } bo.getBusinessObject().newAttrValList = attrs; return bo; } /** * 克隆一个LO对象,建立一个新的对象,只复制属性 * @param source lo对象 * @return * @throws Exception */ public static ClientLinkObject cloneEmptyClientLinkObject(ClientLinkObject source, boolean isNew){ if(source == null){ return null; } //获得空的lo对象 //ClientLinkObject newlo = loOperation.createLinkObject(loType); ClientLinkObject newlo = new ClientLinkObject(); //设置新的LO的信息 if(isNew){ newlo.setOid(ObjectUtility.getNewObjectID36()); } else { newlo.setOid(source.getLinkObject().oid); } newlo.setCreator(source.getCreator()); newlo.setCreateTime(source.getCreateTime()); newlo.setLastModifier(source.getLastModifier()); newlo.setLastModifyTime(source.getLastModifyTime()); newlo.setLoName(source.getLoName()); newlo.setFromBTMName(source.getLinkObject().fromBTName); newlo.setFromNameOid(source.getLinkObject().fromNameOid); newlo.setFromOid(source.getLinkObject().fromOid); newlo.setFromRevisionOid(source.getLinkObject().fromRevOid); newlo.setToBTMName(source.getLinkObject().toBTName); newlo.setToNameOid(source.getLinkObject().toNameOid); newlo.setToOid(source.getLinkObject().toOid); newlo.setToRevisionOid(source.getLinkObject().toRevOid); newlo.setTs(source.getLinkObject().ts); //设置lo的属性 AttributeValue[] attrs = source.getLinkObject().newAttrValList; if(attrs != null){ AttributeValue[] newAttrs = new AttributeValue[attrs.length]; for(int i = 0; i < attrs.length; i++){ AttributeValue av = new AttributeValue(); av.attrName = attrs[i].attrName; av.attrVal = ""; newAttrs[i] = av; } newlo.getLinkObject().newAttrValList = newAttrs; } return newlo; } /** * 得到cbo对象的集合 * @param objs IDataNode集合 * @param direction 如果objs主对像是clo,则用于判断是下载from还是to端对象 * 正向下载to端对象 * @return * @throws Exception */ public ClientBusinessObject[] getClentBusinessObjects( Object[] objs, boolean direction) throws Exception { if(objs == null || objs.length < 1){ return null; } ClientBusinessObject[] cobs = new ClientBusinessObject[objs.length]; for(int i =0; i < objs.length; i++){ if(objs[i] instanceof IDataNode){ if(((IDataNode)objs[i]).getMaterObject() instanceof ClientBusinessObject){ cobs[i] = (ClientBusinessObject) ((IDataNode)objs[i]).getMaterObject(); } else if(((IDataNode)objs[i]).getMaterObject() instanceof ClientLinkObject){ ClientLinkObject clo = (ClientLinkObject) ((IDataNode)objs[i]).getMaterObject(); String oid = ""; String btmName = ""; if(direction){ oid = clo.getLinkObject().toOid; btmName = clo.getLinkObject().toBTName; } else { oid = clo.getLinkObject().fromOid; btmName = clo.getLinkObject().fromBTName; } cobs[i] = boOperation.readBusinessObjectById(oid, btmName); } } } return cobs; } /** * 转换null为空字符 * 去掉前后的空格 * @param str * @return */ public static String getStringNotNull(String str) { if(str == null) { str = ""; } return str.trim(); } /** * 查询BO对象 * @param conditions 查询条件 * @param btmName 业务对象类型 * @return * @throws VCIError */ public static BusinessObject[] queryBusinessObject( Map conditions, String btmName) throws VCIError { return queryBusinessObjectLRLV(conditions, btmName, false); } /** * 查询BO对象 * @param oid 业务对象OID * @param btmName 类型 * @param queryChildren 是否查询子类型数据 * @return * @throws VCIError */ public static ClientBusinessObject queryBusinessObject( String oid, String btmName, boolean queryChildren) throws VCIError { Map conditions = new HashMap(); conditions.put("oid", oid); BusinessObject[] bos = queryBusinessObject( conditions, btmName, queryChildren, Version.currentRevCurrentVer); ClientBusinessObject cbo = new ClientBusinessObject(); if(bos != null && bos.length > 0) { cbo.setBusinessObject(bos[0]); } return cbo; } /** * 查询BO对象 * 最新版本最新版次 * @param conditions 查询条件 * @param btmName 业务对象类型 * @pabtmNamedren 是否查询子分类 * @return * @throws VCIError */ public static BusinessObject[] queryBusinessObjectLRLV(Map conditions, String btmName, boolean queryChildren) throws VCIError { return queryBusinessObject(conditions, btmName, queryChildren, Version.lastRevLastVer); } /** * 查询BO对象 * 查询不经过数据权限校验 * @param conditions 查询条件 * @param btmName 业务对象类型 * @pabtmNamedren 是否查询子分类 * @return * @throws VCIError * @throws Exception */ public static BusinessObject[] queryBusinessObject(Map conditions, String btmName, boolean queryChildren, int version) throws VCIError { QueryTemplate qt2 = new QueryTemplate(); qt2.setId("btmQuery"); qt2.setBtmType(btmName); qt2.setType("btm"); qt2.setRightFlag(false); qt2.setVersion(version); qt2.setQueryChildrenFlag(queryChildren); List clauseList = new ArrayList(); clauseList.add("*"); qt2.setClauseList(clauseList); Condition cond = OQTool .getCondition(conditions); qt2.setCondition(cond); BusinessObject[] bos = QTClient.getService().findBTMObjects( qt2.getId(), OQTool.qtTOXMl(qt2).asXML()); return bos; } /** * 查询BO对象 * 实现批量查询 * 查询不经过数据权限校验 * @param key 过滤属性名称 * @param value 过滤属性值,多个用“,”号隔开 * @param toType BO的类型 * @return * @throws VCIError * @throws Exception */ public static BusinessObject[] queryBusinessObject( String key, String value, String toType) throws VCIError { QueryTemplate qt2 = new QueryTemplate(); qt2.setId("btmQuery"); qt2.setBtmType(toType); qt2.setType("btm"); qt2.setRightFlag(false); qt2.setQueryChildrenFlag(true); qt2.setVersion(Version.lastRevLastVer); List clauseList = new ArrayList(); clauseList.add("*"); qt2.setClauseList(clauseList); Condition cond = new Condition(); cond.setRootCIName("ci1"); Map cIMap = new HashMap(); ConditionItem ci1 = new ConditionItem(); ci1.setId("ci1"); ci1.setLeafFlag(true); LeafInfo leafInfo = new LeafInfo(); leafInfo.setClause(key); leafInfo.setOperator(Operator.IN); LeafValue value_ = new LeafValue(); value_.setOrdinaryValue(value); leafInfo.setValue(value_ ); ci1.setLeafInfo(leafInfo ); cIMap.put("ci1", ci1 ); cond.setCIMap(cIMap ); qt2.setCondition(cond); BusinessObject[] bos = QTClient.getService().findBTMObjects( qt2.getId(), OQTool.qtTOXMl(qt2).asXML()); return bos; } /** * 批量查询BO对象 * @param btmName BO类型 * @param key 过滤属性 * @param valueList 属性值列表 * @return 属性值+BO的Map * @throws Exception */ public static Map queryBusinessObject( String btmName, String key,List valueList) throws Exception{ Map boMap = new HashMap(); if(valueList == null || valueList.isEmpty()){ return boMap; } int number = 0; do { int start = number; StringBuilder conditionValue = new StringBuilder("("); int end = number + 999 <= valueList.size() ? number + 999 : valueList.size(); for(int i = start; i < end; i++){ if(i != start){ conditionValue.append(","); } conditionValue.append("'").append(valueList.get(i)).append("'"); } conditionValue.append(")"); BusinessObject[] bos = UIFUtils .queryBusinessObject(key, conditionValue.toString(), btmName); if(bos != null){ for(BusinessObject bo : bos){ boMap.put(ObjectTool.getBOAttributeValue(bo, key), bo); } } number += 999; } while(number < valueList.size()); return boMap; } /** * 批量查询BO对象 * @param btmName BO类型 * @param key 过滤属性 * @param valueList 属性值列表 * @return 包装成ClientBusinessObject * @throws VCIError */ public static List queryBusinessObjectList( String btmName, String key,List valueList) throws VCIError { List cboList = new ArrayList(); if(valueList == null || valueList.isEmpty()){ return cboList; } int number = 0; do { int start = number; StringBuilder conditionValue = new StringBuilder("("); int end = number + 999 <= valueList.size() ? number + 999 : valueList.size(); for(int i = start; i < end; i++){ if(i != start){ conditionValue.append(","); } conditionValue.append("'").append(valueList.get(i)).append("'"); } conditionValue.append(")"); BusinessObject[] bos = UIFUtils .queryBusinessObject(key, conditionValue.toString(), btmName); if(bos != null){ for(BusinessObject bo : bos){ ClientBusinessObject cbo = new ClientBusinessObject(); cbo.setBusinessObject(bo); cboList.add(cbo); } } number += 999; } while(number < valueList.size()); return cboList; } /** * 通过From查询LO和to端BO对象 * 查询不经过数据权限校验 * @param lintype * @param fromOrToOid * @param direction * @return * @throws VCIError */ public static BOAndLO[] queryLOAddBO(String lintype, String btmType, Map conditioin, boolean direction) throws VCIError{ QueryTemplate qt2 = new QueryTemplate(); qt2.setId("ltQuery"); qt2.setLinkType(lintype); qt2.setType("link"); qt2.setBtmType(btmType); qt2.setRightFlag(false); List clauseList = new ArrayList(); clauseList.add("*"); qt2.setClauseList(clauseList); if(direction){ qt2.setDirection("positive"); }else{ qt2.setDirection("opposite"); } Condition cond = OQTool.getCondition(conditioin); qt2.setCondition(cond); BOAndLO[] loaddbo = QTClient.getService().getBOAndLOS( qt2.getId(), OQTool.qtTOXMl(qt2).asXML(),""); return loaddbo; } /** * 查询LO及BO对象 最新版本最新版次 * @param lintype 查询的链接类型 * @param btmName 查询的BO类型 * @param startOid 起始OID * @param direction 正反向 * @param level 查询层数 * @return * @throws VCIError */ public static BOAndLO[] queryLOAddBO(String lintype, String btmName, String startOid, boolean direction, int level) throws VCIError{ return queryLOAddBO(lintype, btmName, startOid, direction, level, Version.lastRevLastVer); } /** * 查询LO及BO对象 * @param lintype 查询的链接类型 * @param btmName 查询的BO类型 * @param startOid 起始OID * @param direction 正反向 * @param level 查询层数 * @param version 版本版次 * @return * @throws VCIError */ public static BOAndLO[] queryLOAddBO(String lintype, String btmName, String startOid, boolean direction, int level, int version) throws VCIError{ QueryTemplate qt9 = new QueryTemplate(); qt9.setId("ltQuery"); qt9.setLinkType(lintype); qt9.setType("link"); qt9.setBtmType(btmName); qt9.setRightFlag(false); List clauseList = new ArrayList(); clauseList.add("*"); qt9.setClauseList(clauseList); qt9.setVersion(version); Map conditions = new HashMap(); if(direction){ qt9.setDirection("positive"); conditions.put("f_oid", startOid); }else{ qt9.setDirection("opposite"); conditions.put("t_oid", startOid); } Condition cond = OQTool.getCondition(conditions); qt9.setCondition(cond); qt9.setLevel(level); BOAndLO[] loaddbo = QTClient.getService().getBOAndLOS( qt9.getId(), OQTool.qtTOXMl(qt9).asXML(),""); return loaddbo; } /** * 通过From查询LO和to端BO对象 * 查询不经过数据权限校验 * @param lintype * @param fromOrToOid * @param direction * @return * @throws VCIError */ public static LinkObject[] queryLinkObejct(String lintype, String btmType, Map conditioin, boolean direction) throws VCIError{ QueryTemplate qt2 = new QueryTemplate(); qt2.setId("ltQuery"); qt2.setLinkType(lintype); qt2.setType("link"); qt2.setRightFlag(false); if(btmType != null && !btmType.equals("")) { qt2.setBtmType(btmType); } List clauseList = new ArrayList(); clauseList.add("*"); qt2.setClauseList(clauseList); if(direction){ qt2.setDirection("positive"); }else{ qt2.setDirection("opposite"); } Condition cond = OQTool.getCondition(conditioin); qt2.setCondition(cond); LinkObject[] los = QTClient.getService().findLTObjects( qt2.getId(), OQTool.qtTOXMl(qt2).asXML()); return los; } /** * 获取表单数据 * @param f * @return * @throws IOException * @throws VCIError */ public static List getFileList(File f) throws Exception { // 获取流 BufferedInputStream fileInputStream = new BufferedInputStream( new FileInputStream(f)); String name = f.getName(); // 获取表list List sheetDataSets = ExcelDocumentUtils .readExcelDocument(name, fileInputStream, true); return sheetDataSets; } /** * 到处Excel文件 * @param frame 所属窗口 * @param datas Excel文件数据 * @param sheetName 工作表名称 * @return */ public static File exportExcel(Window frame, String[][] datas, String sheetName) throws Exception{ File file = getRequiredFile(frame, false); if(file == null) { return null; } String fileName = file.getAbsolutePath(); // add by xchao 2014.05.15 end new ExcelFileOperation().writeExcelFileInfo(fileName, sheetName, datas, new ExcelCellStyleSettingCallback() { @Override public WorkboolStyleSetting doSetWorkbookStyle( final Workbook workbook) { WorkboolStyleSetting setting = new WorkboolStyleSetting() { @Override public LinkedHashMap getStyleMap() { LinkedHashMap styleMap = new LinkedHashMap(); org.apache.poi.ss.usermodel.CellStyle style = workbook .createCellStyle(); org.apache.poi.ss.usermodel.Font font = (org.apache.poi.ss.usermodel.Font) workbook .createFont(); font.setColor(HSSFFont.COLOR_RED); style.setFont(font); return styleMap; } }; return setting; } }); return file; } public static File getRequiredFile(Window frame, boolean isRead){ File files = getExcelFile(frame); // add by xchao 2014.04.15 begin // 有错误数据要输出时,必须选择有效的excel文件 if(files == null) { return null; } String fileName = files.getAbsolutePath(); // 需要写入时,必须选择一个有效的、可以写入的文件 if(!isRead){ // 如果文件被打开着,则必须选择其它的未打开着的文件 while (files.exists() && !files.renameTo(new File(fileName))) { VCIJOptionPane.showMessageDialog(null, "另一个程序正在使用此文件,进程无法访问,请重新选择!"); // 重新选择文件时,也必须选择有效的excel文件 files = null; while(files == null){ files = getExcelFile(frame); } fileName = files.getAbsolutePath(); } } return files; } /** * 选择Excel文件 * @param frame 所属窗口 * @return */ public static File getExcelFile(Window frame) { File file = null; String filePath = VCISwingUtil.getExcelFileURL(frame, true, ""); if(filePath != null){ file = new File(filePath); } return file; } /** * 获得用户选择对象对应的CBO对象 * @param selectedObjects 用户选择的对象 * @param direction 是正向还是反向:正向取to端;反向取from端 * @return * @throws Exception */ public ClientBusinessObject getBusinessObject( Object[] selectedObjects, boolean direction) throws Exception{ ClientBusinessObject cbo = null; if(selectedObjects == null || selectedObjects.length < 1){ return cbo; } if(selectedObjects[0] instanceof IDataNode){ IDataNode dtn = (IDataNode) selectedObjects[0]; if(dtn.getMaterObject() instanceof ClientBusinessObject){ cbo = (ClientBusinessObject) dtn.getMaterObject(); } else if(dtn.getMaterObject() instanceof ClientLinkObject){ ClientLinkObject clo = (ClientLinkObject) dtn.getMaterObject(); String oid = direction ? clo.getLinkObject().toOid : clo.getLinkObject().fromOid; String btmName = direction ? clo.getLinkObject().toBTName : clo.getLinkObject().fromBTName; if(oid != null && !oid.equals("") && btmName != null && !btmName.equals("")) { cbo = boOperation.readBusinessObjectById(oid, btmName); } } } return cbo; } /** * 获得用户选择对象对应的CBO对象 * @param selectedObject 用户选择的对象 * @param direction 是正向还是反向:正向取to端;反向取from端 * @return * @throws Exception */ public ClientBusinessObject getBusinessObject( Object selectedObject, boolean direction) throws Exception{ ClientBusinessObject cbo = null; if(selectedObject == null ){ return cbo; } if(selectedObject instanceof IDataNode){ IDataNode dtn = (IDataNode) selectedObject; if(dtn.getMaterObject() instanceof ClientBusinessObject){ cbo = (ClientBusinessObject) dtn.getMaterObject(); } else if(dtn.getMaterObject() instanceof ClientLinkObject){ ClientLinkObject clo = (ClientLinkObject) dtn.getMaterObject(); String oid = direction ? clo.getLinkObject().toOid : clo.getLinkObject().fromOid; String btmName = direction ? clo.getLinkObject().toBTName : clo.getLinkObject().fromBTName; if(oid != null && !oid.equals("") && btmName != null && !btmName.equals("")) { cbo = boOperation.readBusinessObjectById(oid, btmName); } } } return cbo; } /** * 获得系统中枚举类型对应的值 * @param btmName 类型名称 * @param attrName 属性名称 * @param key 键值 * @return * @throws Exception */ public String transferEnum(String btmName, String attrName, String key) throws Exception{ if(key == null || key.equals("")) { return ""; } Map sysEnumMap = UIFCache.getInstance().getSysEnumMap(); if(sysEnumMap.containsKey(btmName + "#" + attrName + "#" + key)){ return sysEnumMap.get(btmName + "#" + attrName + "#" + key); } else { //BtmAndApName[] baans = BtmClient.getService().getBtmAndApNameArray(btmName); BtmItem bt = BtmClient.getService().getBtmItemByName(btmName); BtmAndApName baan = new BtmAndApName(bt.name, bt.apNameArray); //for(BtmAndApName baan : baans) { AttribItem[] arItems = APClient.getService().getAttribItemsByNames(baan.apName); for(AttribItem ai : arItems){ if(ai.name.equals(attrName)){ String[] others = ai.other.split(";"); for(String other : others){ String[] cvs = other.split("="); if(cvs[0].trim().equalsIgnoreCase("enumName")){ String enumName = cvs[1].trim(); //EnumItemFilter filter = new EnumItemFilter(enumName); EnumItem[] enumItems = ServiceProvider.getOMDService().getEnumService().getEmItems(enumName, 1, 1); for(EnumItem ei : enumItems){ for(EnumChild ec : ei.children){ sysEnumMap.put(btmName + "#" + attrName + "#" + ec.value, ec.name); } } } } } } //} return sysEnumMap.get(btmName + "#" + attrName + "#" + key); } } /** * 转译生命周期状态 * @param statusName 状态名称 * @return */ public String transferLifecycle(String statusName) { if(statusName == null) { return ""; } String lcStatuc = ""; try { boolean exist = false; StatePool[] statePools = UIFCache.getInstance().getStatePools(); for(StatePool sp:statePools){ if(sp.name.equals(statusName)){ lcStatuc = sp.tag; exist = true; break; } } if(exist){ return lcStatuc; } } catch (Exception e) { e.printStackTrace(); } return statusName; } /** * 查询生命周期节点 * @param lcName 生命周期名称 * @param lcDestStatus 状态 * @return */ public static TransitionVO getTransitionVO(String lcName, String lcSourceStatus,String lcDestStatus) { if (lcSourceStatus == null || lcDestStatus == null) { return null; } lcSourceStatus = lcSourceStatus.trim(); lcDestStatus = lcDestStatus.trim(); LifeCycle lc = getLifeCycle(lcName); if(lc != null) { for (int i = 0; i < lc.routes.length; ++i) { TransitionVO route = lc.routes[i]; if (route.destination.equals(lcDestStatus) && route.source.equals(lcSourceStatus)){ return route; } } } return null; } /** * 查询业务对象的生命周期 * @param lcName 生命周期名称 * @return */ public static LifeCycle getLifeCycle(String lcName) { //得到所有LifeCyle对象 try { LifeCycle[] lifeCyles = LifeCycleStart.getService().getLifeCycles(); for(int i = 0; i < lifeCyles.length; i++){ LifeCycle lc = lifeCyles[i]; //得到业务对象的生命周期 if(lc.name.equals(lcName)) { return lc; } } } catch (VCIError e) { e.printStackTrace(); } return null; } /** * 获得系统默认属性对应的系统数据类型 * @param name 属性名称 * @return 当属性不是系统默认属性时,返回null */ public static String getDefaultAttributeDataType(String name) { if("oid".equalsIgnoreCase(name) || "revisionoid".equalsIgnoreCase(name) || "nameoid".equalsIgnoreCase(name) || "btmname".equalsIgnoreCase(name) || "islastr".equalsIgnoreCase(name) || "isfirstr".equalsIgnoreCase(name) || "islastv".equalsIgnoreCase(name) || "isfirstv".equalsIgnoreCase(name) || "creator".equalsIgnoreCase(name) || "lastmodifier".equalsIgnoreCase(name) || "revisionrule".equalsIgnoreCase(name) || "versionrule".equalsIgnoreCase(name) || "revisionseq".equalsIgnoreCase(name) || "revisionvalue".equalsIgnoreCase(name) || "versionseq".equalsIgnoreCase(name) || "versionvalue".equalsIgnoreCase(name) || "lctid".equalsIgnoreCase(name) || "lcstatus".equalsIgnoreCase(name) || "id".equalsIgnoreCase(name) || "name".equalsIgnoreCase(name) || "description".equalsIgnoreCase(name) || "owner".equalsIgnoreCase(name) || "checkinby".equalsIgnoreCase(name) || "checkoutby".equalsIgnoreCase(name) || "copyfromversion".equalsIgnoreCase(name)) { return VTDataType.VTSTRING; } else if ("createtime".equalsIgnoreCase(name) || "lastmodifytime".equalsIgnoreCase(name) || "ts".equalsIgnoreCase(name) || "checkintime".equalsIgnoreCase(name) || "checkouttime".equalsIgnoreCase(name)) { return VTDataType.VTDATETIME; } return null; } /** * 得到表单上field对应PRMItem集合 * @param formPrm PRM对象 * @return */ public static Map getColAndPRMItemMap(PRM formPrm){ Map prmItemMap = new HashMap(); List prmItemList = formPrm.getPrmItemList(); if(prmItemList == null || prmItemList.isEmpty()){ return prmItemMap; } for(int i = 0; i < prmItemList.size(); i++){ PRMItem p = prmItemList.get(i); if(p.getItemField() != null && !p.getItemField().equals("")){ String field = p.getItemField(); prmItemMap.put(field, p); } } return prmItemMap; } /** * 根据查询模板名称,返回查询模板 * @param queryTemplateName 查询模板 * @return */ public static QueryTemplate getQueryTemplateByName(String queryTemplateName){ QueryTemplate qt = null; try{ QTInfo wrapper = ServiceProvider.getOMDService().getQTDService().getQT(queryTemplateName); qt = OQTool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), queryTemplateName); } catch (VCIError e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } return qt; } /** * 显示异常信息 * 使用资源文件 UIFModelAction * 其它异常信息使用资源文件UIFModelAction:uifmodel.plm.uif.actions.syserror * @param parent 父窗口 * @param e VCIException * @deprecated 本接口默认使用 properties/UIFModelAction.properties作为国际化资源文件,不具备通用性, * 被 showErrorMessage(parent, e, resourceFileName) 替代 */ @Deprecated public static void showErrorMessage(Component parent, VCIException e){ showErrorMessage(parent, e, UIFMODEL_RESOURCE_FILE_NAME); } /** * 显示异常信息 * 其它异常信息使用资源文件UIFModelAction:uifmodel.plm.uif.actions.syserror * @param parent 父窗口 * @param e VCIException * @param resourceFileName 国际化资源文件名称 */ public static void showErrorMessage(Component parent, VCIException e, String resourceFileName){ showErrorMessage(parent, "uifmodel.plm.uif.actions.syserror", e, resourceFileName); } /** * 显示异常信息 枚举 * 使用资源文件 UIFModelAction * Client端的 VCIError是已经转化后的,error_code为国际化后的异常信息 * 其它异常信息使用资源文件UIFModelAction:uifmodel.plm.uif.actions.syserror * @param parent 父窗口 * @param e * @deprecated 本接口默认使用 properties/UIFModelAction.properties作为国际化资源文件,不具备通用性, * 被 showErrorMessage(parent, e, resourceFileName) 替代 */ @Deprecated public static void showErrorMessage(Component parent, Throwable e){ showErrorMessage(parent, e, UIFMODEL_RESOURCE_FILE_NAME); } /** * 显示异常信息 枚举 * Client端的 VCIError是已经转化后的,error_code为国际化后的异常信息 * 其它异常信息使用资源文件UIFModelAction:uifmodel.plm.uif.actions.syserror * @param parent 父窗口 * @param e * @param resourceFileName 国际化资源文件名称 */ @Deprecated public static void showErrorMessage(Component parent, Throwable e, String resourceFileName){ showErrorMessage(parent, "uifmodel.plm.uif.actions.syserror", e, resourceFileName); } /** * 显示异常信息 * @param parent 父窗口 * @param code 国际化文件对应编码 * 使用资源文件 UIFModelAction * @param e 异常信息 * @param resourceFileName 国际化资源文件名称 * @deprecated 本接口默认使用 properties/UIFModelAction.properties作为国际化资源文件,不具备通用性, * 被 showErrorMessage(parent, code, e, resourceFileName) */ public static void showErrorMessage(Component parent, String code, Throwable e){ showErrorMessage(parent, code, e, UIFMODEL_RESOURCE_FILE_NAME); } /** * 显示异常信息 * @param parent 父窗口 * @param code 国际化文件对应编码 * @param e 异常信息 * @param resourceFileName 国际化资源文件名称 */ public static void showErrorMessage(Component parent, String code, Throwable e, String resourceFileName){ writeClientLog(e); if(parent == null){ parent = ClientContextVariable.getFrame(); } String message = getExceptionMessage(e, resourceFileName); showMessageDetails(parent, message, true); } /** * 显示异常信息 * @param parent 父窗口 * @param code 国际化文件对应编码 * @param resourceFileName 国际化资源文件名称 * @param args */ public static void showErrorMessage(Component parent, String code, String resourceFileName, Object...args){ if(parent == null){ parent = ClientContextVariable.getFrame(); } String message = LocaleDisplay.getI18nString(code, resourceFileName, Locale.getDefault()); message = MessageFormat.format(message, args); showMessageDetails(parent, message, true); } /** * 获得异常信息 * @param e 异常 * @return */ private static String getExceptionMessage(Throwable e, String resourceFileName) { if (e == null) { return ""; } String str = ""; String code = ""; Object[] messages = new String[0]; // TODO 待异常对象改造完毕(对象自我说明,对应的error_code在哪个国际化资源文件), boolean isErrorOrException = false; if (e instanceof VCIError) { code = ((VCIError) e).code; //打印异常信息 messages = ((VCIError) e).messages; isErrorOrException = true; } else if (e instanceof VCIException) { code = ((VCIException) e).getException_code(); //打印异常信息 messages = ((VCIException) e).getException_objArray(); isErrorOrException = true; } if(isErrorOrException){ if(messages != null) { for(Object temp : messages) { System.out.println(temp); } } String message = LocaleDisplay.getI18nString(code, resourceFileName, Locale.getDefault()); message = MessageFormat.format(message, messages); str = message; } else { if (e.getCause() != null) str = e.getCause().toString(); else { str = e.toString(); } if (str == null) { str = ""; } } return str; } /** * 显示消息 * 使用文件 UIFModelAction * @param parent 展示窗口 * @param code 国际化文件对应编码 * @param args 参数 * @deprecated 本接口默认使用 properties/UIFModelAction.properties作为国际化资源文件,不具备通用性, * 被 showMessage(parent, code, resourceFileName, args) 替代 */ @Deprecated public static void showMessage(Component parent, String code, Object ... args){ showMessageBySpecifyFileName(parent, code, UIFMODEL_RESOURCE_FILE_NAME, args); } /** * 显示消息 * 使用文件 UIFModelAction * @param parent 展示窗口 * @param code 国际化文件对应编码 * @param resourceFileName 国际化文件名称(该文件需要位于 src/properties 文件夹下,打包后该文件位于jar包根目录里properties文件夹下) * @param args 参数 */ public static void showMessageBySpecifyFileName(Component parent, String code, String resourceFileName, Object...args){ if(parent == null){ parent = ClientContextVariable.getFrame(); } showMessageDetails(parent, getI18nString(code, resourceFileName, args), false); } /** * 显示普通消息 * 不需要国际化 * @param parent 父窗口 * @param message 消息 */ public static void showCommonMessage(Component parent, String message){ if(parent == null){ parent = ClientContextVariable.getFrame(); } showMessageDetails(parent, message, false); } /** * 显示消息 * *内部类,不可修改* * @param parent 父窗口 * @param message 显示的消息 */ private static void showMessageDetails(Component parent, String message, boolean isError) { //获得系统配置,判断是弹出框还是右下角提示信息 String displayModes = ConfigUtils.getConfigValue("PromptMessage.DisplayModes"); if(displayModes != null && displayModes.trim().equals("popup")) { if(isError){ VCIJOptionPane.showError(parent, message); } else{ VCIJOptionPane.showMessage(parent, message); } } else { showPositionMessageDetails(message, isError); } } /** * 在窗口右下角显示提示信息 * *内部类,不可修改* * @param message */ private static void showPositionMessageDetails(String message, boolean isError){ //获得弹出窗口显示时间 int displayTime = 3000; String displayTimeStr = ConfigUtils.getConfigValue("PromptMessage.DisplayTime"); if(displayTimeStr == null || displayTimeStr.trim().equals("")) { displayTimeStr = "3000"; try { displayTime = Integer.parseInt(displayTimeStr); } catch (Exception e) { } } PositionMessager msger = new PositionMessager(); //TODO 待完善注入设置是否显示错误 //msger.setError(isError); // 消息显示停留时间,单位为毫秒 msger.setShowTimes(displayTime); msger.show(message); } /** * 返回 客户端是否启用日志输出 * @return */ private static boolean isEnableClientLog(){ return true; } /** * 输出客户端日志 * @param e */ public static void writeClientLog(Throwable e){ if(isEnableClientLog()){ //TODO 需要调用日志接口输出 // 暂时往往控制台输出 e.printStackTrace(); } } /** * 输出客户端日志 * @param message */ public static void writeClientLog(String message){ if(isEnableClientLog()){ //TODO 需要调用日志接口输出 // 暂时往往控制台输出 System.out.println(message); } } /** * 输出耗时日志 * @param message * @param start * @param end */ public static void writeClientLog(String message, long start, long end){ long sp = (end - start) / 1000; if(sp <= 0){ return; } writeClientLog(message + String.valueOf(sp) + "s"); } /** * 检查指定的字符串是否是Freemarker公式表达式 * @param itemValue * @return */ public static boolean isFreemarkTemplateContent(String itemValue){ int startPos = itemValue.indexOf("${"); int endPos = itemValue.indexOf("}"); return (startPos >= 0 && endPos >= 0 && startPos < endPos); } /** * 根据Freemarker公式表达式,从IDataData中返回解析后的灵气 * @param itemValue * @param sourceData * @return */ public static String getRuleValue(String itemValue, IDataNode sourceData, IRegionPanel regionPanel){ Map valueMap = sourceData.getValueMap(); String defaultValue = ""; // ${t_oid.notfound}-${f_oid.notfound} String rule = itemValue; int start = rule.indexOf("${"); int end = rule.indexOf("}"); boolean allFieldExistInMap = true; while(start >= 0 && end >= 0 && start < end && end < rule.length()){ String fieldRule = rule.substring(start+2, end); rule = rule.substring(end+1); if(!valueMap.containsKey(fieldRule)){ allFieldExistInMap = false; defaultValue = ""; break; } start = rule.indexOf("${"); end = rule.indexOf("}"); } // update by xchao 2014.03.26 end if(allFieldExistInMap){ Map rootMap = convertValueMapToFPOMap(valueMap, regionPanel); defaultValue = FreeMarkerCommon.getValueByTempRule(rootMap, itemValue.replace(".", "_")); } return defaultValue; } private static Map convertValueMapToFPOMap(Map map, IRegionPanel regionPanel){ Map rootMap = new LinkedHashMap(); Iterator it = map.keySet().iterator(); while(it.hasNext()){ String key = it.next(); String value = map.get(key); if(regionPanel != null){ String valueFromUILayout = regionPanel.getBaseLayoutPanel().getValue(key); if(!valueFromUILayout.equals(key)){ value = valueFromUILayout; } } if(value == null){ value = ""; } String newKey = key.replace(".", "_"); FreemarkerParamObject fpo = new FreemarkerParamObject(newKey, value); rootMap.put(newKey, fpo); } return rootMap; } /** * 返回 ComboBox 自定义DataProvider实例 * @param className 自定义DataProvider类完整名称 如: a.b.c?btmname=xx&name=${name}-${id}-${code} * @return */ public static IComboBoxDataProvider getComboBoxDataProvider(String className){ IComboBoxDataProvider res = null; try{ if(className == null || "".equals(className)) return res; Class[] paramClass = new Class[]{String.class}; String[] paramValue = new String[]{""}; if(className.contains("?")){ int index = className.indexOf("?"); paramValue[0] = className.substring(index + 1); className = className.substring(0, index); } Object obj = Class.forName(className).getConstructor(paramClass).newInstance(paramValue); if(obj == null) return res; if(obj instanceof IComboBoxDataProvider){ res = (IComboBoxDataProvider) obj; } }catch(Exception ex){ ex.printStackTrace(); } return res; } /** * 检查字符串是否为null或空 * @param value 待检查的字符串 * @return 如果 待检查字符串为null或空(value.equals("")),返回true */ public static boolean isNullOrEmpty(String value){ return (value == null || "".equals(value)); } /** * * @param key * @return * @deprecated 本接口默认使用 properties/UIFModelAction.properties作为国际化资源文件,不具备通用性, * 被 getI18nString(key, resourceFileName, args) 替代 */ @Deprecated public static String getI18nString(String key) { return getI18nString(key, UIFMODEL_RESOURCE_FILE_NAME); } /** * 返回指定KEY在应用的国际化文件 resourceFileName 里的内容 * @param key 国际化文件对应编码 * @param resourceFileName 国际化文件名称(该文件需要位于 src/properties 文件夹下,打包后该文件位于jar包根目录里properties文件夹下) * @param args 参数 * @return */ public static String getI18nString(String key, String resourceFileName, Object...args){ String res = LocaleDisplay.getI18nString(key, resourceFileName, Locale.getDefault()); if(res == null){ return ""; } res = MessageFormat.format(res, args); return res; } public static ClientBusinessObject[] convertBOs(BusinessObject[] bos){ ClientBusinessObject[] cbos = new ClientBusinessObject[bos.length]; for (int i = 0; i < bos.length; i++) { cbos[i] = convertBO(bos[i]); } return cbos; } public static ClientBusinessObject convertBO(BusinessObject bo){ ClientBusinessObject cbo = new ClientBusinessObject(); cbo.setBusinessObject(bo); return cbo; } protected static UIFUtils _uifUtilsInstance = null; public static UIFUtils getInstance(){ if(_uifUtilsInstance == null){ synchronized (UIFUtils.class) { if(_uifUtilsInstance == null){ _uifUtilsInstance = new UIFUtils(); } } } return _uifUtilsInstance; } @Override public ObjectQueryServicePrx getQTService() throws VCIError { return QTClient.getService(); } }