cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

How to get (lifecycle)state of a WTDocumentMaster object?

ash
10-Marble
10-Marble

How to get (lifecycle)state of a WTDocumentMaster object?

There is a BOM structure. The condition is that before a child is not at its RELEASED state, Parent cannot be released.

I have used  wt.doc.WTDocumentHelper.service.getUsesWTDocumentMasters() to get the child document.

I want to get the state of the child document. SO I used,

                              WTDocumentMaster childPart = (WTDocumentMaster) childInfo;

                               wt.lifecycle.State childState = ((_LifeCycleManaged) childPart).getLifeCycleState();


ERROR is -> wt.doc.WTDocumentMaster cannot be cast to wt.lifecycle._LifeCycleManaged


I cannot get the state of the object. The above function does not work for WTDocumentMaster. Neither does object.getState().

How should I fetch the state of the object??

3 REPLIES 3
MatthewKnight
12-Amethyst
(To:ash)

I haven't looked at the vc or lifecycle packages in a while, so I'm sure there's a better way, but the comparator was fun to write.

// get your master

final WTDocumentMaster master = (WTDocumentMaster)new ReferenceFactory().getReference("xxxxxxxx").getObject();

// add latest iteration of each version to list

final List<WTDocument> list = new ArrayList<>();

final QueryResult versions = VersionControlHelper.service.allVersionsOf(master);

while(versions.hasMoreElements()) {

  list.add((WTDocument)versions.nextElement());

}

// sort list, latest version first

Collections.sort(list,new Comparator<WTDocument>() {

  @Override

  public int compare(final WTDocument o1,final WTDocument o2) {

  try {

  final MultilevelSeries o1Series = VersionControlHelper.getVersionIdentifierSeries(o1);

  final MultilevelSeries o2Series = VersionControlHelper.getVersionIdentifierSeries(o2);

  if(o1Series.equals(o2Series)) {

  return 0;

  }

  if(o1Series.greaterThan(o2Series)) {

  return 1;

  }

  return -1;

  } catch(final VersionControlException e) {

  // it's up to you

  return 0;

  }

  }

});

// you're done

final WTDocument latest = list.get(0);

final State state = latest.getLifeCycleState();

It helped. Thanks!

Just a quick note, if someone else comes across this.

 

 VersionControlHelper.service.allVersionsOf(master) will return an ordered list from newest to oldest. There should be no need to run a sort function on the results to get the latest, as it will be the first entry in the query result. From the API:

 

Finds all of the versions of the given master. The result is an ordered list of versions (i.e., latest iterations) from the most recent one to the first one created, e.g. (B, A). 

 

Announcements

Top Tags