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

Community Tip - You can change your system assigned username to something more personal in your community settings. X

plt/pdf/ed/etc download/export to folder code

cadjett
1-Newbie

plt/pdf/ed/etc download/export to folder code

Hello All,

I cant findthe old thread where I originally asked for hints/help with this, so I am adding new thread.

I asked for way/code/etc to download plt/pdf/ed (applicationdata) to a folder. I have generated code that works for me.

Its not pretty, probably bad java, but when your not one of the gurus, whatever works is good...ha..ha

The main method was: ContentServerHelper.service.writeContentStream(data, path);

I had major issues with RemoteMethodService & this line worked: rms.invoke("FindEpmNumbered", "ext.epmDown_1C", null, aclass, aobj);

I got much help from sid & that was very helpful & appreciated.
I always borrow good code from Antonio (from previous code sent or posted), so I'm very much appreciative.

But the command line is: java ext.epmDown_1C <content type="> <path-where-file-should be=" saved="> <number search=" string=">

It is named epmDown because where I use it elsewhere, it also dumps a .dat file including epmdoc info (attributes name/values, etc)

Typical command line would be: java ext.epmDown_1CpdfC:\\temp 205%

This will get you all pdf's for all 205% drawings in Released state. You can of course change state requirement. Also do plt/ed/etc

On C:\\temp (use \\ instead of \ for separator) & use % instead of * for wildcard..

205% gets you 205001.drw, 2005002.drw, etc

I am posting the code below, because I think all snippets should be posted & maybe also attached, because code is found
best through searches. If the methods are not in the postings, we can search for it in attached code. But I will uttach it also.

I am posting the code in an odd fashion. I am using /**/ instead of tabs, because the tabs get lost in the posting & make
it hard for rookies like me to see what the code is doing. It works fine when compiled with the /**/, but If you copy/paste, you
can always find/replace /**/ with tabs. I dont compile with /**/ in code, but I figure it will help here. Simple find/replace works.

The code is ugly, but itis dumping the content objects, so I'm Happy. The only problem I have is that with the RemoteMethodServer
invoke, I dont get any System.out.println output. If anybody can look at code & see why, I would appreciate a post here or email.

Let me know where the code can be written better &/or add functionality.

Thanks
Lawrence Jett
cadjett@aol.com,datajett@aol.com


package ext;

import java.util.*;
import java.rmi.RemoteException;
import java.net.URL;
import java.beans.PropertyVetoException;
import java.io.*;

import wt.util.*;
import wt.fc.*;
import wt.vc.*;
import wt.query.*;
import wt.part.*;
import wt.epm.*;
import wt.httpgw.GatewayAuthenticator;
import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;

import wt.content.*;
import wt.representation.*;

import wt.fv.StandardFvService;

import wt.lifecycle.*;
import wt.lifecycle.State;

import com.ptc.wvs.common.util.WVSProperties;
import com.ptc.wvs.server.util.PublishUtils;
import com.ptc.wvs.server.util.WVSContentHelper;

import wt.security.FileAccess;
import wt.security.WTSecurityException;

import wt.services.ManagerService;
import wt.services.ManagerServiceFactory;

import wt.session.SessionHelper;
import wt.session.SessionManager;

