Why getOrigin() returns null on the server side
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
Comments
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?
It's possible that the origin wasn't set for the item. The documentation states it can return null if the origin is unknown.
Also, why do you need it? you have access to all the service you could want, as you are running IN the repository
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? :( :( :(
doesn't work the same in server side.
1 vote
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();