How to get ITeamRepository and IWorkItemClient (in RTC follow-up action)?
I'm trying to extend an RTC with follow-up action plug-in. It works well but untill I try to get workitem attributes. How to do it, I found a lot of excellent articles including this one:
http://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/
But I stumble at the step when I need get ITeamRepository and IWorkItemClient objects. For example, I used such code:
IProcessArea procarea = operation.getProcessArea();
ITeamRepository teamRepository1 = (ITeamRepository) procarea.getOrigin();
IWorkItemClient workItemClient1 = (IWorkItemClient) teamRepository1.getClientLibrary(IWorkItemClient.class);
and another one:
IProjectAreaHandle projhndl = newState.getProjectArea();
ITeamRepository teamRepository2 = (ITeamRepository) projhndl.getOrigin();
IWorkItemClient workItemClient2 = (IWorkItemClient) teamRepository2.getClientLibrary(IWorkItemClient.class);
But every time, I have null for the teamRepository object! Can somebody say what is wrong? As far as I understand, follow-up action is called by RTC under a user which is already connected to the repository. Can I get an existing reference to this data from within RTC extention plug-in?
Thank you very much in advance for any advices!
Accepted answer
Comments
Thank you very much!
Yes, I understand now the internal work of the solution. You really helped me to clarify this!
But is somebody else will be wondered the exact way which I used, I applied next code:
List<IAttributeHandle> wi_customs = wi.getCustomAttributes();
IRepositoryItemService itemService = getService(IRepositoryItemService.class);
for (int i = 0; i < wi_customs.size(); i++) {
IAttribute attribute = (IAttribute) itemService. fetchItem(wi_customs.get(i), IRepositoryItemService.COMPLETE);
<some operations with attribute>
}
And don't forget (as Sam pointed above) add next string manually into plugin.xml of service plugin project:
<requiredService interface="com.ibm.team.repository.service.IRepositoryItemService"/>
By the way, the solution is described here:
https://jazz.net/forum/questions/87341/how-to-fetch-the-workitem-built-in-custom-attribute-id-and-value
The conclusion - no need to apply ITeamRepository and IWorkItemClient here!
thank you for posting your usage for others!!
One other answer
Comments
Sam,
Thank you for quick reply!
You write "most objects have a getOrigin() method which returns the repository". But I used getOrigin() for IProcessArea and IProjectAreaHandle objects which I found through class declarations. And everywhere getOrigin() returns null as if I'm out of the repository. This case strongly confuses me!
To make clear my end point, I need to get a list of all attributes for a workitem resulting from saving operation for this workitem. To get these attributes, I presume to use some code like next:
IWorkItemClient workItemClient = (IWorkItemClient) fTeamRepository.getClientLibrary(IWorkItemClient.class);
IAttribute someAttribute= workItemClient.findAttribute(fProjectArea, "some_attribute_ID", monitor);
But I can not get fTeamRepository which is always null!