Windchill二次开发,IBA相关操作工具类

/**
  * 批量设置IBA属性
  * @param doc 文档对象
  * @param ibas iba集合,key为属性名,Value为属性值
  * @throws WTException
  */    
public static void setIBAValue(WTDocument doc, Map<String, Object> ibas) throws WTException{
        if (ibas != null && !ibas.isEmpty()) {
            LWCNormalizedObject lwcObject = new LWCNormalizedObject(doc, null, SessionHelper.getLocale(),new UpdateOperationIdentifier());
            Iterator<String> keyIt = ibas.keySet().iterator();
            String key = null;
            lwcObject.load(ibas.keySet());
            while (keyIt.hasNext()) {
                key = keyIt.next();
                lwcObject.set(key, ibas.get(key));
            }
            
            lwcObject.apply();
        }
    }

/**
	 * 根据类型、IBA属性查找文档
	 * @param docType 文档类型
	 * @param ibaName iba属性名
	 * @param ibaValue iba属性值
	 * @return 文档对象
	 * @throws WTException
	 */
	public static List<WTDocument> getDocumentsByIba(String docType,String ibaName,String ibaValue) throws WTException {
		List<WTDocument> docList = new ArrayList<WTDocument>();
		Hashtable<Object, Object> iba = new Hashtable<>();
		iba.put(ibaName, ibaValue);
		QuerySpec qs = new QuerySpec(WTDocument.class);
		qs.setAdvancedQueryEnabled(true);
		int indexDoc = qs.addClassList(WTDocument.class, true);
		int indexDocMaster = qs.addClassList(WTDocumentMaster.class, false);
		int indextype = qs.addClassList(WTTypeDefinition.class, false);
		int indextypeMaster = qs.addClassList(WTTypeDefinitionMaster.class,false);
		
		SearchCondition docLatest = new SearchCondition(WTDocument.class,WTDocument.LATEST_ITERATION, SearchCondition.IS_TRUE, true);
		qs.appendWhere(docLatest, new int[] { indexDoc });
		qs.appendAnd();

		SearchCondition scdoc = new SearchCondition(WTDocument.class,"masterReference.key.id", WTDocumentMaster.class,"thePersistInfo.theObjectIdentifier.id");
		qs.appendWhere(scdoc, new int[] { indexDoc, indexDocMaster });
		qs.appendAnd();

		SearchCondition scLink = new SearchCondition(WTDocument.class,"typeDefinitionReference.key.id", WTTypeDefinition.class,"thePersistInfo.theObjectIdentifier.id");
		qs.appendWhere(scLink, new int[] { indexDoc, indextype });
		qs.appendAnd();

		SearchCondition scepm = new SearchCondition(WTTypeDefinitionMaster.class,"thePersistInfo.theObjectIdentifier.id",WTTypeDefinition.class, "masterReference.key.id");
		qs.appendWhere(scepm, new int[] { indextypeMaster, indextype });
		qs.appendAnd();

		SearchCondition scMast = new SearchCondition(WTTypeDefinitionMaster.class,WTTypeDefinitionMaster.INT_HID, SearchCondition.EQUAL, docType);
		qs.appendWhere(scMast, new int[] { indextypeMaster });
		qs.appendAnd();

		SearchCondition scMastDelete = new SearchCondition(WTTypeDefinitionMaster.class,WTTypeDefinitionMaster.DELETED_ID, SearchCondition.IS_NULL, true);
		qs.appendWhere(scMastDelete, new int[] { indextypeMaster });
		
		addIBASearchCondition(WTDocument.class, qs, iba);
		QueryResult result = PersistenceHelper.manager.find(qs);
		while(result.hasMoreElements()) {
			Object obj = result.nextElement();
			if (obj instanceof Object[]) {
				docList.add((WTDocument)((Object[]) obj)[0]);
			} else {
				docList.add((WTDocument)obj);
			}
		}
		return docList;
	}
	
	 /**
	  * 添加iba属性搜索条件
     * @param ibaHolderClass 查询目标类型
     * @param qs 查询语句
     * @param htIBAS iba属性集合 key位属性名,value位属性值
     * @throws QueryException
     */
	public static void addIBASearchCondition(Class ibaHolderClass, QuerySpec qs, Hashtable htIBAS) throws QueryException {
        Enumeration eIBA = htIBAS.keys();
        while (eIBA.hasMoreElements()) {
            int ibaStringDefinitionIndex = qs.appendClassList(StringDefinition.class, false);
            int iIndex_StringValue = qs.appendClassList(StringValue.class, false);

            String strIBA_Name = (String) eIBA.nextElement();
            String strIBA_Value = (String) htIBAS.get(strIBA_Name);

            logger.debug("IBA_Name:" + strIBA_Name + "====>IBA_Value:" + strIBA_Value);

            ClassAttribute caValue = new ClassAttribute(StringValue.class, StringValue.VALUE);
            SQLFunction upperFunction = new SQLFunction("UPPER", caValue);
            String strOP = SearchCondition.EQUAL;
            if (strIBA_Value != null && (strIBA_Value.indexOf('*') != -1 || strIBA_Value.indexOf('%') != -1)) {
                strOP = SearchCondition.LIKE;
            }
            SearchCondition scStringValueValue = new SearchCondition(upperFunction, strOP, new ConstantExpression(new String(strIBA_Value).toUpperCase()));
            SearchCondition scStringDefinitionName = new SearchCondition(StringDefinition.class, StringDefinition.NAME, SearchCondition.EQUAL, strIBA_Name);
            SearchCondition scJoinStringValueStringDefinition = new SearchCondition(StringValue.class, "definitionReference.key.id", StringDefinition.class, WTAttributeNameIfc.ID_NAME);
            SearchCondition scStringValueDoc = new SearchCondition(StringValue.class, "theIBAHolderReference.key.id", ibaHolderClass, WTAttributeNameIfc.ID_NAME);

            if (qs.getConditionCount() > 0) {
                qs.appendAnd();
            }
            qs.appendWhere(scStringValueValue, new int[] { iIndex_StringValue });
            qs.appendAnd();
            int iIBAHolderIndex = qs.getFromClause().getPosition(ibaHolderClass);
            qs.appendWhere(scStringValueDoc, new int[] { iIndex_StringValue, iIBAHolderIndex });
            qs.appendAnd();
            qs.appendWhere(scJoinStringValueStringDefinition, new int[] { iIndex_StringValue, ibaStringDefinitionIndex });
            qs.appendAnd();
            qs.appendWhere(scStringDefinitionName, new int[] { ibaStringDefinitionIndex });
        }
    }

