Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

Jérémy

0 votes


Accepted answer

Permanent link
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

1 vote

Comments

 Ralph , 
Is it possible to get work item used to checkin a file/Changeset 
For Exaple if file PropertyReader.java has been checked in by a Developer  most recently using work item 123456 .. Need to get the work item number.. 
Using scm show history  command we can get the Change Set details,but not the work item number.

 scm show history -r $URL -u $userId -P $pwd -w $ws --component icdp_core_as /source/common/Adapters/com/bac/icdp/consumer/common 
/PropertyReader.java
 
Change sets: 
  (1539) ----$ Json "Lenderview_ForwardFits" 03-Feb-2015 07:35 AM 
  (1259) ----$ Joshi, issue fix." 26-Jun-2014 05:17 AM 
  (1260) ----$ Dinesh "changed and added new" 16-May-2014 05:24 AM 
There is additional history available before this point. 

Can i get the Work Item used for the Change set using JAVA or SCM? 
  (1539) ----$ Json "Code review changes" 03-Feb-2015 07:35 AM 




Your answer

Register or log in to post 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,937
× 369
× 70
× 6

Question asked: Oct 02 '14, 12:21 p.m.

Question was seen: 5,092 times

Last updated: Mar 27 '15, 6:20 p.m.

Confirmation Cancel Confirm