How to retrieve enumeration values from a multi-select field
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
3 answers
- 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.
- 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.
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.
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.
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;
}}
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 ?
This shows what worked for me in 3.x-4.x so far: http://rsjazz.wordpress.com/2012/08/20/manipulationg-work-item-enumeration-values/
I will have to update my sample to handle the string version of the enum
Comments
sam detweiler
Jan 02 '13, 10:23 a.m.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.
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Jan 02 '13, 10:39 a.m.Hi Sam,
I don't understand
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?
sam detweiler
Jan 02 '13, 2:48 p.m.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