How to retrieve complex custom attribute of a Workitem.
We have custom workitems in RTC and custom attributes attached to those workitems.
We are trying to retrieve a custom attribute's value by using JAVA API. We can retrieve the value of custom attributes like Timestamp,string etc. But when iit comes to retrieve the value of a complex attribute which holds a component as Item,it's hard to retrieve the value.
We are using this piece of code:
IAttribute attribute2 = workItemClient.findAttribute(projectArea,"deployment.component", null);
Object obj2 = workItem2.getValue(attribute2);
We get the object and if we print it we have
"com.ibm.team.scm.common.internal.impl.ComponentHandleImpl@ead0ead (stateId: <unset>, itemId: [UUID _LlT-wBEPEeKQ4PpX4404og], origin: com.ibm.team.repository.client.internal.TeamRepository@128c128c, immutable: true)"
How can we cast this object to a component?
One answer
you will always get an object back if you get a value. You have to find out which type the object is. This is fairly simple during debugging.
See for example how to get enumeration variables http://rsjazz.wordpress.com/2012/08/20/manipulationg-work-item-enumeration-values/
The code in the other answer is absolutely correct and the usual way to resolve work items, and get attributes by their ID and use that to get the value. The cast is also typical.
There is - as far as I can tell - no built in type for components. So it is either a string or something completely custom. In the first case you should be able to cast it to String and in the latter, you are in the best position to tell which type it actually is.
Comments
pugazhenthi samidurai
Oct 08 '12, 8:11 a.m.Canberk Akduygu
Oct 08 '12, 8:28 a.m.pugazhenthi samidurai
Oct 09 '12, 9:54 a.m.