Skip to main content
1-Visitor
January 11, 2017
Question

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

  • January 11, 2017
  • 1 reply
  • 2709 views

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??

1 reply

1-Visitor
January 11, 2017

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

ash1-VisitorAuthor
1-Visitor
January 12, 2017

It helped. Thanks!