How to get Work Item Owner name from RTC Plain Java API
Accepted answer
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.
One other answer
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.
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/ ).
Good luck with your endeavors.
Ralph
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
Comments
Michael Plautz
Feb 18 '15, 3:29 p.m.Thanks @KevinRamer. That helps tremendously for the IContributorHandle details.
Kevin Ramer
Feb 18 '15, 4:09 p.m.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);
}
Michael Plautz
Feb 18 '15, 6:30 p.m.It works beautifully. I wondered how the heck to do an IAttribute lookup, since none of the IAttribute methods have any lookup capabilities.
Michael Plautz
Feb 19 '15, 9:10 a.m.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.
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Feb 19 '15, 9:41 a.m.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.