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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Download Latest version/iteration of EPM document

vmhala
10-Marble

Download Latest version/iteration of EPM document

Hi Windchillers,

Iam trying to download the latest copy of EPM document by using the following code; but the content downloaded is non latest. What could be the issue :

package com.phoenix.listen;

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.fc.PersistenceHelper;

import wt.fc.QueryResult;

import wt.query.QuerySpec;

import wt.query.SearchCondition;

import wt.util.WTException;

public class EPM_Doc_Pass {

  public static boolean downloadFile(EPMDocument epmDoc, String downloadDirectory) {

    boolean result=false;

  ContentItem primaryContent=null;

  String wtTemp = System.getProperty("wt.temp");

  String fullName = wtTemp + "//" + downloadDirectory + "//" + epmDoc.getCADName();

  String Docname = epmDoc.getName();

  try {

  // EPMDocument

  if ( !epmDoc.isGeneric() ) {

  QuerySpec qs = new QuerySpec (EPMDocument.class);

  

   qs.appendWhere(new SearchCondition(EPMDocument.class,EPMDocument.NAME,SearchCondition.LIKE,Docname));

   qs.appendAnd();

   qs.appendSearchCondition (new SearchCondition (EPMDocument.class, "iterationInfo.latest", SearchCondition.IS_TRUE));

 

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

                              

     while (qr.hasMoreElements()) {

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

               System.out.println(epmDoc1.getCADName()+ epmDoc1.getVersionDisplayIdentifier()+epmDoc1.getIterationDisplayIdentifier());

               epmDoc1 = (EPMDocument) ContentHelper.service.getContents( epmDoc1 );

               primaryContent = ContentHelper.getPrimary((FormatContentHolder)epmDoc1);

               if ( primaryContent!=null )

               {

               System.out.println("downloadFile >>> EPMDocument, writeContentStream : " + fullName );

               ContentServerHelper.service.writeContentStream( (ApplicationData)primaryContent, fullName );

               result=true;           

  

}

              

                 

    }

  }

  }

  catch (Exception _e) {

  _e.printStackTrace();

  return false;

  }

  System.out.println("downloadFile >>> OUT...");

  return(result);

  }

}

4 REPLIES 4
kpritchard
12-Amethyst
(To:vmhala)

My thinking is that your query is getting the latest iteration of each version.  If it's me I'm probably querying for EPMDocumentMaster and getting the ordered list of versions (allVersionsOf()) from there

Just looking at other download samples, should this:

   qs.appendWhere(new SearchCondition(EPMDocument.class,EPMDocument.NAME,SearchCondition.LIKE,Docname));

   qs.appendAnd();

   qs.appendSearchCondition (new SearchCondition (EPMDocument.class, "iterationInfo.latest", SearchCondition.IS_TRUE));

Be this:

qs.appendWhere(new SearchCondition(EPMDocument.class,EPMDocument.NAME,SearchCondition.LIKE, Docname));

qs.appendAnd();

qs.appendWhere(new SearchCondition(EPMDocument.class, "iterationInfo.latest", "TRUE"));

ybagul
12-Amethyst
(To:vmhala)

Can you replace downloadFile method with following method and try? I have not tested this code, but it should work. I guess this is what Keir Pritchard suggested.

public static boolean downloadFile(EPMDocument epmDoc, String downloadDirectory) {

  boolean result=false;

  ContentItem primaryContent=null;

  String wtTemp = System.getProperty("wt.temp");

  String fullName = wtTemp + "//" + downloadDirectory + "//" + epmDoc.getCADName();

  String Docname = epmDoc.getName();

  try {

  // EPMDocument

  if ( !epmDoc.isGeneric() ) {

  QueryResult epmQueryResult = VersionControlHelper.service.allVersionsOf(epmDoc.getMaster());

  EPMDocument epmDoc1 = null;

  while(epmQueryResult.hasMoreElements()){

  epmDoc1 = (EPMDocument) epmQueryResult.nextElement();

  break;

  }

  System.out.println(epmDoc1.getCADName()+ epmDoc1.getVersionDisplayIdentifier()+epmDoc1.getIterationDisplayIdentifier());

  epmDoc1 = (EPMDocument) ContentHelper.service.getContents( epmDoc1 );

  primaryContent = ContentHelper.getPrimary((FormatContentHolder)epmDoc1);

  if(primaryContent!=null){

  System.out.println("downloadFile >>> EPMDocument, writeContentStream : " + fullName );

  ContentServerHelper.service.writeContentStream((ApplicationData)primaryContent, fullName);

  result=true;

  }

  }

  } catch (Exception _e) {

  _e.printStackTrace();

  return false;

  }

  System.out.println("downloadFile >>> OUT...");

  return(result);

  }

rmk
7-Bedrock
7-Bedrock
(To:vmhala)

Hi

Please Try the following code,

package ext.test;

import wt.epm.EPMDocument;

import wt.epm.EPMDocumentMaster;

import wt.fc.PersistenceHelper;

import wt.fc.QueryResult;

import wt.pds.StatementSpec;

import wt.query.QuerySpec;

import wt.util.WTException;

public class EPMLatest {

  public static void main(String[] args) throws WTException {

  // **************************************************************

  // Retrieve List of EPMDocumentMasters

  // **************************************************************

  QuerySpec qs = new QuerySpec(EPMDocumentMaster.class);

  EPMDocumentMaster master = null;

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

  System.out.println("Number of EPM Document Masters: " + qr.size() + "\n\n");

  while (qr.hasMoreElements()) {

  master = (EPMDocumentMaster) qr.nextElement();

  System.out.println("***** Name ->"+ master.getName());

  EPMDocument latest = (EPMDocument)wt.vc.VersionControlHelper.service.allVersionsOf(master).nextElement();

  String versionLatest = wt.vc.VersionControlHelper.getVersionIdentifier(latest).getValue();

  System.out.println("******** Identity -> "+ latest.getIdentity());

  System.out.println("******** Latest Version -> "+ versionLatest);

  System.out.println("******** Latest Iteration -> "+ latest.getIterationDisplayIdentifier());

  System.out.println("******** State of latest version of latest iteration -> "+latest.getState());

  // Use Here to download the Content

  primaryContent = ContentHelper.getPrimary((FormatContentHolder)latest);

               if ( primaryContent!=null )

               {

               System.out.println("downloadFile >>> EPMDocument, writeContentStream : " + fullName );

               ContentServerHelper.service.writeContentStream( (ApplicationData)primaryContent, FileFullName(C:/abc.prt) );

  }

  }

}

BR

MKR

Announcements


Top Tags