Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Query with complex boolean Expression from code?

How do you construct a query in code using the Client library classes ("api") that has a complex filter? That is, how do you construct an Expression that's a boolean combination of other Expressions?
For example (simple one), what's the code to construct and run a query to find all defects that have a Resolved Date after a particular date?

0 votes



One answer

Permanent link
Snippet of code that works for me; not sure if there is a better way:

My code:


// uses my utility class to get repository, project area, and WI type refs
ITeamRepository repo = getUtility().getRepo(true);
IProjectAreaHandle pa = getUtility().getProjectArea();
IWorkItemType wiType = getUtility().getWorkItemType();


// playing with these attributes
IQueryableAttribute paAttr = getAttribute(IWorkItem.PROJECT_AREA_PROPERTY);
IQueryableAttribute typeAttr = getAttribute(IWorkItem.TYPE_PROPERTY);
IQueryableAttribute rdateAttr = getAttribute(IWorkItem.RESOLUTION_DATE_PROPERTY);

// Need to know today for resolved by date use
java.util.Date dateToday = new java.util.Date();
java.sql.Timestamp timeToday = new java.sql.Timestamp(dateToday.getTime());

// Make simple expressions with the attributes - default WI type is Defect

Expression paExpr = new AttributeExpression(
paAttr, AttributeOperation.EQUALS, pa);
Expression typeExpr = new AttributeExpression(
typeAttr, AttributeOperation.EQUALS, wiType.getIdentifier());
Expression rdateExpr = new AttributeExpression(
rdateAttr, AttributeOperation.BEFORE, timeToday);

// Make a complex expression
Term combined= new Term(Term.AND, new Expression[] { rdateExpr, paExpr, typeExpr});

// Setup and run query; check them for returned WI count
IQueryClient qc = (IQueryClient) repo.getClientLibrary(IQueryClient.class);
IQueryResult<IResolvedResult<IWorkItem>> result;

result = qc.getResolvedExpressionResults(pa, combined, IWorkItem.SMALL_PROFILE);

System.out.println("Combined expression query: "
+ "(rdate, defect type, and pa specific) query found:"
+ result.getTotalSize(null) + " WIs");


Given my repository I find two work items.

1 vote

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 11,072

Question asked: May 02 '08, 9:05 a.m.

Question was seen: 8,133 times

Last updated: May 02 '08, 9:05 a.m.

Confirmation Cancel Confirm