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

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?)

0 votes

Comments

 Thanks @KevinRamer. That helps tremendously for the IContributorHandle details. 


I do not totally comprehend how to use the information on the story points. Is this something I use with IWorkItem.getValue()? Because in the JavaDoc, I do not even see a java package named com.ibm.team.apt.attribute.complexity, nor a class named Complexity.

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. 


When I do the IWorkItem.getValue(IAttribute) method using the above approach to obtain the correct IAttribute, I get an Object back that identifies itself as an ILiteral (via toString) but is actually an com.ibm.team.workitem.common.model.Identifier.

@KevinRamer, if you would like to receive credit for the answer, feel free to extract out what you said and make in an answer and I'll mark it right. Otherwise I'll post an answer when I have all three - I'm still working on the links/parent work item thing.

 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.


Accepted answer

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

1 vote


One other answer

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

1 vote

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/ ).

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

showing 5 of 6 show 1 more comments

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

Question asked: Feb 18 '15, 2:59 p.m.

Question was seen: 8,075 times

Last updated: Feb 19 '15, 9:41 a.m.

Confirmation Cancel Confirm