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.
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();
}
}