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
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:
// repo is a ITeamRepository
IProcessItemService connect = (IProcessItemService) repo
.getClientLibrary(IProcessItemService.class);
List<IProjectArea> p = connect.findAllProjectAreas(null, monitor);
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.
auditableClient = (IAuditableClient) repository.getClientLibrary(IAuditableClient.class);
IQueryClient queryClient = (IQueryClient) repository.getClientLibrary(IQueryClient.class);
IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(currProject, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, null);
Expression expression = new AttributeExpression(attribute, AttributeOperation.EQUALS, currProject);
IQueryResult<IResolvedResult<IWorkItem>> results = queryClient.getResolvedExpressionResults(currProject, expression, IWorkItem.FULL_PROFILE);
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.
Comments
1 vote
1 vote
1 vote
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
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.
IAttributeVariable<String> variable = new WorkItemTypeVariable("defect");
System.out.println(variable.getDisplayName());
IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE) .findAttribute(currProject, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, monitor);
Expression expression = new VariableAttributeExpression(attribute,
AttributeOperation.EQUALS, variable);
IQueryResult<IResolvedResult<IWorkItem>> results = queryClient
.getResolvedExpressionResults(currProject, expression,
IWorkItem.FULL_PROFILE);
Is there a way to do this?
Best regards
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());
}
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!
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!