It's all about the answers!

Ask a question

How to retrieve complex custom attribute of a Workitem.


Canberk Akduygu (99237371) | asked Oct 08 '12, 6:58 a.m.

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?


Comments
pugazhenthi samidurai commented Oct 08 '12, 8:11 a.m.

Hi canberk,

whats the type of  "deployment.component" attribute?


Canberk Akduygu commented Oct 08 '12, 8:28 a.m.

Type is an "Item".

Also those codes were for the Plain Java Library. I also need to convert "findByAttribute" method to server side. How can I achieve that?

IAttribute attribute2 = workItemClient.findAttribute(projectArea,"deployment.component", null); This is not working for Server Side plugin as it's using client side codes. I couldnt find the server side method for fetching attributes


pugazhenthi samidurai commented Oct 09 '12, 9:54 a.m.

more information given by Canberk,

I created an attribute where I can set a "component". The reason I do that is for my release management. People will search workitems and find what other works re in progress on a specific component. So when I receive the value from getvalue(IAttribute) method, I receive a object which contains the component information.

So I need to cast this object to a Component and receive its name somehow. Thank you for the help but that doesnt help me :(

One answer



permanent link
Ralph Schoon (63.0k33645) | answered Oct 09 '12, 9:57 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Oct 09 '12, 9:59 a.m.
Canberk,

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.

Your answer


Register or to post your answer.