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

How to retrieve all objects(WTpart,document,epm) from a Particular context?

SOLVED
Visitor

How to retrieve all objects(WTpart,document,epm) from a Particular context?

I need to get all the objects including WTPart,WTDocument,EPMDocument from a particular context.Any give me some code or API for this to do.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to retrieve all objects(WTpart,document,epm) from a Particular context?

HI Vigneshwaran,

Don't know whether It's a efficient way or not.But it works in `10.1

package ext.customization;

import wt.doc.WTDocument;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
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{
CompositeQuerySpec cqs = new CompositeQuerySpec();
cqs.addComponent(statementspecGenerator(WTPart.class,"<product name>"));
cqs.addComponent(statementspecGenerator(WTDocument.class,"<product name>"));

QueryResult queryResult2 = PersistenceHelper.manager.find((StatementSpec)cqs);
System.out.println(queryResult2.size());
}
catch(QueryException e)
{
e.printStackTrace();
} catch (WTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

private static StatementSpec statementspecGenerator(Class c,String contName) throws QueryException
{
QuerySpec queryspec = new QuerySpec(c);


queryspec.setAdvancedQueryEnabled(true);
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 });

//QueryResult queryResult = PersistenceHelper.manager.find((StatementSpec)queryspec);

return (StatementSpec)queryspec;
}

}

View solution in original post

7 REPLIES 7

Re: How to retrieve all objects(WTpart,document,epm) from a Particular context?

HI Vigneshwaran,

Don't know whether It's a efficient way or not.But it works in `10.1

package ext.customization;

import wt.doc.WTDocument;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
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{
CompositeQuerySpec cqs = new CompositeQuerySpec();
cqs.addComponent(statementspecGenerator(WTPart.class,"<product name>"));
cqs.addComponent(statementspecGenerator(WTDocument.class,"<product name>"));

QueryResult queryResult2 = PersistenceHelper.manager.find((StatementSpec)cqs);
System.out.println(queryResult2.size());
}
catch(QueryException e)
{
e.printStackTrace();
} catch (WTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

private static StatementSpec statementspecGenerator(Class c,String contName) throws QueryException
{
QuerySpec queryspec = new QuerySpec(c);


queryspec.setAdvancedQueryEnabled(true);
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 });

//QueryResult queryResult = PersistenceHelper.manager.find((StatementSpec)queryspec);

return (StatementSpec)queryspec;
}

}

View solution in original post

Re: How to retrieve all objects(WTpart,document,epm) from a Particular context?

Hi kaushik das,

thanks for your response.The code you have given is working fine but it is giving the query size only.I need to get all the objects with their lifecycle state(each object may have different LC).I tried to get object from query result using queryresult2.nextelement().But it is showing error.

what I'm trying to achieve is to change the Lifecycle state of each objects.

thank you

Re: How to retrieve all objects(WTpart,document,epm) from a Particular context?

Change your main method to the following and it will give you the object .

public static void main(String[] args) {

try{

WTPart part = null;

WTDocument doc = null;

Persistable[] pt = null;

CompositeQuerySpec cqs = new CompositeQuerySpec();

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

cqs.addComponent(statementspecGenerator(WTDocument.class,"newMPM"));

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

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

while(queryResult2.hasMoreElements())

{

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

for(Persistable p:pt)

{

if(p instanceof WTPart)

{

part = (WTPart)p;

System.out.println("Part name :- " + part.getName());

}

else if(p instanceof WTDocument)

{

doc = (WTDocument)p;

System.out.println("Doc name " + doc.getName());

}

}

}

}

catch(QueryException e)

{

e.printStackTrace();

} catch (WTException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Re: How to retrieve all objects(WTpart,document,epm) from a Particular context?

Hi kaushick das,

Along with this I need to pass the folder of any container.i.e.,I need to get objects from a particular folder inside the product.How to pass folder in query??

thanks

Re: How to retrieve all objects(WTpart,document,epm) from a Particular context?

If you want to achieve that then you have to join three tables using queryspec.

1> WTPart

2>Subfolder

3>Pdmlinkproduct

Re: How to retrieve all objects(WTpart,document,epm) from a Particular context?

Thanks Kaushik,

This works for my earlier post which you replied.

Re: How to retrieve all objects(WTpart,document,epm) from a Particular context?

Hello,

Is it possible to use this code from a client user or it must be loaded from the server?

Thanks,

Juan

Announcements