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