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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

How to search EPMDocument in folder or container using WC APIs

ptc-4576665
1-Visitor

How to search EPMDocument in folder or container using WC APIs

I want to search all EPMDocuments in a folder or container using Windchill API (QuerySpec). I do not want to use webjects. How can I do it?

7 REPLIES 7

I want to search All EPMDocuments under a folder. Query should take Folder path or container name as input and output should list all EPDocumets under that folder.

vmg
7-Bedrock
7-Bedrock
(To:ptc-4576665)

Hi Amit,

QuerySpec querySpec2 = new QuerySpec(EPMDocument.class);

/*SearchCondition condition = new SearchCondition(ContainerTeam.class,ContainerTeam.NAME, SearchCondition.LIKE,"%Sample_Product_02");

querySpec2.appendWhere(condition);*/

QueryResult queryResult2 = PersistenceServerHelper.manager.query(querySpec2);

while (queryResult2.hasMoreElements()) {

EPMDocument epmDocument = (EPMDocument) queryResult2.nextElement();

System.out.println("Part Name : "+ epmDocument.getCADName());

}

it only takes all the cad names (EPM Document).

but i cant able to fullfill your requirement.

Thank you

Vijayan

KD
12-Amethyst
12-Amethyst
(To:vmg)

Hi,

Try this may be it'll help

QuerySpec qss = new QuerySpec(EPMDocument.class);

EPMDocument doc = null;

qss.appendWhere(new SearchCondition(EPMDocument.class,EPMDocument.CONTAINER_NAME,SearchCondition.EQUAL,"<your container name>"),new int[] { 0 });

qss.appendAnd();

qss.appendWhere(new SearchCondition(EPMDocument.class,EPMDocument.FOLDER_PATH,SearchCondition.EQUAL,"<your folder path>"),new int[] { 0 });

QueryResult qrr = PersistenceHelper.manager.find((StatementSpec)qss);

while(qrr.hasMoreElements())

{

doc = (EPMDocument)qrr.nextElement();

}

Message was edited by: kaushik das

ptc-4576665
1-Visitor
(To:KD)

Thanks Kaushik but I Getting below error.

It is for the line

wt.query.QueryException

(EPMDocument.class,EPMDocument.CONTAINER_NAME,SearchCondition.EQUAL,"mytest2"),new int[] { 0 });

: Attribute "containerReference.name" is not a member of class "class wt.epm.EPMDocument"

Nested exception is: Attribute "containerReference.name" is not a member of class "class wt.epm.EPMDocument"; nested exception is:

(wt.pom.pomResource/0)

wt.pom.PersistenceException

: A persistence error occurred. System message follows:

Nested exception is: (wt.introspection.introspectionResource/2)

wt.introspection.WTIntrospectionException

: containerReference.name column not found for V_EPMDocument.

at wt.introspection.DatabaseViewInfo.getColumnDescriptor(

DatabaseViewInfo.java:302

)

at wt.pds.DatabaseInfoUtilities.getValidColumnDescriptor(

DatabaseInfoUtilities.java:339

)

at wt.pds.DatabaseInfoUtilities.getValidColumnDescriptor(

DatabaseInfoUtilities.java:377

)

at wt.pds.DatabaseInfoUtilities.getPersistableColumnDescriptor(

DatabaseInfoUtilities.java:666

)

at wt.query.ClassAttribute.validate(

ClassAttribute.java:1054

)

at wt.query.ClassAttribute.setAttributeName(

ClassAttribute.java:218

)

at wt.query.ClassAttribute.<init>(

ClassAttribute.java:468

)

at wt.query.SearchCondition.initialize(

SearchCondition.java:2234

)

at wt.query.SearchCondition.<init>(

SearchCondition.java:1433

)

at wt.query.SearchCondition.<init>(

SearchCondition.java:1388

)

at com.slb.test.EPMSearch.main(

EPMSearch.java:51

)

KD
12-Amethyst
12-Amethyst
(To:ptc-4576665)

QuerySpec qss = new QuerySpec(EPMDocument.class);

EPMDocument doc = null;

QueryResult qrr = PersistenceHelper.

manager.find((StatementSpec)qss);

while(qrr.hasMoreElements())

{

doc = (EPMDocument)qrr.nextElement();

String path = doc.getFolderPath();

if(doc.getContainerName().equalsIgnoreCase("<your container name>")==true && path.substring(0,path.lastIndexOf("/")).equalsIgnoreCase("<folder name>")==true)

{

//System.out.println(doc.getContainerName());

<your code >

//System.out.println();

}

}

Message was edited by: kaushik das

KD
12-Amethyst
12-Amethyst
(To:KD)

QuerySpec queryspec =

new QuerySpec(EPMDocument.class);

queryspec.setAdvancedQueryEnabled(

true);

int contIndex = queryspec.appendClassList(PDMLinkProduct.class,false);

SearchCondition sc1 =

new SearchCondition(EPMDocument.class, "containerReference.key.id",PDMLinkProduct.class, wt.util.WTAttributeNameIfc.ID_NAME);

