1

I have a WTPart object and it have some Describe link(as WTDocument) associated with it.Now I need to revise the describe link through code.

Following is the code I have tried so far

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);

        }
    }

This code is revising only the WTDocument object which is linked as Describelink but not revising the Describelink. If I pass the Describe link object directly like this

localRevisionControlled=(RevisionControlled) VersionControlHelper.service.newVersion((Versioned)localPartlink);

means I'm getting error message like following

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)

I don't know how to solve this issue but I need to revise the Part describelink by code.Suggest me the API which is needed for this or some example code snippet would be useful for me.

4

2 に答える 2

1

WTPartDescribeLinkの一部のプロパティを更新する必要がある場合は、(WTDocumentではなく)新しいバージョンのWTPartを作成する必要があります。
次のコードで実行できます。

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トランザクションで囲むために、チェックアウト/チェックインを実行する方がよい場合もあります。

于 2013-03-12T07:52:52.783 に答える
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 ");

        }

上記のコードは正常に動作するようになりました。

于 2013-03-20T10:44:22.593 に答える