It's all about the answers!

Ask a question

How to get ITeamRepository and IWorkItemClient (in RTC follow-up action)?


1
1
Dmitry A. Lesin (24424493) | asked Mar 26 '14, 11:41 a.m.
edited Mar 26 '14, 11:42 a.m.
Hello everybody!
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


permanent link
sam detweiler (12.5k6189201) | answered Mar 26 '14, 1:18 p.m.
  because your code is a subclass of abstractService you have access to methods to load libraries

from another plugin
fWorkItemServer = getService(IWorkItemServer.class);
fAuditableCommon = getService(IAuditableCommon.class);
fcontributorService = getService(IContributorService.class);
fProcessServerService = getService(IProcessServerService.class);
fQueryService = getService(IQueryService.class);
fItemService = getService(IRepositoryItemService.class);

note that you must declare the need to access these other services in your plugin.xml
            <extensionService
                componentId="com.sd.tools.workitem.createapproval.participant.component"
                implementationClass="com.sd.tools.CreateApprovalParticipant">
                <prerequisites>
                 <requiredService interface="com.ibm.team.repository.common.service.IContributorService"/>    
            <requiredService interface="com.ibm.team.workitem.common.IAuditableCommon"/>         
            <requiredService interface="com.ibm.team.process.service.IProcessServerService"/>
            <requiredService interface="com.ibm.team.workitem.service.IWorkItemServer"/>
            <requiredService interface="com.ibm.team.repository.common.service.IQueryService"/>
            <requiredService interface="com.ibm.team.repository.service.IRepositoryItemService"/>  
                </prerequisites>
            </extensionService>

also all attributes, see here
https://jazz.net/forum/questions/94776/assertionfailedexception-problem-with-getting-the-values-of-attributes

routine
 private static void printResolved(IQueryClient queryClient, 
Dmitry A. Lesin selected this answer as the correct answer

Comments
Dmitry A. Lesin commented Mar 26 '14, 1:57 p.m. | edited Mar 26 '14, 2:00 p.m.

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!


sam detweiler commented Mar 26 '14, 2:19 p.m.

thank you for posting your usage for others!! 

One other answer



permanent link
sam detweiler (12.5k6189201) | answered Mar 26 '14, 12:17 p.m.
edited Mar 26 '14, 12:18 p.m.
 you are IN the repository..

most objects have a getOrigin() method which returns the repository..

see one of my plugins to do the rest .(or Ralph's blog) .post 2 has a working advisor to enforce depends/blocks
https://jazz.net/forum/questions/64268/operation-advisor-custom-precondition-for-work-items

Comments
Dmitry A. Lesin commented Mar 26 '14, 1:13 p.m. | edited Mar 26 '14, 1:15 p.m.

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!

Your answer


Register or to post your answer.