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

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

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!

1

1 vote


Accepted answer

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

0 votes

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

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

0 votes

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!

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,939

Question asked: Mar 26 '14, 11:41 a.m.

Question was seen: 5,853 times

Last updated: Mar 26 '14, 2:19 p.m.

Confirmation Cancel Confirm