How to get value from Custom Attribute?
I am using number of Custom Attributes in my code. I am using following types of Custom Attributes,
String, Contributor, Category and Boolean
I am able to get values from Custom Attribute whose type is String and Boolean, but for others I am getting objects. Can anyone please help me? Here is the code,
//here Custom Attribute(owner) is of type Contributor
myattr = workItemCommon.findAttribute(workItem.getProjectArea(), "owner", monitor);
owner = (ContributorHandleImpl) workItem.getValue(myattr);
//here Custom Attribute(groupOwner) is of type Category
myattr = workItemCommon.findAttribute(workItem.getProjectArea(), "groupOwner", monitor);
groupOwner = (CategoryHandleImpl) workItem.getValue(myattr);
How can I get value from owner and groupOwner?
Accepted answer
You can guess the type you have to cast to or you use the debugger to see it. This is also explained above together with https://rsjazz.wordpress.com/2013/02/28/setting-up-rational-team-concert-for-api-development/ .
You can also use the search field in the blog to search for things like Contributor.
You will get an object that you have to cast to, an IContributorHandle for owner attributes you have to cast to and the resolve it, an ICathegoryHandle for type Category and a Boolean (not boolean).
Comments
Hello Ralph,
Thanks for the quick reply. I already tried code on that blog. Please find code,
ContributorHandleImpl owner;
CategoryHandleImpl groupOwner;
//here Custom Attribute(owner) is of type Contributor
myattr = workItemCommon.findAttribute(workItem.getProjectArea(), "owner", monitor);
owner = (ContributorHandleImpl) workItem.getValue(myattr);
//here Custom Attribute(groupOwner) is of type Category
myattr = workItemCommon.findAttribute(workItem.getProjectArea(), "groupOwner", monitor);
groupOwner = (CategoryHandleImpl) workItem.getValue(myattr);
I am not getting, how to get values from 'owner' and 'groupOwner'.
Read the answer above again.
Please be aware that the API uses EMF which generates the interfaces e.g. ICathegoryHandle and an implementation CategoryHandleImpl which is then implemented. You want to cast to the interface ICathegoryHandle .
As explained in https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ the handle needs to be resolved. See that post.