Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How to retrieve enumeration values from a multi-select field

Hi

I have been trying to find out a way of getting the actual values for a multi select attribute in RTC version 3.0.1

The attribute has been set up as Large String type with enumeration as Key in the presentation and the attribute kind is multi select list in the presentation.

I have been trying the following code
IAttribute ia = workItemServer.findAttribute(workItem.getProjectArea(),attributeId,null);
EnumerationManager enumerationManager = new EnumerationManager(workItemServer.getAuditableCommon());
enumerationManager.internalResolve(workItem.getProjectArea(), ia.getAttributeType(), monitor);

This gives exception AssertionFailed as the attribute is not of type Enumeration. Appreciate if you can please provide an example of sample code that can be used to get this sorted.

Thanks in advance


however this fails to get the enumeration handle as




0 votes

Comments

as mentioned, this is not an enumeration in practice, but a string.. so you handle it like a string. (If you use my code, it attempts to get the enum, and the catch() processes non-enumerations..)..

then it is a string.. and a string is a string.. 

the multi-select presentation just stores the literals in the string separated by semi-colon (';')  this was a hack solution, and IBM said so.. and replaced it with something in 4.x.. but it is also a different kind of hack.  cause the values are in an external database, and harder to manage/manipulate/etc from extension code.

Hi Sam,

I don't understand

but it is also a different kind of hack.  cause the values are in an external database, and harder to manage/manipulate/etc from extension code.

As far as I understand the new attribute type that is available is a list type for enumerations (as well as other basic data types). You can use it with enumerations that are backed by the database as well as with the ones stored in the template.

So where is the issue?

I can't change my post.. I updated my sample to handle the V4 multi-select..
it is a list.. (still of the literals)  when it is stored in the process config



3 answers

Permanent link
As far as I can tell, this depends on how the attribute is actually set up.

  1. In the past, you had to use a string type attribute and the multi selection was actually done by the presentation.The values stored where the enumeration literals, separated by a , or ;. You can tell from looking at a query if you display the attribute. 
  2. Since 4.x there seems to be a new attribute type (Enumeration List). I have only remotely played with that one, but I assume the data is stored in the database and you would get a list of objects that are enumeration literals.

So for option 1, I assume you have to cast to a string and then you need to split() the string using the separator. You can use means like in this post to get the enumeration literals from the string.

For the other option I would try to cast to List and then look into the list you retrieve.

I would always use if(object instanceof SomeClassOrInterface) to test before I cast. During debugging it should also be possible to determine the type.





0 votes

Comments

Hi Ralph

Many thanks for suggesting the solution.

I tried the 1st Option as we have the version 3, however when it reaches this if condition, the value(workItem.getValue(iAttribute)) seems to be of instance String and not an identifier and does not go inside the if body.

if (value instanceof Identifier) {
    Identifier literalID = (Identifier) value;
    ILiteral literal = getLiteralbyID(literalID, iAttribute);
    String displayValue = literal.getName();
}


I have tried the version that you mentioned for in case of string. But however using just the below:

ILiteral literal= (ILiteral)iAttribute.getValue(auditableCommon,workItem,null);
String result = literal.getName();

displays only the literal name which is "access_level_rqm.literal.l2" and not the actual value.

Appreciate your help.

As Sam and I were saying:

  • you get a string, the string contains the literal(s) as a string.
  • The Literal string representations are seperated by ;
  • You can split them with myValueString.split(";").
    • That with some trim should get you the string representation of the literal.
  •  To get the literal you will have to look into the blog post I mentioned and iterate over the literals of the enumeration.
    • You compare the string you got from the split to the string representation of the literal
      • If you find one with the same string representation as the literal you are looking at, you have the ILiteral.
      • From that you can get the other data.
The reasons for that are all answered in this post already.

Hi Ralph & Sam

Thanks a lot for the explanation.

 I have already tried the above option of getting the string out and comparing it with the literals from enumeration. The issue is that since attribute is not an instance of enumeration(its a multi select list implemented as string using enumeratoin presentation version 3) it fails at the creation of the enumeration object.IEnumeration<? extends ILiteral> enumeration = workItemServer.resolveEnumeration(ia,null);
the above throws assertion error, also tried the version I mentioned the very first which is getting the enumerationmanager and calling internalresolve().EnumerationManager enumerationManager = new EnumerationManager(workItemServer.getAuditableCommon());enumerationManager.internalResolve(workItem.getProjectArea(), ia.getAttributeType(), monitor);This is the case of a version 3. Is there a way to get the IEnumeration object created ? Or is it some other way that we need to get the the value corressponding to a literal other than using the enumeration object?ILiteral literal= (ILiteral)iAttribute.getValue(auditableCommon,workItem,null);
String result = literal.getName();

I see the problem. The knowledge about the enumeration in use is in the presentation, so you have to put some knowledge in your extension to find it. Since Sam seems to have done that already, I leave it to him to answer.


Permanent link
once u have the literal, there is one more step, matching it with a value..

from my prior code post

  List<iliteral> enumerationLiterals = enumeration
                                        .getEnumerationLiterals();
                                for (ILiteral literal : enumerationLiterals)
                                {
                                    if (literal.getIdentifier2()
                                            .getStringIdentifier()
                                            .equalsIgnoreCase(iaval[1]))
                                    {
                                        System.out
                                        .println("\t\t\t\t --> attribute name="
                                                + ia.getIdentifier()
                                                + ", type"
                                                + "="
                                                + ia.getAttributeType()
                                                + " literal="
                                                + literal
                                                .getIdentifier2()
                                                .getStringIdentifier()
                                                + " literal name="
                                                + literal.getName());
                                        break;
}}

0 votes

Comments

Getting the enumeration objacte as below

.IEnumeration<? extends ILiteral> enumeration = workItemServer.resolveEnumeration(ia,null);

throws assertion error, also tried the version I mentioned the very first which is getting the enumerationmanager and calling internalresolve().EnumerationManager enumerationManager = new EnumerationManager(workItemServer.getAuditableCommon());enumerationManager.internalResolve(workItem.getProjectArea(), ia.getAttributeType(), monitor)

This is the case of a version 3.

Is there a way to get the IEnumeration object created ?

I will have to update my sample to handle the string version of the enum


Permanent link
According to support, this code only works in 4.x

0 votes

Your answer

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

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938

Question asked: Jan 02 '13, 10:04 a.m.

Question was seen: 5,683 times

Last updated: Jan 24 '13, 12:37 p.m.

Confirmation Cancel Confirm