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

how to identify WTPart being created using SAVE AS action ?

SOLVED
shetakesubhash7
Regular Member

how to identify WTPart being created using SAVE AS action ?

 
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: how to identify WTPart being created using SAVE AS action ?

Hi, you can listen to the event

PersistenceManagerEvent.PRE_STORE

and then look for the MadeFromLink objects like:

@Override
public void notifyVetoableMultiObjectEvent(Object obj) throws WTException {
if (((KeyedEvent) obj).getEventType().equals(PersistenceManagerEvent.PRE_STORE)) {
WTCollection wtCollection = (WTCollection) ((PersistenceManagerEvent) obj).getEventTarget();
WTCollection madeFromLinkCollection = wtCollection.subCollection(MadeFromLink.class, true);
if (!madeFromLinkCollection.isEmpty()) {
log.debug("madeFromLinkCollection.size() = {}", madeFromLinkCollection.size());
Iterator iterator = madeFromLinkCollection.persistableIterator();
while (iterator.hasNext()) {
MadeFromLink madeFromLink = (MadeFromLink) iterator.next();
Persistable targetPersistable = madeFromLink.getCopy();
Persistable sourcePersistable = madeFromLink.getRoleBObject();
...
}
}
}
}

 

View solution in original post

6 REPLIES 6

Re: how to identify WTPart being created using SAVE AS action ?

Not sure if there is a dedicated method for this.

If not, you can still navigate the link "wt.enterprise.MadeFromLink".

Florent ROUSSEL
www.4cad.ca

Re: how to identify WTPart being created using SAVE AS action ?

Thanks but seems its not working on 11.0 windchill version

Re: how to identify WTPart being created using SAVE AS action ?

It does work.

 

The following

 

PersistenceHelper.manager.navigate(myPart, "original", MadeFromLink.class, true) 

 

returns the part that has been used to create "myPart".

So if there is no element in the QueryResult, it means myPart hasn't been created from a save-as.

 

But maybe that's not what you're looking for, if so, then elaborate your need.

 

Florent ROUSSEL
www.4cad.ca

Re: how to identify WTPart being created using SAVE AS action ?

Well, need is to identify whether WTPart being created via SAVE AS action on Create Part action. this need to be identify while creating WTPart e.g. on listener level. Post that rest validation will applied. 

Currently am trying this on PersistenceManagerEvent.PRE_STORE listener service event.

 

 

tried your suggestion as well:

QueryResult qr=PersistenceHelper.manager.navigate( wtPart,"original", MadeFromLink.class, false);

this returns 0 elements. 

 

 

 

Re: how to identify WTPart being created using SAVE AS action ?

This makes sense as the PRE_STORE event is (as its name means) is raised prior anything is stored in the DB, therefore you won't find the link.

I would rather look into the EnterpriseServiceEvent.PRE_COPY or  VersionControlServiceEvent.NEW_VERSION or the PersistenceManagerEvent.INSERT events.

 

Or even implementing your own custom CopyWTPartDelegate

Florent ROUSSEL
www.4cad.ca

Re: how to identify WTPart being created using SAVE AS action ?

Hi, you can listen to the event

PersistenceManagerEvent.PRE_STORE

and then look for the MadeFromLink objects like:

@Override
public void notifyVetoableMultiObjectEvent(Object obj) throws WTException {
if (((KeyedEvent) obj).getEventType().equals(PersistenceManagerEvent.PRE_STORE)) {
WTCollection wtCollection = (WTCollection) ((PersistenceManagerEvent) obj).getEventTarget();
WTCollection madeFromLinkCollection = wtCollection.subCollection(MadeFromLink.class, true);
if (!madeFromLinkCollection.isEmpty()) {
log.debug("madeFromLinkCollection.size() = {}", madeFromLinkCollection.size());
Iterator iterator = madeFromLinkCollection.persistableIterator();
while (iterator.hasNext()) {
MadeFromLink madeFromLink = (MadeFromLink) iterator.next();
Persistable targetPersistable = madeFromLink.getCopy();
Persistable sourcePersistable = madeFromLink.getRoleBObject();
...
}
}
}
}

 

View solution in original post

Announcements