It's all about the answers!

Ask a question

Enumeration literals for custom fields with RTC API on server side


Dmitry A. Lesin (24826996) | asked Sep 15 '14, 1:10 a.m.
edited Sep 15 '14, 1:11 a.m.
Hello!
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


permanent link
Ralph Schoon (63.5k33646) | answered Sep 15 '14, 3:02 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You can access the data like this using IWorkItemCommn:
		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/
Dmitry A. Lesin selected this answer as the correct answer

Comments
Ralph Schoon commented Sep 15 '14, 3:04 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

As far as I know you get the literal ID's and have to iterate the enumeration to get the display value.


sam detweiler commented Sep 15 '14, 7:48 a.m.

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.





Dmitry A. Lesin commented Sep 16 '14, 1:20 p.m.

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"/>



Dmitry A. Lesin commented Sep 16 '14, 1:22 p.m. | edited Sep 16 '14, 1:23 p.m.
  1. 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;
    }

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.