It's all about the answers!

Ask a question

retrieving the conditions of a query programatically using the plain Java client libraries


Miguel Tomico (5001423) | asked Oct 07 '14, 9:23 a.m.
edited Oct 07 '14, 9:28 a.m.
I have seen a couple of posts on how to create query conditions using Java, but I would like to retrieve the conditions of every predefined query, for administration and reporting purposes.

Ideally, we would like to have something similar to a WHERE clause in an SQL statement. E.g.: WHERE ((Work_Item_Type == 'Task') AND (Priority == 'Medium'))
I guess we can use the Statement, Term and Operator classes as follows, but I was wondering if there is an easier way. Any ideas?

List<IQueryDescriptor> queryDescriptorList = queryClient.findSharedQueries(prj, sharingTargets, QueryTypes.WORK_ITEM_QUERY, IQueryDescriptor.FULL_PROFILE, monitor);
for (int countQueryDescriptor=0;countQueryDescriptor<queryDescriptorList.size();countQueryDescriptor++) {
IQueryDescriptor queryDescriptor = queryDescriptorList.get(countQueryDescriptor);
Statement stmt = (Statement)queryDescriptor.getExpression();
Term term = (Term) stmt.getConditions();
List<Expression> listConditions = term.getExpressions();
//Use a recursive function to retrieve all expressions along with their operators
...
}

One answer



permanent link
Ralph Schoon (63.5k33646) | answered Oct 07 '14, 10:06 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I would think that is the way to do it. You might want to check com.ibm.team.workitem.ide.ui.internal.queryeditor.QueryEditor how it does it. My assumption is, it would do it the very same way. You'd get a tree of expressions and conditions.

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.