public class epmDown_1C implements RemoteAccess {

/**/public static Enumeration FindEpmNumbered(String conTyp, String dlLoc, String drwNo) throws WTException, WTPropertyVetoException {
/**//**/QuerySpec qs = new QuerySpec(EPMDocument.class);
/**//**/qs.appendWhere(new SearchCondition(EPMDocument.class,EPMDocument.NUMBER,SearchCondition.LIKE, drwNo));
/**//**/qs.appendAnd();
/**//**/qs.appendWhere(new SearchCondition(EPMDocument.class, "iterationInfo.latest", "TRUE"));
/**//**/final QueryResult qr = PersistenceHelper.manager.find(qs);

/**//**/while (qr.hasMoreElements()) {
/**//**//**/EPMDocument epmm = (EPMDocument)qr.nextElement();

/**//**//**/if (epmm.getNumber().endsWith(".drw") ) {
/**//**//**//**/LifeCycleManaged LMObject = (LifeCycleManaged)epmm;
/**//**//**//**/String StStg = (String)LMObject.getLifeCycleState().toString();

/**//**//**//**/if (StStg.compareTo("RELEASED") == 0) {
/**//**//**//**//**/System.out.println( "\nEPMDoc - Number: " + epmm.getNumber() + " - Name: " + epmm.getName()+ " - CadName: " + epmm.getCADName() );
/**//**//**//**//**/System.out.println( "EPMDocument " + epmm.getNumber() + " -Version: " + epmm.getVersionIdentifier().getValue() + " - Iteration:"+epmm.getIterationIdentifier().getValue());
/**//**//**//**//**/System.out.println( "Life Cycle State: "+StStg);

/**//**//**//**//**/try {
/**//**//**//**//**//**/Representation defaultRep=RepresentationHelper.service.getDefaultRepresentation(epmm);
/**//**//**//**//**//**/ContentHolder holder=ContentHelper.service.getContents(defaultRep);
/**//**//**//**//**//**/Vector contents=ContentHelper.getContentListAll(holder);
/**//**//**//**//**//**/ApplicationData data=null;

/**//**//**//**//**//**/for (int i=0;i<contents.size();i++)<br/>/**//**//**//**//**//**/{
/**//**//**//**//**//**//**/if (contents.get(i) instanceof ApplicationData)
/**//**//**//**//**//**//**/{
/**//**//**//**//**//**//**//**/data=(ApplicationData)contents.get(i);

/**//**//**//**//**//**//**//**/if (data!=null && data.getFileName().endsWith(conTyp))
/**//**//**//**//**//**//**//**/{
/**//**//**//**//**//**//**//**//**/String path = dlLoc+"\\"+data.getFileName();
/**//**//**//**//**//**//**//**//**/ContentServerHelper.service.writeContentStream(data, path);
/**//**//**//**//**//**//**//**//**/break;
/**//**//**//**//**//**//**//**/}
/**//**//**//**//**//**//**/}
/**//**//**//**//**//**/}

/**//**//**//**//**/}
/**//**//**//**//**/catch(Exception exception)
/**//**//**//**//**/{
/**//**//**//**//**//**/exception.printStackTrace();
/**//**//**//**//**/}
/**//**//**//**//**/queCnt++;
/**//**//**//**/}
/**//**//**/}
/**//**/}

/**//**/return new Enumeration() {
/**//**//**/public boolean hasMoreElements() {
/**//**//**//**/return qr.hasMoreElements();
/**//**//**/}
/**//**//**/public Object nextElement() throws NoSuchElementException {
/**//**//**//**/return ((Persistable[])qr.nextElement());
/**//**//**/}
/**//**/};
/**/}

/**/public static void main(String[] args) {
/**//**/if(args.length < 3)
/**//**/{
/**//**//**/System.out.println("Usage: windchill epmDown <content type="> <path-where-file-should be=" saved="> <number search=" string=">");
/**//**//**/System.exit(0);
/**//**/} else
/**//**/{
/**//**//**/try {
/**//**//**//**/RemoteMethodServer rms = RemoteMethodServer.getDefault();
/**//**//**//**/GatewayAuthenticator auth = new GatewayAuthenticator();
/**//**//**//**/auth.setRemoteUser("wcadmin");
/**//**//**//**/rms.setAuthenticator(auth);

/**//**//**//**/String conTyp = args[0];
/**//**//**//**/String dlLoc = args[1];
/**//**//**//**/String drwNo = args[2];

/**//**//**//**/Class aclass[] = new Class[3];
/**//**//**//**/aclass[0] = java.lang.String.class;
/**//**//**//**/aclass[1] = java.lang.String.class;
/**//**//**//**/aclass[2] = java.lang.String.class;

/**//**//**//**/Object aobj[] = { conTyp, dlLoc, drwNo };

/**//**//**//**/try {
/**//**//**//**//**/rms.invoke("FindEpmNumbered", "ext.epmDown_1C", null, aclass, aobj);

/**//**//**//**//**/Enumeration e = FindEpmNumbered(conTyp,dlLoc,drwNo);
/**//**//**//**//**/while (e.hasMoreElements()) {
/**//**//**//**//**//**/System.out.println(((EPMDocument)e.nextElement()).getIdentity());
/**//**//**//**//**/}

/**//**//**//**//**/System.out.println(queCnt+" Objects Queried.");
/**//**//**//**/}
/**//**//**//**/catch (WTException wtee) {
/**//**//**//**//**/wtee.printStackTrace();
/**//**//**//**/}
/**//**//**//**/catch (WTPropertyVetoException wtpe) {
/**//**//**//**//**/wtpe.printStackTrace();
/**//**//**//**/}
/**//**//**//**/finally {
/**//**//**//**//**/System.exit(0);
/**//**//**//**/}
/**//**//**//**/System.exit(0);
/**//**//**/}
/**//**//**/catch(Exception exceptionMain)
/**//**//**/{
/**//**//**//**/System.out.println("Exception in Main: "+exceptionMain);
/**//**//**//**/exceptionMain.printStackTrace();
/**//**//**/}
/**//**/}
/**/}
/**/static int queCnt=0;
}

2 REPLIES 2

By the way, the code was tested & worked on wc7,8,9 & worked in each with minor adjustments.

L Jett

I'm Back,

Previously I mentioned code that obtained all proe params - wc attributes & associated values (for epmdocs).

I originally hard coded an array of attributes to gather values for. Now I found/generated the code to find all attributes
& associated values with in each epmdoc in search/query.

This one beat me up for awhile & it feels good to get it to work:

The command line is:

java ext.attrList d:\\temp 1000%>attrList_1000_01.txt

2 args: 1) download of dat file location 2) epmdoc search string (% for wildcard)

I did also place the /**/ below instead of tabs, to allow forbetter viewing (I think). Just find/replace /**/ with tabs.

I also attached the code with out the /**/

L Jett
cadjett@aol.com,datajett@aol.com

Top Tags