queryspec.appendWhere(sc1,

new int[] { 0, contIndex });

queryspec.appendAnd();

SearchCondition scSWPart =

new SearchCondition(PDMLinkProduct.class ,"containerInfo.name",SearchCondition.EQUAL,"<your product name>",true);

queryspec.appendWhere(scSWPart,

new int[] { contIndex });

QueryResult queryResult = PersistenceHelper.

manager.find((StatementSpec)queryspec);

System.

out.println("Size :- " + queryResult.size());

vuchekar
10-Marble
(To:KD)

Hi Kaushik,

Above code is working perfect for Product, but for WTLibarary, i have create similar method, but i am getting "wt.query.QueryException: Attribute "containerReferene.key.id" is not a member of class "class wt.part.WTPart"

here is Program,

Please guide me to solve this error,

===========================================================

import wt.doc.WTDocument;

import wt.epm.EPMDocument;

import wt.fc.Persistable;

import wt.fc.PersistenceHelper;

import wt.fc.QueryResult;

import wt.inf.library.WTLibrary;

import wt.lifecycle.LifeCycleHelper;

import wt.lifecycle.LifeCycleState;

import wt.part.WTPart;

import wt.pdmlink.PDMLinkProduct;

import wt.pds.StatementSpec;

import wt.query.CompositeQuerySpec;

import wt.query.QueryException;

import wt.query.QuerySpec;

import wt.query.SearchCondition;

import wt.util.WTException;

public class ObjectFromContainer {

public static void main(String[] args) {

try{

    WTPart part=null;

    WTDocument doc=null;

    EPMDocument epm=null;

    Persistable[] pers=null;

    String name="Test Lib";

    // * Entering QuerySpec for multiple query statements by CompositeQuerySpec

   

    CompositeQuerySpec cqs = new CompositeQuerySpec();

   cqs.addComponent(statementspecGenerator(WTPart.class,"TestProduct"));

   cqs.addComponent(statementspecGenerator(WTDocument.class,name));

   cqs.addComponent(statementspecGenerator(EPMDocument.class, "TestProduct"));

    QueryResult queryResult2 =  PersistenceHelper.manager.find((StatementSpec)cqs);

    System.out.println(queryResult2.size());

    while(queryResult2.hasMoreElements())

    {

        pers=(Persistable[]) queryResult2.nextElement();

        for(Persistable p:pers)

        {

            // * Changing the LifeCycleState of the objects As given

            if(p instanceof WTPart)

            {

                part=(WTPart) p;

                System.out.println("Parts are"+((WTPart) p).getName());

            }

            else if(p instanceof WTDocument)

            {

                doc=(WTDocument) p;

                System.out.println("Documents are"+((WTDocument) p).getName());

            }

            else if(p instanceof EPMDocument)

            {

                epm=(EPMDocument) p;

                System.out.println("EPM's are"+((EPMDocument) p).getName());

            }

        }

    }

    System.out.println("*******All Process Completed *********");

}

catch(QueryException e)

{

  e.printStackTrace();

} catch (WTException e) {

  // TODO Auto-generated catch block

  e.printStackTrace();

}

}

@SuppressWarnings("unchecked")

private static StatementSpec statementspecGenerator(Class c,String contName) throws WTException

{

    QuerySpec queryspec = new QuerySpec(c);

    queryspec.isAdvancedQueryEnabled();

    int contIndex = queryspec.appendClassList(PDMLinkProduct.class,false);

    SearchCondition sc1 = new SearchCondition(c, "containerReference.key.id",PDMLinkProduct.class, wt.util.WTAttributeNameIfc.ID_NAME);

    queryspec.appendWhere(sc1, new int[] { 0, contIndex });

    queryspec.appendAnd();

    SearchCondition scSWPart = new SearchCondition(PDMLinkProduct.class ,"containerInfo.name",SearchCondition.EQUAL,contName,true);

    queryspec.appendWhere(scSWPart, new int[] {  contIndex });

return (StatementSpec)queryspec;

}

// For WTLiberyext.racing.ObjectFromContainer

@SuppressWarnings("unchecked")

private static StatementSpec statementspecGeneratorLibrary(Class c,String contName) throws WTException{

  QuerySpec queryspec = new QuerySpec(c);

  queryspec.isAdvancedQueryEnabled();

  int contIndex = queryspec.appendClassList(WTLibrary.class, false);

  SearchCondition sc1 = new SearchCondition(c,"containerReferene.key.id",WTLibrary.class,wt.util.WTAttributeNameIfc.ID_NAME);

  queryspec.appendWhere(sc1, new int[]{ 0, contIndex });

  queryspec.appendAnd();

  SearchCondition scSWPart = new SearchCondition(WTLibrary.class,"conatinerInfo.name",SearchCondition.EQUAL,contName,true);

  queryspec.appendWhere(scSWPart,new int[]{contIndex});

  return (StatementSpec)queryspec;

}

}

=============================================================

// when i call statementspecGeneratorLibrary method i am getting error.

Please guide me.

Regards,

Vivek

Announcements


Top Tags