Getting work Items through Plain Java API
Hello,
I try to get work Items of a specific project area through the plain Java API. I managed to get all project areas with the following code:
Afterwards I'd like to get all WorkItems of a project area. How can I do this? I am working with Plain Java Client Libraries Version 3.0.1.2 Best regards |
Accepted answer
I used the following code to get the work items associated with each project area:
In my code, currProject would be the IProjectArea pointer to the current project as you loop through the List of project areas p in your code. The IQueryResult object 'results' then contains a list of IResolvedResult records with all of the work items for that project you can iterate through and find properties for each work item. Hope this helps. Melanie Finke selected this answer as the correct answer
Comments Also see http://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/ and http://rsjazz.wordpress.com/2012/11/19/using-expressions-for-automation/ and http://rsjazz.wordpress.com/2012/11/19/using-an-expression-to-synchronize-attributes-for-work-items-of-a-specific-type/ as examples for this kind of automation.
Mathieu Defianas
commented Dec 17 '14, 10:34 a.m.
Hello,
1
Ralph Schoon
commented Dec 17 '14, 11:22 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
To run a query on the server, you can use IQueryCommon which is a common service - in fact, you can probably use it on the client as well. The rest should look like in
Mathieu Defianas
commented Dec 17 '14, 11:35 a.m.
Thanks Ralph.
About
1
Ralph Schoon
commented Dec 17 '14, 11:43 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You get it using fWorkItemCommon = getService(IWorkItemCommon.class); You can only use getService if your class extends com.ibm.team.repository.service.AbstractService for example public class MyParticipant extends AbstractService implements IOperationParticipant { See examples such as https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/ on that blog.
Mathieu Defianas
commented Dec 17 '14, 12:28 p.m.
Thanks a lot Ralph !
Mathieu Defianas
commented Dec 17 '14, 12:46 p.m.
Ralph,
sam detweiler
commented Dec 17 '14, 12:56 p.m.
I get the same warning, but it works
1
Ralph Schoon
commented Dec 18 '14, 2:44 a.m.
| edited Dec 18 '14, 2:46 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
The warning is normal and does not create problems. If you leave the prerequisites out, you do. The schema should be adjusted, I think.
showing 5 of 10
show 5 more comments
|
5 other answers
Hello,
thank's for the answer. Now I get all WorkItems. Is it possible to get only the work Items with e.g. type defect? I tried it with the following code, but still get all Work Items.
Is there a way to do this? Best regards |
Hi,
I am new to RTC. could you able to given code for fetching work items from plain java api. Thanks, Pugazh |
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()); } |
private List<IWorkItem> getWorkItems( IIteration sprint, String projectId ) throws TeamRepositoryException
{
IProjectAreaHandle iProjectAreaHandle = (IProjectAreaHandle) getProjectArea( projectId ).getItemHandle();
IQueryClient queryClient = (IQueryClient) getTeamRepository().getClientLibrary( IQueryClient.class );
IAuditableClient auditableClient = (IAuditableClient) getTeamRepository().getClientLibrary(
IAuditableClient.class );
IQueryableAttributeFactory queryableAttributeFactory = QueryableAttributes.getFactory( IWorkItem.ITEM_TYPE );
IQueryableAttribute targetProperty = queryableAttributeFactory.findAttribute( iProjectAreaHandle,
IWorkItem.TARGET_PROPERTY, auditableClient, null );
Expression sprintEqulas = new AttributeExpression( targetProperty, AttributeOperation.EQUALS, sprint );
IQueryableAttribute isArchived = queryableAttributeFactory.findAttribute( iProjectAreaHandle,
IWorkItem.ARCHIVED_PROPERTY, auditableClient, null );
Expression notArchived = new AttributeExpression( isArchived, AttributeOperation.EQUALS, false );
Term expression = new Term( Operator.AND );
expression.add( sprintEqulas );
expression.add( notArchived );
IQueryResult<IResolvedResult<IWorkItem>> queryResult = queryClient.getResolvedExpressionResults(
iProjectAreaHandle, expression, IWorkItem.FULL_PROFILE );
List<IWorkItem> workItems = new ArrayList<IWorkItem>( queryResult.getResultSize( getProgressMonitor() )
.getTotalAvailable() );
while (queryResult.hasNext( getProgressMonitor() ))
{
IResolvedResult<IWorkItem> resolvedResult = queryResult.next( getProgressMonitor() );
IWorkItem workItem = resolvedResult.getItem();
workItems.add( workItem );
}
return workItems;
}
|
Hi all,
can someone share or attach the whole source-code for getting ALL WorkItems without predefined queries? My Idea behind is to list all project areas and to list all worktimes for every project areas. The first step is done! I get all my project areas in a customized way...but now i'm trying to get the workitems and that doesn't work with the help of the tutorials. That's why I need the source to see the imports, main-class and the other methods. Always there is something missing or i am not able to include your codes. Best regards! Comments
Ralph Schoon
commented Oct 05 '15, 10:04 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You can only get work items in a project area.
|
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.