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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Facing issue while getting Business Attribute of a WTpart by using NEW_VERSION event

vuchekar
9-Granite

Facing issue while getting Business Attribute of a WTpart by using NEW_VERSION event

Hi All,

My requirement -> fetch a Business Attributes of WTPart, just after the WTPart creation.

for this purpose, i am using this event " VersionControlServiceEvent.NEW_VERSION ".

i am able to get part Name,number, creator, timestamp etc here, but when i try to fetch Business Attributes, its gives value null, even there a business attribute present with valid values.

Here is My code, Please let me know where i am doing wrong ?

Any help will be great !!

1. VersionEventListenerAdapter.java

-------------------------------

package ext;

import wt.epm.EPMDocument;

import wt.events.KeyedEvent;

import wt.fc.PersistenceHelper;

import wt.fc.QueryResult;

import wt.fc.ReferenceFactory;

import wt.fc.WTReference;

import wt.part.WTPart;

import wt.query.QuerySpec;

import wt.query.SearchCondition;

import wt.services.ServiceEventListenerAdapter;

import wt.util.WTException;

import wt.util.WTPropertyVetoException;

import wt.vc.VersionControlServiceEvent;

public class VersionEventListenerAdapter extends ServiceEventListenerAdapter {

  public VersionEventListenerAdapter(String serviceId) {

     super(serviceId);

  }

  public void notifyVetoableEvent(Object event) throws WTException, WTPropertyVetoException {

     if (!(event instanceof KeyedEvent)) {

         return;

     }

     Object target = ((KeyedEvent) event).getEventTarget();

     Object eventType = ((KeyedEvent) event).getEventType();

    

     System.out.println("FROM @@@@@@@@@  Target >>>>> "+target);

     System.out.println("FROM @@@@@@@@@  eventType >>>>> "+eventType);

    

     ReferenceFactory refFactory = new ReferenceFactory();

  WTReference ref = refFactory.getReference(target.toString());

     if (eventType.equals(VersionControlServiceEvent.NEW_VERSION))

     {

        /** Call your business code here

            example : yourMethod(target);

         **/

      System.out.println(">>>>>>>> INSIDE EVENT TYPE >>>> ");

    

      if(target instanceof WTPart){

      WTPart wtp = (WTPart)ref.getObject();

    

      System.out.println("Name >> "+wtp.getName());

      System.out.println("Number >> "+wtp.getNumber());

      System.out.println("Created By >> "+wtp.getCreatorFullName());

      System.out.println("Creation Time >> "+wtp.getCreateTimestamp());

      System.out.println("Time >>> "+System.currentTimeMillis());

      System.out.println(" VERSION >> "+wtp.getVersionIdentifier().getValue()+"."+wtp.getIterationIdentifier().getValue());

      System.out.println("======= =================");

   

    

    

     // below code to fetch attribute GOB_WEIGHT

      com.ptc.core.lwc.server.LWCNormalizedObject obj = new com.ptc.core.lwc.server.LWCNormalizedObject(wtp, null,

             java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());

    

      obj.load("GOB_WEIGHT");

      java.lang.String string_value = (java.lang.String) obj.get("GOB_WEIGHT");

      System.out.println("Soft attibute value : " + string_value);

      }

     }

  }

  }

2. MStandardListenerService.java

package ext;

import wt.services.ManagerException;

import wt.services.StandardManager;

import wt.util.WTException;

import wt.vc.VersionControlServiceEvent;

public class MStandardListenerService extends StandardManager implements MListenerServiceInterface {

  private static final long serialVersionUID = 1L;

  protected synchronized void performStartupProcess() throws ManagerException {

     VersionEventListenerAdapter versionEventListenerAdapter = new VersionEventListenerAdapter(getName());

     getManagerService().addEventListener(versionEventListenerAdapter, VersionControlServiceEvent.generateEventKey(VersionControlServiceEvent.NEW_VERSION));

     getManagerService().addEventListener(versionEventListenerAdapter, VersionControlServiceEvent.generateEventKey(VersionControlServiceEvent.PRE_NEW_VERSION));

     getManagerService().addEventListener(versionEventListenerAdapter, VersionControlServiceEvent.generateEventKey(VersionControlServiceEvent.POST_INSERT_ITERATION));

     getManagerService().addEventListener(versionEventListenerAdapter, VersionControlServiceEvent.generateEventKey(VersionControlServiceEvent.POST_ROLLUP));

     getManagerService().addEventListener(versionEventListenerAdapter, VersionControlServiceEvent.generateEventKey(VersionControlServiceEvent.POST_SUPERSEDE));

    

  }

  public static MStandardListenerService newMStandardListenerService() throws WTException {

     MStandardListenerService instance = new MStandardListenerService();

     instance.initialize();

     return instance;

  }

}

Please check and suggest me.

Regards,

Vivek

1 ACCEPTED SOLUTION

Accepted Solutions
BhushanNehe
14-Alexandrite
(To:vuchekar)

Hi Vivek,

A quick test at my end shows the events are fired in following sequence. So when you listen to NEW_VERSION event the IBA's are not yet persisted in the database and hence the value is still NULL. Try POST_STORE event instead.

/wt.vc.VersionControlServiceEvent/NEW_VERSION   :: for object wt.part.WTPart

/wt.fc.PersistenceManagerEvent/INSERT :: for object wt.iba.value.StringValue

/wt.fc.PersistenceManagerEvent/POST_STORE :: for object wt.part.WTPart

Regards,

Bhushan

View solution in original post

2 REPLIES 2
BhushanNehe
14-Alexandrite
(To:vuchekar)

Hi Vivek,

A quick test at my end shows the events are fired in following sequence. So when you listen to NEW_VERSION event the IBA's are not yet persisted in the database and hence the value is still NULL. Try POST_STORE event instead.

/wt.vc.VersionControlServiceEvent/NEW_VERSION   :: for object wt.part.WTPart

/wt.fc.PersistenceManagerEvent/INSERT :: for object wt.iba.value.StringValue

/wt.fc.PersistenceManagerEvent/POST_STORE :: for object wt.part.WTPart

Regards,

Bhushan

Thanks, Bhushan.

By using POST_STORE  event, now i am able to get attributes on that part.

Thanks a lot.

Regards.

Vivek

Top Tags