How to get Work Item Owner name from RTC Plain Java API
![]()
I have been able to use the RTC Plain Java Client API to successfully connect to a repository, list all of the project areas, and then list all of the work items within a project area.
One of the last things I am trying to figure out is how to get all of the following information:
Story/Task ID #: IWorkItem.getId()
Parent ID #: (I'm not sure how to get the links to a work item, but specifically the "Parent" link)
Story Points: ? (Is this an attribute?)
Title: IWorkItem.getHTMLSummary()
Description/Acceptance Criteria: IWorkItem.getHTMLDescription()
Owned By: IWorkItem.getOwner()
(As you can see, the Parent ID and Story Points are two that I do not know about).
Specifically, for the IWorkItem.getOwner() method, it returns an object of time IContributorHandle. When I go through the JavaDoc for IContributorHandle, I see that it is an object that only has public methods entirely inherited from the IItemHandle class. None of these methods list anything like getName() for instance. When I simply do IContributorHandle.toString(), I get a string of some of the field details, but they only include the state UUID, the item UUID, the origin, and its immutibility.
How do I get the name of the contributor (or an object that has that info) from this IContributorHandle object?
(And of course to save me the trouble, how do I get the Parent Work Item and Story Points as well?)
|
Accepted answer
![]()
I've seen this handy snippett:
IContributor contributor = (IContributor) teamRepository.itemManager() .fetchCompleteItem(handle, IItemManager.DEFAULT, null); String userID=contributor.getUserId(); teamRepository is ITeamRepository class and you probably have one in-hand. I'll let others chime in on the links. Story points is an enumeration type whose id is: com.ibm.team.apt.attribute.complexity. Ralph Schoon selected this answer as the correct answer
|
One other answer
![]()
Ralph Schoon (63.3k●3●36●46)
| answered Feb 19 '15, 3:01 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I would suggest to read https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ carefully to understand the structure better and to understand what handles are (basically a thing you can get the object) and the object itself, how to get them etc.
Comments With respect to IAttributes https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/ should add more info.
Finally, you can also search that blog (and the whole internet/the Jazz.net site), so if you have a Java Class, you can often find related posts and examples. The search https://www.google.com/search?q=owner+api+IContributorHandle+site:jazz.net lists a couple of correct answers.
Thank you @rschoon, this post actually helped me put things into better perspective. The answer that @KevinRamer gave did exactly what your post was talking about. It uses the teamRepository's itemManager() to fetch the complete item. This applies to the IContributor/IContributorHandle and IWorkItem/IWorkItem handle relationships. The IItemManager.DEFAULT and IItemManager.REFRESH is an important thing to know to. In my case, I am just using lookups, so I will not ever need for things to refresh, but if I were modifying and creating stories, then the refresh is important to know.
To give an in context answer for how to get the parent of a work item, given a team repository and a work item object, this is how you get the parent work item:
final ILinkManager linkManager = (ILinkManager) teamRepository.getClientLibrary(ILinkManager.class); IReference workItemRef = linkManager.referenceFactory().createReferenceToItem(workItem); ILinkQueryPage queryPage = linkManager.findLinksBySource(WorkItemLinkTypes.PARENT_WORK_ITEM, workItemRef, monitor); java.util.Collection<ilink> links = queryPage.getAllLinksFromHereOn(); for (ILink l : links) { IItemHandle linkHandle = (IItemHandle) l.getTargetRef().resolve(); if (linkHandle instanceof IWorkItemHandle) { IWorkItem parentItem = (IWorkItem) teamRepository.itemManager().fetchCompleteItem(linkHandle, IItemManager.DEFAULT, monitor); } } Michael, you probably want to search my blog https://rsjazz.wordpress.com/ next time around. There is a good chance that you will find code for the most common use cases, including code like the above (e.g. in https://rsjazz.wordpress.com/2012/09/19/the-rtc-workitem-link-api-linking-workitems-to-other-elements/ ).
Oh, and to get an (almost) complete set of API examples for almost everything with respect to work item manipulation, see https://rsjazz.wordpress.com/2015/02/13/the-workitem-command-line-explained/ the code downloadable from the linked post does most of the tricks you want to know in the com.ibm.js.team.workitem.commandline.helper.WorkItemHelper
showing 5 of 6
show 1 more comments
|
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.
Comments
Thanks @KevinRamer. That helps tremendously for the IContributorHandle details.
I'm guessing that one could get the attribute by that ID, then get its value. Story Points is one of the rare items whose value is really a value, not an identifier, ok it is an identifier, but it's a numeric string.
I use this:
IWorkItemClient service = getWorkItemClient();
// IProjectAreaHandle area
// String attributeId -- "com.ibm.team.apt.attribute.complexity"
IAttribute attribute = service.findAttribute(area, attributeId, null);
private IWorkItemClient getWorkItemClient() {
return (IWorkItemClient)repository.getClientLibrary(
IWorkItemClient.class);
}
It works beautifully. I wondered how the heck to do an IAttribute lookup, since none of the IAttribute methods have any lookup capabilities.
Also Kevin (@yzwkzfn), is the Story Points ("com.ibm.team.apt.attribute.complexity") attribute documented anywhere? That was very helpful but it was also the first I had ever heard of it.
Michael,
The complexity attribute can be customized. The various templates define something e.g. the story work item type with a story points attribute in the scrum template. If you click on the story points attribute it in the work item types and attributes editor, for work item type story it shows the "com.ibm.team.apt.attribute.complexity" as external ID. Which one to use in planning is then configured in the planning section - you select th one - story points is preselected in scrum.