Enumeration literals for custom fields with RTC API on server side
Hello!
To get custom fields values, I use such code in my own Rational Team Concert follow-up action:
But all my experiments failed when I was trying to extract enumeration displayed values (or literals) for these fields. Here I can get the enumeration identifiers only but not literals. Does somebody knows how I could get them on the server side of my RTC custom extension?
Thank you very much in advance!
To get custom fields values, I use such code in my own Rational Team Concert follow-up action:
// Get custom attributes List<IAttributeHandle> wi_customs = wi.getCustomAttributes();
// Go through all work item fields
for (int i = 0; i < wi_customs.size(); i++) {
IAttribute attribute = (IAttribute) itemService.fetchItem(
wi_customs.get(i), IRepositoryItemService.COMPLETE);
String value = "";
// To avoid any problems with non-synchronized attributes
if (wi.hasAttribute(attribute)) {
Object objval = wi.getValue(attribute);
if (objval != null)
value = objval.toString();
}
attributes.add(new Attribute(attribute.getIdentifier(), value));
}
But all my experiments failed when I was trying to extract enumeration displayed values (or literals) for these fields. Here I can get the enumeration identifiers only but not literals. Does somebody knows how I could get them on the server side of my RTC custom extension?
Thank you very much in advance!
Accepted answer
You can access the data like this using IWorkItemCommn:
Also see https://rsjazz.wordpress.com/2012/08/20/manipulationg-work-item-enumeration-values/
fWorkItemCommon = getService(IWorkItemCommon.class); // Iterate the enumeration literals and create IEnumeration targetEnumeration = fWorkItemCommon .resolveEnumeration(enumerationAttribute, monitor); List literals = targetEnumeration .getEnumerationLiterals(); for (ILiteral targetLiteral : literals) { ....... }
Also see https://rsjazz.wordpress.com/2012/08/20/manipulationg-work-item-enumeration-values/
Comments
As far as I know you get the literal ID's and have to iterate the enumeration to get the display value.
the data stored in the database for the enumeration is the values ID.
As Ralph says,
you have to make additional calls to map the ID to the text string.
Thanks to everybody who was answering my question!
I only will do some additional remarks here for others. I hope, it will be useful as well.
1. To do working next string:
fWorkItemCommon = getService(IWorkItemCommon.class);
next prerequisite should be added into plugins.xml:
<requiredService
interface="com.ibm.team.workitem.common.IWorkItemCommon"/>
- To get the literal, I used next code:
IWorkItem wi;
...
Object objval = wi.getValue(attribute);
Identifier<? extends ILiteral> curId = (Identifier<? extends ILiteral>) objval;
String literalValue = findLiteralValueInEnumeration(curId, literals);
// Iterate the enumeration literals and search the needed
private String findLiteralValueInEnumeration(
Identifier<? extends ILiteral> id, List<ILiteral> literals) {
String result = null;
for (ILiteral targetLiteral : literals) {
Identifier<? extends ILiteral> curId = targetLiteral.getIdentifier2();
String dispValue = targetLiteral.getName();
if (curId.equals(id)) {
result = dispValue;
break;
}
}
return result;
}