It's all about the answers!

Ask a question

Why getOrigin() returns null on the server side


Dmitry A. Lesin (23412960) | asked Apr 01 '14, 9:34 a.m.
edited Apr 01 '14, 9:37 a.m.
Hello!
I can not go through an initial problem getting a reference to current repository object. I need it to get the additional libraries which could help me to work with workitem attributes. I try to get the repository object in this way:

...IWorkItem wi...
ITeamRepository repo = (ITeamRepository) wi.getOrigin();

I tried next services as prerequisites in plugin.xml:

<prerequisites>
<requiredService interface="com.ibm.team.workitem.service.IWorkItemServer"/>
<requiredService interface="com.ibm.team.repository.service.IRepositoryItemService"/>
<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"/>
</prerequisites>

But every time, I get null instead of an existing object! And the question is, which service could be declared to get non null repository object?

Thank you in advance!

Accepted answer


permanent link
sam detweiler (12.4k6177201) | answered Apr 01 '14, 9:54 a.m.
 because your plugin extends AbstractSerivce you have access to methods to load other libraries

fWorkItemServer = getService(IWorkItemServer.class);
fAuditableCommon = getService(IAuditableCommon.class);
fcontributorService = getService(IContributorService.class);
fProcessServerService = getService(IProcessServerService.class);
fQueryService = getService(IQueryService.class);
fItemService = getService(IRepositoryItemService.class);
Dmitry A. Lesin selected this answer as the correct answer

Comments
Dmitry A. Lesin commented Apr 01 '14, 10:33 a.m.

Thank you!
But in this case, is there a way to get non null team repository object with some another library? How can I get not null getOrigin?


Tim Mok commented Apr 01 '14, 10:44 a.m.
JAZZ DEVELOPER

It's possible that the origin wasn't set for the item. The documentation states it can return null if the origin is unknown.


sam detweiler commented Apr 01 '14, 10:49 a.m.

Also, why do you need it? you have access to all the service you could want, as you are running IN the repository 


Dmitry A. Lesin commented Apr 01 '14, 11:02 a.m. | edited Apr 01 '14, 11:02 a.m.

The plugin is an RTC follow-up action trigger which is called on saving a workitem. As for me, I need only to get a "FoundIn" attribute for a typical defect from Scrum process. I'm investigating a way like this:

IWorkItemClient client = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
if (projectArea != null) {
        IAttribute filedAgainst = client.findAttribute(projectArea, IWorkItem.FOUND_IN_PROPERTY, monitor);
}

But client variable requires repo parameter which I can not get now. May be my way is wrong, isn't it?  :(

I tried getOrigin() for current workitem and process area. Everywhere, it's null! But how can it be null, if I already connected to the repository?  :( :( :(


1
sam detweiler commented Apr 01 '14, 11:08 a.m. | edited Apr 01 '14, 11:09 a.m.

doesn't work the same in server side. 


private IWorkItemServer fWorkItemServer = getService(IWorkItemServer.class);
fWorkItemServer.findAttribute(projectArea, IWorkItem.FOUND_IN_PROPERTY, monitor); 


Dmitry A. Lesin commented Apr 01 '14, 11:50 a.m. | edited Apr 01 '14, 11:52 a.m.

Thank you very much! It really works. Finally produced code with getting the value for "FoundIn" attribute is next:

        ...IWorkItem wi...

        IWorkItemServer fWorkItemServer = getService(IWorkItemServer.class);
        IAttribute attr_foundIn = fWorkItemServer.findAttribute(projectArea,
                IWorkItem.FOUND_IN_PROPERTY, monitor);
        IDeliverableHandle wi_foundIn = (IDeliverableHandle) wi.getValue(attr_foundIn);
        IDeliverable foundIn = (IDeliverable) itemService.fetchItem(wi_foundIn,
                IRepositoryItemService.COMPLETE);
        ... = foundIn.getName();

showing 5 of 6 show 1 more comments

Your answer


Register or to post your answer.