It's all about the answers!

Ask a question

How to get enumeration value


silencehill wu (5022432) | asked Dec 26 '13, 12:00 p.m.

I am writing program  to get enumeration values by http client using OSLC-CM 2.0.

I want to know how I can get all id and name of enumeration by OSLC-CM 2.0 in java api.

For example:

      <enumeration attributeTypeId="bugtype" name="bugproblemtype">
           <literal id="bugtype.literal.l1" name="CA-用例缺陷"/>
           <literal id="bugtype.literal.l2" name="DOC-文档错误"/>
           <literal id="bugtype.literal.l3" name="EC-编码错误"/>

    </enumeration>

1. I want to get a map <id, name> of enumeration.

  AttributeTypeId ="bugtype"  or  name ="bugproblemtype" as argument. I want to get the map as below:

  <bugtype.literal.l1, CA-用例缺陷>, <bugtype.literal.l2, DOC-文档错误>, <bugtype.literal.l3, EC-编码错误>

2. I want to get a id by name

Input CA-用例缺陷 as argument, the id  bugtype.literal.l1 will be return.

Please give me an advise.

Accepted answer


permanent link
Sterling Bates (2311612) | answered Dec 27 '13, 6:37 p.m.
If you already have the IAttribute instance you can get the IEnumeration this way:

IWorkItemClient svc = (IWorkItemClient)teamrepo.getClientLibrary(IWorkItemClient.class);
IEnumeration<ILiteral> enum = (IEnumeration<ILiteral>)svc.resolveEnumeration(attribute, null);
List<ILiteral> literals = enum.getEnumerationLiterals();

Now, you said both HTTP (meaning REST?) and Java API, this is just the Java API method.
silencehill wu selected this answer as the correct answer

Comments
silencehill wu commented Dec 29 '13, 11:18 a.m.

Thank for your answer. I am using java plain api, but not using RTC-SDK. The REST is the only way now I want to know. Do you have any idea? 

Your answer


Register or to post your answer.