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

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

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?

0 votes



3 answers

Permanent link

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.

1 vote

Comments

 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

 See



You can create a query from an expression or use an existing query.

0 votes

Comments

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


Permanent link

@ 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);
}

0 votes

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
× 10,943

Question asked: Feb 14 '17, 10:53 a.m.

Question was seen: 2,594 times

Last updated: Feb 15 '17, 6:10 a.m.

Confirmation Cancel Confirm