2

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.

Vignesh Vino
  • 1,242
  • 4
  • 25
  • 50
  • 1
    As it is raised in the ClassCastException, WTPartDescribeLink can not be versioned. Versioned object are WTPart, WTDocument, EPMDocument, but any link object. If you want to update WTPartDescribeLink, you have to create a new version of WTPart (that is link holder). – Julien Boulay Mar 12 '13 at 07:37

2 Answers2

2

If you need to update some properties on WTPartDescribeLink, then you should create a new version of WTPart (and not WTDocument).
It can be done with the following code :

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

It might also be better to do a check-out/check-in in order to create a new iteration of the WTPart and to surround the operation with windchill transaction

Julien Boulay
  • 1,164
  • 7
  • 15
  • :The above code gives me query result as 0 since the revision is not saved there.Also we need to check-out that part to iterate. – Vignesh Vino Mar 12 '13 at 09:36
  • I have a windchill service that will capture the revision of WTPart and my requirement is I need that partDescribeLink associated with that part also gets revised.I'm not supposed to check-out that part with code – Vignesh Vino Mar 12 '13 at 09:45
  • 1
    As I said in my previous comment, partDescribeLink can not be revised. Once your WTPart is revised, partDescribeLink is automatically reconducted on the new WTPart version. Revise partDescribeLink is not a requirement, because a link can not get a version ! What do you want to do exactly ? – Julien Boulay Mar 14 '13 at 14:49
0

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.

Vignesh Vino
  • 1,242
  • 4
  • 25
  • 50