Quantcast
Channel: PTC Community : Unanswered Discussions - Windchill
Viewing all articles
Browse latest Browse all 3592

Downloading EPM documents

$
0
0

From 10.1 version the download option for EPM has been removed by PTC. Here i'm trying to add an action which will execute the 'download action' ,   kindly review the java code and see if thats enough

 

 

 

package ext;

 

 

import java.io.*;

import java.util.*;

import java.rmi.RemoteException;

import java.net.URL;

 

 

import wt.util.*;

import wt.content.*;

import wt.epm.*;

import wt.fc.*;

import wt.query.*;

import wt.representation.*;

 

 

import wt.method.RemoteAccess;

 

 

public class dlRep

          implements RemoteAccess, Serializable

{

          private static String extractContent(EPMDocument EPMDoc, String dlLoc, String conType)

          {

                    String rtnStg="NO Data Found (extractContent)";

                    try {

                              Representation defaultRep=RepresentationHelper.service.getDefaultRepresentation(EPMDoc);

 

 

                              if(defaultRep != null)

                              {

                                        ContentHolder holder=ContentHelper.service.getContents(defaultRep);

                                        Vector contents=ContentHelper.getContentListAll(holder);

                                        ApplicationData data=null;

 

 

                                        for (int i=0;i<contents.size();i++)

                                        {

                                                  if (contents.get(i) instanceof ApplicationData)

                                                  {

                                                            data=(ApplicationData)contents.get(i);

 

 

                                                            if (data!=null && data.getFileName().endsWith(conType))

                                                            {

                                                                      if (dlLoc.equals("C:\shared")) {

                                                                                URL url = data.getViewContentURL(holder);

                                                                                String urlStg = data.getFileName()+"|C:\shared|"+url.toString();

                                                                                String mtData = ContentServerHelper.service.getMimeType(data);

                                                                                System.out.println("\ndata MimeType: "+mtData+"\n");

                                                                                System.out.println("\nurlStg (getViewContentURL): "+urlStg+"\n");

                                                                                return urlStg;

                                                                      }

                                                                      else {

                                                                                String path = dlLoc+"\\"+data.getFileName();

                                                                                rtnStg ="Download Step Executed To: "+dlLoc;

                                                                                ContentServerHelper.service.writeContentStream(data, path);

                                                                                System.out.println(rtnStg+".\n");

                                                                                return rtnStg;

                                                                      }

                                                            }

                                                  }

                                                  else {

                                                            rtnStg = "No App Data associated to current Object.";

                                                            System.out.println("\n"+rtnStg+"\n");

                                                            return rtnStg;

                                                  }

                                        }

                              }

                    }

                    catch(Exception exception)

                    {

                              exception.printStackTrace();

                    }

                    return rtnStg;

          }

 

 

          public static String getEPMDoc(String dlLoc, String drwNo, String conType)

          {

                    String rtnStg="NO Data Found (getEPMDoc)";

                    try

                    {

                              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"));

                              System.out.println("Now Querying for Doc Using:\n " + qs.toString());

 

 

                              final QueryResult qr = PersistenceHelper.manager.find(qs);

 

 

                              while (qr.hasMoreElements()) {

                                        EPMDocument epmm = (EPMDocument)qr.nextElement();

 

 

                                        if (epmm.getNumber().endsWith(".DRW") || epmm.getNumber().endsWith(".CATpart") || epmm.getNumber().endsWith(".CATProduct")  ) {

                                                  System.out.println( "\nEPMDoc - Number: " + epmm.getNumber() + " - Name: " + epmm.getName()+ " - CadName: " + epmm.getCADName() );

                                                  System.out.println( " - Version: " + epmm.getVersionIdentifier().getValue() + " - Iteration:"+epmm.getIterationIdentifier().getValue()+"\n - Life Cycle State: "+epmm.getLifeCycleState().toString());

                                                  rtnStg = extractContent(epmm, dlLoc, conType);

                                                  return rtnStg;

                                        }

                              }

                    }

                    catch(Exception exception)

                    {

                              exception.printStackTrace();

                    }

                    return rtnStg;

          }

}


Viewing all articles
Browse latest Browse all 3592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>