It's all about the answers!

Ask a question

Need Java api calls for listing and executing Queries


Sumana Marathe (143) | asked Dec 08 '11, 7:25 a.m.
Hi all,

I have a requirement where I need to show the list of pre-defined queries and my queries created in RTC 3.0 in my Java client code. Also, I need to execute those queries and display the results. Can anyone provide me with sample code for doing this?

Thanks,
Sumana Bhat

8 answers



permanent link
Michele Pegoraro (1.8k14119103) | answered Dec 13 '11, 3:28 a.m.
You have to use IQueryService, IQueryClient or IQueryCommon (it depends on what kind of use do you need). Then you can use, for example

IQueryCommon.findPersonalQueries
IQueryCommon.findSharedQueries

in order to get queries and than

IQueryCommon.getQueryResults(query)

to get results.

Best regards,
Michele.

permanent link
Tobias Käppeli (261) | answered Jan 16 '12, 5:19 a.m.
So now i got it and I want to share the results here.

The Queryclient is initialzied like this
IWorkItemClient Client = (IWorkItemClient) this.teamRepository.getClientLibrary(IWorkItemClient.class);

IQueryClient QueryClient = Client.getQueryClient();


The query I search is shared within my Projectarea. It could also be a Team. Or both i think.
List<IProjectAreaHandle> sharingTargets =  new ArrayList<IProjectAreaHandle>();

The project is from type IProjectArea
sharingTargets.add(Project.getProjectArea());

The method call for the SharedQueries
List<IQueryDescriptor> SharedQueries =  QueryClient.findSharedQueries(Project.getProjectArea(), sharingTargets, QueryTypes.WORK_ITEM_QUERY, QueryDescriptor.FULL_PROFILE, monitor);
The method call for your personal "My Queries"

List<IQueryDescriptor> MyQueries = QueryClient.findPersonalQueries(Project.getProjectArea(), (IContributorHandle)this.teamRepository.loggedInContributor().getItemHandle(), QueryTypes.WORK_ITEM_QUERY, QueryDescriptor.FULL_PROFILE, monitor);

permanent link
sam detweiler (12.5k6195201) | answered Dec 12 '11, 9:41 a.m.
I don't know how to do it exactly, but there is no simple 'api'... there are a bunch of methods on objects as this is an Object Oriented system..

you will have to connect to the repository and then use the IQuery interface classes to get and manage queries

see com.ibm.team.repository.common.query in the javadoc provided with 3.0.1.1. you will need some of com.ibm.team.repository.client and common to do that..

Sam

permanent link
Adam Rice (6) | answered Jan 09 '12, 4:15 a.m.
You have to use IQueryService, IQueryClient or IQueryCommon (it depends on what kind of use do you need). Then you can use, for example

IQueryCommon.findPersonalQueries
IQueryCommon.findSharedQueries

in order to get queries and than

IQueryCommon.getQueryResults(query)

to get results.

Best regards,
Michele.


Hi Michele,

Do you know what value I should be passing in as the QueryType to those method calls? I have been trying to use them and I keep getting back empty lists.


String queryType= "WorkItemQuery";
ItemProfile<IQueryDescriptor> defaultprofile = IQueryDescriptor.DEFAULT_PROFILE;
List<IQueryDescriptor> personalQueries = queryClient.findPersonalQueries(projectArea, teamRepository.loggedInContributor(), queryType, defaultprofile, null);


Regards,
Adam

permanent link
Tobias Käppeli (261) | answered Jan 13 '12, 9:52 a.m.
I'm at the same point like you. Did you already find out which value you have to pass for QueryType?

Regards,
Tobias

permanent link
sam detweiler (12.5k6195201) | answered Jan 13 '12, 12:50 p.m.
In many cases, the only answers are to read the source code.

Sam

permanent link
Tobias Käppeli (261) | answered Jan 16 '12, 2:07 a.m.
For my own Query i could get results with this call:

List<IQueryDescriptor> Queries = QueryClient.findPersonalQueries(Project.getProjectArea(), (IContributorHandle)this.teamRepository.loggedInContributor().getItemHandle(), QueryTypes.WORK_ITEM_QUERY, QueryDescriptor.FULL_PROFILE, monitor);


Now I stuck at the "List<extends>" for the sharingTargets at the findSharedQueries method.

Any ideas what that target is?

Regards
Tobias

Comments
Michele Pegoraro commented Feb 11 '13, 9:16 a.m.

SharingTarget could be a List of IProjectAreaHandle as in the example above. What is the problem with "extends"?


permanent link
Ralph Schoon (63.7k33648) | answered Feb 11 '13, 4:08 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
 This post shows working code it especially allows you to exceed the query result set size limit. https://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.