/**
     * 设置String类型iba属性
     * @param obj 目标对象
     * @param ibaName iba属性名称
     * @param newValue iba属性值
     * @throws WTException
     */
    public static void setIBAStringValue(WTObject obj, String ibaName, String newValue) throws WTException {
        String ibaClass = "wt.iba.definition.StringDefinition";

        if (obj instanceof IBAHolder) {
            IBAHolder ibaHolder = (IBAHolder) obj;
            DefaultAttributeContainer defaultattributecontainer = getContainer(ibaHolder);
            if (defaultattributecontainer == null) {
                defaultattributecontainer = new DefaultAttributeContainer();
                ibaHolder.setAttributeContainer(defaultattributecontainer);
            }
            StringValueDefaultView abstractvaluedefaultview = (StringValueDefaultView) getIBAValueView(
                    defaultattributecontainer, ibaName, ibaClass);
            if (abstractvaluedefaultview != null) {
                try {
                    abstractvaluedefaultview.setValue(newValue);
                } catch (WTPropertyVetoException e) {
                    logger.error(e.getLocalizedMessage(), e);
                    throw new WTException(e);
                }
                defaultattributecontainer.updateAttributeValue(abstractvaluedefaultview);
            } else {
                AttributeDefDefaultView attributedefdefaultview = getAttributeDefinition(ibaName, false);
                StringValueDefaultView abstractvaluedefaultview1 = new StringValueDefaultView(
                        (StringDefView) attributedefdefaultview, newValue);
                defaultattributecontainer.addAttributeValue(abstractvaluedefaultview1);
            }
            ibaHolder.setAttributeContainer(defaultattributecontainer);
            StandardIBAValueService.theIBAValueDBService.updateAttributeContainer(ibaHolder, null, null, null);
            try {
                ibaHolder = IBAValueHelper.service.refreshAttributeContainer(ibaHolder, "CSM", null, null);
            } catch (RemoteException e) {
                logger.error(e.getLocalizedMessage(), e);
                throw new WTException(e);
            }
        }
    }

