Define RTC query term including workitem state
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());
}
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());
}