Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
I want to use API to download EPMDocumentMaster, see the code as below:
package com.cisco.whichen2;
import java.io.IOException;
import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.part.WTPart;
import wt.pds.StatementSpec;
import wt.pom.PersistenceException;
import wt.pom.Transaction;
import wt.query.QuerySpec;
import wt.util.WTException;
import wt.vc.config.LatestConfigSpec;
import wt.content.ApplicationData;
import wt.content.ContentHelper;
import wt.content.ContentItem;
import wt.content.ContentServerHelper;
import wt.content.FormatContentHolder;
import wt.epm.EPMDocument;
import wt.epm.EPMDocumentMaster;
import wt.fc.QueryResult;
import wt.query.SearchCondition;
import wt.fc.PersistenceHelper;
import wt.content.ContentServerHelper;
public class PartManager implements RemoteAccess{
public static void main(String[] args) throws Exception {
RemoteMethodServer rms=RemoteMethodServer.getDefault();
rms.setUserName("wcadmin");
rms.setPassword("wcadmin");
Class argTypes[]={String.class, String.class};
Object argValues[]={"29-8888-01.prt","C:\\temp\\"};
System.out.println(PartManager.class.getName());
rms.invoke("getEPM", PartManager.class.getName(), null, argTypes, argValues);
}
public static void getEPM (String epmName,String path) throws Exception{
Transaction tx=new Transaction();
tx.start();
EPMDocumentMaster cad = null;
ContentItem primaryContent=null;
if (epmName == null || epmName.trim().length()==0){
System.out.println();
}
QuerySpec qs= new QuerySpec(EPMDocumentMaster.class);
qs.appendWhere(new SearchCondition(EPMDocumentMaster.class,EPMDocumentMaster.NAME,SearchCondition.EQUAL,epmName) , new int[]{0,-1});
System.out.println(qs);
QueryResult qr = PersistenceHelper.manager.find((StatementSpec)qs);
System.out.println(qr.hasMoreElements());
while(qr.hasMoreElements()){
cad = (EPMDocumentMaster) qr.nextElement();
String fullName = path + cad.getCADName();
System.out.println("downloadFile>>>EMPDocumentMaster, writeContentStream:"+fullName);
EPMDocument latest = (EPMDocument) wt.vc.VersionControlHelper.service.allVersionsOf(cad).nextElement();
System.out.println("Get the latest version successful");
primaryContent=ContentHelper.getPrimary((FormatContentHolder)latest);
System.out.println("The primary content is:");
ContentServerHelper.service.writeContentStream((ApplicationData)primaryContent,fullName);
}
tx.commit();
}
}
The error information is:
com.cisco.whichen2.PartManager
Exception in thread "main" 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 com.cisco.whichen2.PartManager.main(PartManager.java:36)
Caused by: java.lang.NullPointerException
... 2 more
Who can help me?
Thanks.
White
Solved! Go to Solution.
Could you give more detail as to how you're testing this? If you're calling PartManager.main(args) from the Windchill server where the class lives, say in a .jsp file, it should work fine.
Well, I guess calling the function and getting the Remote Method Server code should work fine....I didn't actually look at the getEPM code, which isn't your problem at this point.
Could you give more detail as to how you're testing this? If you're calling PartManager.main(args) from the Windchill server where the class lives, say in a .jsp file, it should work fine.
Well, I guess calling the function and getting the Remote Method Server code should work fine....I didn't actually look at the getEPM code, which isn't your problem at this point.
Thanks a lot for your inspiring. My problem is resolved.
Can I ask one more question? I want get the part information in my workplace, when I select the part(show in picture), how can I get the part information by click customized button? I know I maybe need to use "NmCommandBean " and its method ".getSelectedOidForPopup()", but I don't how to use it, can you show me an example to use NmcommandBean class?
Best Regards.
White
White Chen wrote:
Thanks a lot for your inspiring. My problem is resolved.
Can I ask one more question? I want get the part information in my workplace, when I select the part(show in picture), how can I get the part information by click customized button? I know I maybe need to use "NmCommandBean " and its method ".getSelectedOidForPopup()", but I don't how to use it, can you show me an example to use NmcommandBean class?
Check out the following thread:
Re: How to get Object details from selected row via custom action on separate jsp page