/**
     * 获取IBA属性值
     * @param holder 目标对象
     * @param ibaName iba属性名称
     * @return iba属性值
     * @throws WTException
     */
    public static String getIBAValue(IBAHolder holder, String ibaName) throws WTException {
        AttributeDefDefaultView addv = null;
        try {
            addv = IBADefinitionHelper.service.getAttributeDefDefaultViewByPath(ibaName);
        } catch (RemoteException e) {
            logger.error(e.getLocalizedMessage(), e);
            throw new WTException(e);
        }
        if (addv == null) {
            throw new WTException("undefined iba name :" + ibaName);
        }
        long ibaDefId = addv.getObjectID().getId();

        QuerySpec qs = new QuerySpec(StringValue.class);
        qs.appendWhere(new SearchCondition(StringValue.class,
                AbstractValue.IBAHOLDER_REFERENCE + "." + ObjectReference.KEY + "." + ObjectIdentifier.ID,
                SearchCondition.EQUAL,
                PersistenceHelper.getObjectIdentifier((Persistable) holder).getId()), new int[] { 0 });
        qs.appendAnd();
        qs.appendWhere(new SearchCondition(StringValue.class, StringValue.DEFINITION_REFERENCE + "."
                + ObjectReference.KEY
                + "." + ObjectIdentifier.ID, SearchCondition.EQUAL, ibaDefId), new int[] { 0 });

        QueryResult qr = PersistenceHelper.manager.find((StatementSpec) qs);
        StringValue sv = null;
        if (qr.hasMoreElements()) {
            sv = (StringValue) qr.nextElement();
        }
        return sv == null ? null : sv.getValue();
    }

Windchill是PTC公司一款用于产品生命周期管理(PLM)的软件平台。二次开发是指在Windchill平台上使用软件开发技术进行定制化开发,以满足企业特定的业务需求。 想要进行Windchill二次开发入门,首先需要掌握Java编程语言。JavaWindchill平台主要的开发语言,熟练掌握Java编程可以帮助我们在Windchill平台上进行二次开发。 其次,我们需要熟悉Windchill平台的架构和数据模型。了解Windchill的架构可以帮助我们理解软件的运行机制,以及如何通过二次开发来扩展和定制Windchill的功能。同时,熟悉Windchill的数据模型可以帮助我们理解数据在Windchill平台中的组织和管理方式,为二次开发提供基础。 在掌握基本的Java编程和Windchill平台的知识后,我们可以开始进行实际的二次开发工作。在二次开发中,我们可以利用Windchill提供的API(应用程序接口)来访问和操作Windchill平台的各种功能和数据。通过API,我们可以实现自定义的业务逻辑和界面,满足企业特定的需求。 最后,为了更好地进行Windchill二次开发,我们还可以参考相关的文档和教程。PTC公司为Windchill开发者提供了丰富的文档资源,包括开发手册、API文档等,可以帮助我们更好地理解Windchill二次开发方式和最佳实践。 总之,想要进行Windchill二次开发入门,需要掌握Java编程语言,熟悉Windchill平台的架构和数据模型,并借助Windchill提供的API进行实际的开发工作。不断学习和实践,我们可以逐渐提升自己的二次开发能力,并为企业定制出更符合需求的Windchill应用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值