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