我有一个WTPart对象,它有一些与之关联的Describe链接(作为WTDocument)。现在我需要通过代码修改describe链接。
以下是我到目前为止尝试过的代码
Vector localVector=new Vector();
QueryResult localQueryResult=WTPartHelper.service.getDescribedByWTDocuments(part,false);
System.out.println("size is "+localQueryResult.size());
if((localQueryResult!=null)&&(localQueryResult.hasMoreElements()))
{
while(localQueryResult.hasMoreElements())
{
WTObject localObject=(WTObject) localQueryResult.nextElement();
localVector.addElement(localObject);
}
}
if((localVector!=null)&&(localVector.size()>0))
{
for(int i=0;i<localVector.size();i++)
{
WTPartDescribeLink localPartlink=(WTPartDescribeLink) localVector.elementAt(i);
WTDocument localWTDocument=localPartlink.getDescribedBy();
System.out.println("values are "+localWTDocument.getNumber());
RevisionControlled localRevisionControlled=null;
localRevisionControlled=(RevisionControlled) VersionControlHelper.service.newVersion(localWTDocument);
localRevisionControlled=(RevisionControlled) PersistenceHelper.manager.save(localRevisionControlled);
}
}
此代码仅修改WTDocument对象,该对象链接为Describelink但未修改Describelink。 如果我像这样直接传递Describe链接对象
localRevisionControlled=(RevisionControlled) VersionControlHelper.service.newVersion((Versioned)localPartlink);
表示我收到如下错误消息
Exception in thread "main" java.lang.ClassCastException: wt.part.WTPartDescribeLink cannot be cast to wt.vc.Versioned
at ext.gt.test.CheckLink.getPartlink(CheckLink.java:100)
at ext.gt.test.CheckLink.searchPart(CheckLink.java:52)
at ext.gt.test.CheckLink.main(CheckLink.java:32)
我不知道如何解决这个问题,但我需要通过代码修改Part describeelink.Suggest me这个或一些示例代码片段对我来说非常有用。
答案 0 :(得分:1)
如果您需要更新WTPartDescribeLink上的某些属性,那么您应该创建一个新版本的WTPart(而不是WTDocument)。
可以使用以下代码完成:
part = VersionControlHelper.service.newVersion(part);
QueryResult qr =WTPartHelper.service.getDescribedByWTDocuments(part,false);
if(qr!=null)
{
while(qr.hasMoreElements())
{
WTPartDescribeLink link =(WTPartDescribeLink) localQueryResult.nextElement();
/** ...
Update some attributes on the link
... **/
link= PersistenceServerHelper.manager.save(link);
}
}
为了创建WTPart的新迭代并使用windchill事务包围操作,执行签出/签入也可能更好
答案 1 :(得分:0)
根据@Julien Boulay上面给出的答案,我创建了一个查询文档对象的方法,然后在我创建了一个新链接之后修改了该文档。
private WTPartDescribeLink getPartlink(WTPart target) throws WTException, WTPropertyVetoException {
WTDocument localWTDocument=null;
if(target==null)
return null;
QueryResult localQueryResult=WTPartHelper.service.getDescribedByWTDocuments(target, false);
ilogger.info("size of query result is "+localQueryResult.size());
if((localQueryResult!=null)&&(localQueryResult.hasMoreElements()))
{
while(localQueryResult.hasMoreElements())
{
WTObject localObject=(WTObject) localQueryResult.nextElement();
WTPartDescribeLink localPartlink=(WTPartDescribeLink) localObject;
localWTDocument=localPartlink.getDescribedBy();
}
}
WTDocument docm=(WTDocument) VersionControlHelper.service.allVersionsOf(localWTDocument).nextElement();
ilogger.info("values are "+docm.getNumber());
String version=docm.getVersionIdentifier().getValue();
String iteration=docm.getIterationIdentifier().getValue();
ilogger.info("Object passing with version and iteration of"+version+"."+iteration);
RevisionControlled localRevisionControlled=null;
localRevisionControlled=(RevisionControlled) VersionControlHelper.service.newVersion(docm);
localRevisionControlled=(RevisionControlled) PersistenceHelper.manager.save(localRevisionControlled);
createLink(target,docm);
return null;
}
private void createLink(WTPart spart, WTDocument localWTDocument) throws WTException {
WTPartDescribeLink link=WTPartDescribeLink.newWTPartDescribeLink(spart, localWTDocument);
PersistenceServerHelper.manager.insert(link);
ilogger.info("Link saved ");
}
上面的代码现在运行正常。