javaptc-windchill

How to revise WTPartDescribeLink?


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.


Solution

  • According to the answer given above by @Julien Boulay ,I have created a method which query the the document object and then revise that document after I have created a new link with my part.

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

    The above code is now works fine.