It's all about the answers!

Ask a question

how can be created a work item query with a team area property using the Java API?


Krasimir Malchev (56531) | asked Feb 14 '17, 10:53 a.m.

It is possible to create a work item query with a specified team area in the RTC Eclipse and web clients?

How can I create a similar one using the Plain Java API?

3 answers



permanent link
Krasimir Malchev (56531) | answered Feb 15 '17, 6:04 a.m.
edited Feb 15 '17, 6:10 a.m.

@ Kevin Ramer: Thanks for the useful hint!


I have finally managed to solve my issue with the following pseudo-code:

   private void printQueryResults(IProcessArea fProcessArea,
IProgressMonitor monitor) throws TeamRepositoryException {
IWorkItemCommon workItemCommonService = (IWorkItemCommon) teamRepository
.getClientLibrary(IWorkItemCommon.class);
IQueryCommon queryCommon = (IQueryCommon) teamRepository
.getClientLibrary(IQueryCommon.class);
IQueryableAttributeFactory attrFactory = QueryableAttributes
.getFactory(IWorkItem.ITEM_TYPE);
IQueryableAttribute attribProjectArea = attrFactory.findAttribute(
fProcessArea.getProjectArea(), IWorkItem.PROJECT_AREA_PROPERTY,
queryCommon.getAuditableCommon(), monitor);
Term workItemsInProcessArea = new Term(Term.Operator.AND);
Expression inProjectArea = new AttributeExpression(attribProjectArea,
AttributeOperation.EQUALS, fProcessArea.getProjectArea());
workItemsInProcessArea.add(inProjectArea);
Term term = generateCategoryTerm(fProcessArea, workItemCommonService,
monitor);
workItemsInProcessArea.add(term);
IQueryDescriptor descriptor = queryCommon.createQuery(
fProcessArea.getProjectArea(), "WorkItemsInProcessArea",
"WorkItemsInProcessArea", workItemsInProcessArea);
IQueryResult<IResolvedResult<IWorkItem>> resolvedResults = queryCommon
.getResolvedQueryResults(descriptor, IWorkItem.SMALL_PROFILE);
resolvedResults.setLimit(Integer.MAX_VALUE);
processResolvedResults(resolvedResults, monitor);
}
private static Term generateCategoryTerm(
IProcessArea processArea, IWorkItemCommon workItemCommonService,
IProgressMonitor monitor) throws TeamRepositoryException {
List<ICategory> processAreaCategories = workItemCommonService
.findCategoriesOfProcessArea(processArea,
ICategory.FULL_PROFILE, monitor);
Term processAreaCategoriesTerm = new Term(Operator.OR);
IQueryableAttribute categoryAttribute = QueryableAttributes.getFactory(
IWorkItem.ITEM_TYPE).findAttribute(
processArea.getProjectArea(), IWorkItem.CATEGORY_PROPERTY,
workItemCommonService.getAuditableCommon(), monitor);
for (ICategory category : processAreaCategories) {
Expression categoryExpression = new AttributeExpression(
categoryAttribute, AttributeOperation.EQUALS, category);
processAreaCategoriesTerm.add(categoryExpression);
}
return processAreaCategoriesTerm;
}
private static void processResolvedResults(
IQueryResult<IResolvedResult<IWorkItem>> resolvedResults,
IProgressMonitor monitor) throws TeamRepositoryException {
long processed = 0;
while (resolvedResults.hasNext(monitor)) {
IResolvedResult<IWorkItem> result = resolvedResults.next(monitor);
IWorkItem workItem = (IWorkItem) result.getItem();
System.out.println(workItem.getId());
processed++;
}
System.out.println("Processed work items: " + processed);
}


permanent link
Kevin Ramer (4.5k8183200) | answered Feb 14 '17, 3:42 p.m.

You need to determing Category to Team/Project Area.   Assigning the work item category implicitly associates the work item to a process area ( Team or Project ). The attribute is exposed as Filed Against, but underneath it is the category.

This little snippet might help you see how the categories can be gotten from project area:

                IWorkItemClient service = getWorkItemClient();  // "private" method to my Jazz client class.   Your work probably already can do this.
                
                List<ICategory> findCategories=null;
                try {
// jazzServer.getProjectArea() returns an IProjectArea, you might have it another way.
                    findCategories = service.findCategories(
                            jazzServer.getProjectArea(), ICategory.FULL_PROFILE,
                            jazzServer.getMonitor());
                } catch (TeamRepositoryException e) {
                    // TODO Auto-generated catch block
                    logger.error("Exception",e);
                }
                for (ICategory category : findCategories) {
                    if (!category_cache.containsKey(category.getHierarchicalName())) {

                        logger.debug("Adding category name "+category.getHierarchicalName()+" to cache.");
                        category_cache.put(category.getHierarchicalName(), category);
                    }
                }

The ICategory object has methods to get the associated process area, but the query should use the category.


Comments
Ralph Schoon commented Feb 15 '17, 3:53 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 Right, the TeamArea Property is not an attribute. as opposed to com.ibm.team.workitem.common.model.IWorkItem.PROJECT_AREA_PROPERTY. It is derived by using the category and you will likely have to get the categories from the team area and then search for the categories that are relevant.


I don't have an example. I can't possibly create examples for all the questions out there. I can only provide basic examples. You have to improve on that. 


permanent link
Ralph Schoon (63.1k33646) | answered Feb 14 '17, 11:07 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Comments
Krasimir Malchev commented Feb 14 '17, 11:13 a.m.

Yes, I have gone through these wonderful articles.

Though, I am still not able to specify a team area as a queryable attribute as it looks like the team area is not an attribute.
I want to create a query which returns all work items assigned to a specified team area or its child team areas.
I tried to use constructs like this:
if(processArea instanceof ITeamArea) {
   IAssociation association=   
                      descriptor.getAssociations().createAssociation(processArea);
   descriptor.getAssociations().associate(association);
Unfortunately it does not work.
Ralf, is it possible to help me what exactly should I do to get the result?

Thanks a lot!
 
Greetings,
K. Malchev

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.