Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
I am trying load a wtpart into windchill through API's and i would like to know how to set the lifecycle state of the part to a specific state.
Solved! Go to Solution.
Hey @RandyJones ,your solution is right , but we have to first store the new part which we created and the change its life cycle state.
@aashishramchand wrote:
I am trying load a wtpart into windchill through API's and i would like to know how to set the lifecycle state of the part to a specific state.
The LifeCycleHelper class is used for this. eg
String myState = "PROTOTYPE";
WTPart myPart = <already defined>;
LifeCycleHelper.service.setLifeCycleState((LifeCycleManaged) myPart, State.toState(myState));
I tried that and getting this error.
Exception in thread "main" (wt.fc.fcResource/0) wt.util.WTException: The operation: "setLifeCycleState" failed.
Nested exception is: wt.util.WTRemoteException: Unable to invoke remote method; nested exception is:
java.rmi.ServerRuntimeException: Server exception; nested exception is:
java.lang.NullPointerException
at wt.method.RemoteMethodServer.invoke(RemoteMethodServer.java:788)
at wt.services.ServiceFactory$ClientInvocationHandler.invoke(ServiceFactory.java:349)
at com.sun.proxy.$Proxy13.setLifeCycleState(Unknown Source)
at ext.ttl.LoadPart_test.injectWTPart(LoadPart_test.java:118)
at ext.ttl.LoadPart_test.main(LoadPart_test.java:77)
Caused by: java.lang.NullPointerException
... 5 more
@aashishramchand wrote:
I tried that and getting this error.
Exception in thread "main" (wt.fc.fcResource/0) wt.util.WTException: The operation: "setLifeCycleState" failed.
Nested exception is: wt.util.WTRemoteException: Unable to invoke remote method; nested exception is:
java.rmi.ServerRuntimeException: Server exception; nested exception is:
java.lang.NullPointerException
at wt.method.RemoteMethodServer.invoke(RemoteMethodServer.java:788)
at wt.services.ServiceFactory$ClientInvocationHandler.invoke(ServiceFactory.java:349)
at com.sun.proxy.$Proxy13.setLifeCycleState(Unknown Source)
at ext.ttl.LoadPart_test.injectWTPart(LoadPart_test.java:118)
at ext.ttl.LoadPart_test.main(LoadPart_test.java:77)
Caused by: java.lang.NullPointerException
... 5 more
This is an issue with your setup. You apparently are not running this on Windchill itself eg: jsp page, workflow, etc.
See this article for running code from a java client:
I executed the code from the windchill shell and im getting the same error as before "Illegal arguments Exception".
Hi @aashishramchand,
Can you try following and let me know if that helps!
package ext;
public class TestLifeCycleState implements wt.method.RemoteAccess {
public static void main(String[] args) throws java.rmi.RemoteException, java.lang.reflect.InvocationTargetException {
wt.method.RemoteMethodServer rms = wt.method.RemoteMethodServer.getDefault();
rms.invoke("setState", "ext.TestLifeCycleState", null, null, null);
}
public static void setState ()
{
//Your code
//String myState = "PROTOTYPE";
//WTPart myPart = <already defined>;
//LifeCycleHelper.service.setLifeCycleState((LifeCycleManaged) myPart, State.toState(myState));
}
}
Regards,
Bhushan
@aashishramchand Can you share MS logs and also the code in Text format. Also, can you elaborate on your requirement are you trying to create a new object with non-initial state or just trying to set state for an existing already persisted object?
Regards,
Bhushan
@BhushanNehe yes, I am trying to create a new object with non-initial lifecycle state
public class Tester implements RemoteAccess {
public static void main(String[] args) {
RemoteMethodServer rms = RemoteMethodServer.getDefault();
rms.setUserName("username");
rms.setPassword("password");
try {
rms.invoke("setState", Tester.class.getName(), null, null, null);
} catch (RemoteException | InvocationTargetException e) {
e.printStackTrace();
}
}
public static void setState() throws WTException, WTPropertyVetoException {
String name = "TestPart1"; // Name
String number = "00000055"; // Number
String lifeCycleName = "Basic"; // Lifecycle name
String container_path = "container path";
String folder_path = "/Default/Design"; // Folder path
String PPAPRevision = "20";
WTPart newPart = WTPart.newWTPart();
newPart.setName(name);
newPart.setNumber(number);
WTContainerRef containerRef = WTContainerHelper.service.getByPath(container_path);
newPart.setContainerReference(containerRef);
Folder folder = FolderHelper.service.getFolder(folder_path, containerRef);
FolderHelper.assignLocation(newPart, folder);
LifeCycleTemplate lct = LifeCycleHelper.service.getLifeCycleTemplate(lifeCycleName,
newPart.getContainerReference());
newPart = (WTPart) LifeCycleHelper.setLifeCycle(newPart, lct);
String myState = "RELEASED";
LifeCycleHelper.service.setLifeCycleState((wt.lifecycle.LifeCycleManaged) newPart, State.toState(myState));
newPart = (WTPart) wt.fc.PersistenceHelper.manager.store(newPart);
}
}
here are the MS logs:
//--------------------------------------------------------------------------------------
2018-07-23 19:02:49,205 ERROR [RMI TCP Connection(11)-172.28.77.125] wt.method.MethodContextMonitor.contexts.rmi wcadmin - 2018-07-23 13:32:48.891 +0000, 1br5x19;jjyb9vd5;40236;rc07vq;1, -, -, -, wcadmin, 172.28.77.125, ext.ttl.Tester, setState, , 0, 27, 0.017394686, 26, 0.128692733, 0.1248008, 0.31294933 java.lang.IllegalArgumentException: null cache key at wt.pom.RefreshCache.find(RefreshCache.java:283) at wt.pom.RefreshCache.containskey(RefreshCache.java:119) at wt.pom.TransactionManager.containOidInCache(TransactionManager.java:907) at wt.pom.PersistentObjectManager.lock(PersistentObjectManager.java:919) at wt.fc.StandardPersistenceManager.lock(StandardPersistenceManager.java:1335) at wt.lifecycle.StandardLifeCycleService.doSetState(StandardLifeCycleService.java:10350) at wt.lifecycle.StandardLifeCycleService.doSetState(StandardLifeCycleService.java:7683) at wt.lifecycle.StandardLifeCycleService.setState(StandardLifeCycleService.java:7490) at wt.lifecycle.StandardLifeCycleService.setLifeCycleState(StandardLifeCycleService.java:2734) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at wt.services.ServiceFactory$ServerInvocationHandler.invoke(ServiceFactory.java:399) at com.sun.proxy.$Proxy143.setLifeCycleState(Unknown Source) at ext.ttl.Tester.setState(Tester.java:79) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at wt.method.MethodResultWriter.writeExternal(MethodResultWriter.java:152) at wt.method.MethodResult.writeExternal(MethodResult.java:228) at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1455) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1429) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347) at sun.rmi.server.UnicastRef.marshalValue(UnicastRef.java:293) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:332) at sun.rmi.transport.Transport$1.run(Transport.java:177) at sun.rmi.transport.Transport$1.run(Transport.java:174) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:173) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744)
//------------------------------------------------------------------------------------------------------------------------------------------
here is the error im getting when i run the code on windchill shell:
wt.util.WTRemoteException: Unable to invoke remote method; nested exception is:
java.rmi.ServerRuntimeException: Server exception; nested exception is:
java.lang.IllegalArgumentException: null cache key
at wt.method.RemoteMethodServer.invoke(RemoteMethodServer.java:788)
at ext.ttl.Tester.main(Tester.java:48)
Caused by: java.lang.IllegalArgumentException: null cache key
... 2 more
Hey @RandyJones ,your solution is right , but we have to first store the new part which we created and the change its life cycle state.
