It's all about the answers!

Ask a question

Getting custom attributes names via Java API


Luca Martinucci (1.0k397112) | asked Sep 11 '12, 11:26 a.m.
I am trying to retrieve the list of custom attributes via Java API.
I've been able to retrieve a list of IAttributeHandle; can I get IAttribute from IAttributeHandle (in order to retrieve the name)?

Accepted answer


permanent link
Jared Russell (1.3k12019) | answered Sep 12 '12, 6:16 a.m.
 Based on Luca's comment, on the server side you can use the IRepositoryItemService class to achieve this.

IAttributeHandle handle = ...
IRepositoryItemService itemService = getService(IRepositoryItemService.class);
IAttribute attribute = (IAttribute) itemService.fetchItem(handle, IRepositoryItemService.COMPLETE);
Note that if you want to fetch a number of attribute handles you can use the IRepositoryItemService#fetchItems() method instead.
Luca Martinucci selected this answer as the correct answer

3 other answers



permanent link
Lauren Hayward Schaefer (3.3k11727) | answered Sep 11 '12, 11:57 a.m.
JAZZ DEVELOPER
Hi Luca,
The following code snippet should get you started:

com.ibm.team.workitem.common.model.IAttributeHandle handle = workItem.getCustomAttributes().get(0);
com.ibm.team.workitem.common.model.IAttribute attribute = (IAttribute) teamRepository.itemManager().fetchCompleteItem(handle, IItemManager.DEFAULT, new NullProgressMonitor());
System.out.println("The attribute id: " + attribute.getIdentifier());
System.out.println("The attribute name: " + attribute.getDisplayName());
System.out.println("The value of the custom attribute: " + workItem.getValue(attribute));

Comments
Luca Martinucci commented Sep 12 '12, 6:07 a.m.

Hi Lauren, your code is fine, but in order to get a teamRepository, I need to import the com.ibm.team.repository.client package. Instead, I am writing a server-side extension, so I can use only "common" and "service" packages. Any suggestion?


permanent link
Luca Martinucci (1.0k397112) | answered Sep 12 '12, 9:45 a.m.
Jared, it works!
Thanks for your answer!

permanent link
Canberk Akduygu (99237371) | answered Oct 09 '12, 3:50 a.m.
That worked for me too. Thank you very much. I have one question: I have a custom datefield which is a timestamp. When I try to set its value by using Plain Java libraries and java.sql.Timestamp object, there's no problem. But when I try to do the same operation in server side I get the error below.

Problem
An unhandled exception occurred during "Date Check Advisor".

java.sql.Timestamp incompatible with com.ibm.team.repository.common.IItemHandle

The Java code:

String str_date =

"11-June-13";

DateFormat formatter;

Date date =

new Date();

formatter =

new SimpleDateFormat("dd-MMM-yy");

try {

date = (Date) formatter.parse(str_date);

}

catch (ParseException e) {

}

java.sql.Timestamp timeStampDate =

new Timestamp(date.getTime());

newWorkItem.setValue(attribute, timeStampDate);


Your answer


Register or 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.