How to get the WorkItems from a Project Area based on their type ?
I am trying to get all the work items which have their type as defect from a particular project area. But I'm only able to get all the work items irrespective of their type from a particular project area. Can any one please tell me how to add the type criteria and get the work items which are of type defect. Below is the code which I am working on.
Thanks.
Thanks.
String repoUri = "****************"; final String userId = "****************"; final String password = "******************"; List<IWorkItem> defectWorkitems=new ArrayList<IWorkItem>(); TeamPlatform.startup(); try {
// Login to the repository using the provided credentials
ITeamRepository repo = TeamPlatform.getTeamRepositoryService().getTeamRepository(repoUri); repo.registerLoginHandler(new ILoginHandler2() {
@Override
public ILoginInfo2 challenge(ITeamRepository arg0) {
return new UsernameAndPasswordLoginInfo(userId, password);
}
});
repo.login(new SysoutProgressMonitor());
IProcessItemService connect = (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
List<IProjectArea> p = connect.findAllProjectAreas(null, new SysoutProgressMonitor());
System.out.println("Project Areas :");
for(IProjectArea projectArea: p){
System.out.println(projectArea.getName());
if(projectArea.getName().equals("********************")){
System.out.println("here");
IAuditableClient auditableClient = (IAuditableClient) repo.getClientLibrary(IAuditableClient.class);
IQueryClient queryClient = (IQueryClient) repo.getClientLibrary(IQueryClient.class);
IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(projectArea, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, null);
Expression expression = new AttributeExpression(attribute, AttributeOperation.EQUALS, projectArea);
IQueryResult<IResolvedResult<IWorkItem>> results = queryClient.getResolvedExpressionResults(projectArea, expression, IWorkItem.FULL_PROFILE);
while(results.hasNext(new SysoutProgressMonitor())){
IResolvedResult<IWorkItem> result = results.next(new SysoutProgressMonitor());
IWorkItem workItem = (IWorkItem) result.getItem();
System.out.println(workItem.getItemId());
if(workItem.getItemType().toString()=="Enhancement"){
System.out.println("here");
defectWorkitems.add(workItem);
}
}
}
} System.out.println(defectWorkitems.size());
} finally {
TeamPlatform.shutdown();
}
}
One answer
see Ralphs blog on querys
https://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/
https://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/
Comments
I m getting an error while running the above code right after printing the Project Area list.
ERROR: com.ibm.team.workitem.common - Value set provider not found: com.ibm.sport.rtc.common.ComponentBrowseValueSetUtils
Hm.. I have not figured out how to configure a batch application using the plain java apis to support running scripted extensions.