It's all about the answers!

Ask a question

Define RTC query term including workitem state


Kelvin Lui (51299) | asked Mar 26 '12, 1:07 p.m.
Hi,

I am trying to query a list of workitem base certain criteria:

term.add(projectAreaExpression);
term.add(workItemTypeExpression);
term.add(categoryExpression);

The query works fine until I try to add the filter of the workitem state.
The query returns null object. Could someone shed some light how to generate the query to look up list of workitem base on its state?

Thanks.



IQueryableAttribute stateAttribute = findAttribute(teamRepository, projectArea, IWorkItem.STATE_PROPERTY, monitor);
AttributeExpression workItemStateTypeExpression = new AttributeExpression(stateAttribute, AttributeOperation.EQUALS, "Open");
...

term.add(workItemStateTypeExpression);


Code snippet:

IQueryableAttribute projectAreaAttribute= findAttribute(teamRepository, projectArea, IWorkItem.PROJECT_AREA_PROPERTY, monitor);
AttributeExpression projectAreaExpression= new AttributeExpression(projectAreaAttribute, AttributeOperation.EQUALS, projectArea);


IQueryableAttribute categoryAttribute = findAttribute(teamRepository, projectArea, IWorkItem.CATEGORY_PROPERTY, monitor);
AttributeExpression categoryExpression = new AttributeExpression(categoryAttribute, AttributeOperation.EQUALS, category);


IQueryableAttribute workItemTypeAttribute = findAttribute(teamRepository, projectArea, IWorkItem.TYPE_PROPERTY, monitor);
AttributeExpression workItemTypeExpression = new AttributeExpression(workItemTypeAttribute, AttributeOperation.EQUALS, WorkItemType.getIdentifier());



IQueryableAttribute stateAttribute = findAttribute(teamRepository, projectArea, IWorkItem.STATE_PROPERTY, monitor);


AttributeExpression workItemStateTypeExpression = new AttributeExpression(stateAttribute, AttributeOperation.EQUALS, "Open");

/* //Owner is Kelvin Lui"
IQueryableAttribute ownerAttribute = findAttribute(teamRepository, projectArea, IWorkItem.OWNER_PROPERTY, monitor);
AttributeExpression ownerTypeExpression = new AttributeExpression(ownerAttribute, AttributeOperation.EQUALS, "Kelvin Lui" );

System.out.println(" ownerAttribute.getAttributeType()" + ownerAttribute.getAttributeType() + " "+
ownerAttribute.getDisplayName() + " " + ownerAttribute.getIdentifier());*/

/*//WorkItem ID
IQueryableAttribute idAttribute = findAttribute(teamRepository, projectArea, IWorkItem.ID_PROPERTY, monitor);
//AttributeExpression idExpression = new AttributeExpression(idAttribute, AttributeOperation.EQUALS, "57320" );
//new AttributeExpression(idAttribute, AttributeOperation.EQUALS, "57320" );
*/
//System.out.println("ownerTypeExpress: "+ownerTypeExpression.getValue()+ " "+ ownerTypeExpression.getAttributeIdentifier());

//Build the Query by doing an AND Operation among the 3 above sub-queries
Term term= new Term(Operator.AND);
term.add(projectAreaExpression);
term.add(workItemTypeExpression);
term.add(categoryExpression);
term.add(workItemStateTypeExpression);
//term.add(idExpression);

/* IQueryClient queryClient = (IQueryClient) teamRepository.getClientLibrary(IQueryClient.class);

com.ibm.team.workitem.common.query.IQueryResult<IResolvedResult<IWorkItem>> result =
queryClient.getResolvedExpressionResults(projectArea, term, IWorkItem.FULL_PROFILE);

*/
// Evaluate Query

IQueryCommon queryService= getQueryCommon(teamRepository);
//ItemProfile<IWorkItem> profile= this.getProfile(projectAreaAttribute).createExtension(IWorkItem.CREATOR_PROPERTY);
this.getProfile(projectAreaAttribute).createExtension(IWorkItem.CREATOR_PROPERTY);
//IQueryResult<IResolvedResult<IWorkItem>> result= queryService.getResolvedExpressionResults(projectArea, term, profile);
IQueryResult<IResolvedResult<IWorkItem>> result= queryService.getResolvedExpressionResults(projectArea, term, IWorkItem.FULL_PROFILE);

//Add All Results in a list and return that list
List<IWorkItem> matchingWorkItems= new ArrayList<IWorkItem>(result.getResultSize(monitor).getTotalAvailable());
while (result.hasNext(monitor)) {
matchingWorkItems.add(result.next(monitor).getItem());
}

Be the first one to answer this question!


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.