Get all work items from project
![]()
Hi,
I would like to retrieve all work items from a project.
I found a method on this forum which allows to do, but the problem is that I try to get a ITeamRepository object and it is null.
could someone unblock me?
My code is :
public class Moniteur extends AbstractService implements IOperationParticipant {
private IWorkItem wi;
private IProgressMonitor monitor;
public void run(AdvisableOperation operation,
IProcessConfigurationElement participantConfig,
IParticipantInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException {
if (data instanceof ISaveParameter)
{
wi = (IWorkItem) ((ISaveParameter) data).getNewState();
if (wi != null)
{
IWorkItem workingCopy = getFreshCopyWorItem();
IProjectAreaHandle ipah = workingCopy.getProjectArea();
IProjectArea ipa = (IProjectArea)getItemService().fetchItem(ipah,null);
IQueryDescriptor query = findPersonalQuery(ipa, "All Work Items", monitor);
}
}
}
public IQueryDescriptor findPersonalQuery(IProjectArea projectArea,
String queryName, IProgressMonitor monitor)
throws TeamRepositoryException {
// Get the required client libraries
ITeamRepository teamRepository = (ITeamRepository)projectArea.getOrigin();
IWorkItemClient workItemClient = (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);
IQueryClient queryClient = workItemClient.getQueryClient();
// Get the current user.
IContributor loggedIn = teamRepository.loggedInContributor();
IQueryDescriptor queryToRun = null;
// Get all queries of the user in this project area.
List queries = queryClient.findPersonalQueries(projectArea.getProjectArea(), loggedIn,QueryTypes.WORK_ITEM_QUERY,IQueryDescriptor.FULL_PROFILE, monitor);
// Find a query with a matching name
for (Iterator iterator = queries.iterator(); iterator.hasNext();) {
IQueryDescriptor iQueryDescriptor = (IQueryDescriptor) iterator.next();
if (iQueryDescriptor.getName().equals(queryName)) {
queryToRun = iQueryDescriptor;
break;
}
}
return queryToRun;
}
public IWorkItem getFreshCopy(IWorkItem workItem, IProgressMonitor monitor) throws TeamRepositoryException {
return getWorkItemServer().findWorkItemById(workItem.getId(), IWorkItem.FULL_PROFILE, monitor);
}
public IWorkItemServer getWorkItemServer() {
return super.getService(IWorkItemServer.class);
}
public IRepositoryItemService getItemService(){
return super.getService(IRepositoryItemService.class);
}
public IWorkItem getFreshCopyWorItem() throws TeamRepositoryException{
IWorkItem wiFreshCopy = getFreshCopy(wi, monitor);
return (IWorkItem) wiFreshCopy.getWorkingCopy();
}
}
Best regards
|
Accepted answer
![]()
Ralph Schoon (62.3k●3●36●43)
| answered Oct 07 '14, 7:16 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
See https://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/ and Jeremy's comment and my answer to it underneath the post.
Ralph Schoon selected this answer as the correct answer
Comments Ralph ,
|