Problem in accessing enumeration in work item using client java API
I am trying to get value of enumeration literal using java API. I referred this link to access enumeration values using java API.
but when I use IAttribute to fetch required attribute I am getting Null pointer exception.
IAttribute someAttribute= workItemClient.findAttribute(projectareahandle, "severity", null);
value of someAttribute variable in null.
IAttribute someAttribute= workItemClient.findAttribute(projectareahandle, "com.ibm.team.workitem.attribute.severity", null);
this code snippet also return value of someAttribute as null. Therefore further part of code is not executed.
Is there any other way to fetch attribute of type enumeration. Or am I doing something wrong here,?
following is complete code snippet of my program
IProjectAreaHandle projectareahandle = projectArea.getProjectArea();
IWorkItemClient workItemClient = (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);
IWorkItem work = workItemClient.findWorkItemById(id, IWorkItem.FULL_PROFILE, null);
IWorkItem workcopy = (IWorkItem)work.getWorkingCopy();
IAttribute someAttribute= workItemClient.findAttribute(projectareahandle, "severity", null);
Object value = workcopy.getValue(someAttribute);
if(value instanceof Identifier)
{
Identifier literalID = (Identifier) value;
IEnumeration enumeration = workItemClient.resolveEnumeration(someAttribute, null);
List literals = enumeration.getEnumerationLiterals();
for (Iterator iterator = literals.iterator(); iterator.hasNext();)
{
ILiteral iLiteral = (ILiteral) iterator.next();
if (iLiteral.getIdentifier2().equals(literalID))
{
String displayvalue = iLiteral.getName();
System.out.println("its value is "+displayvalue);
}
}
}
in someAttribute value fetched is null therefore further part is not executed.
Accepted answer
Comments
Hi Ralph,
Question here is about fetching attribute of type enumeration,
When following line of code is executed
IAttribute someAttribute= workItemClient.findAttribute(projectareahandle, "severity", null);
value of someAttribute variable is null.
this also happens when I pass complete Id as follow
IAttribute someAttribute= workItemClient.findAttribute(projectareahandle, "com.ibm.team.workitem.attribute.severity", null);
It is working fine when i pass attribute id of other attributes. Problem is when I pass Id of enumeration type attribute.
This works for me. Of course you have to pass a valid ID for the enumeration type attribute and not one that is not available. You also want to read carefully: https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/ and consider hasAttribute(). Of course that also requires the attribute to be found and thus a valid ID to be passed in findAttribute(). Or iterate the attributes available and get the ID's. Or use A RTC WorkItem Command Line Version 3.0 to print the available attribute ID's.
Hi Ralph,
When I passed "internalSeverity" as attribute Id it worked for me.
I don't know why it was not working when I was passing attribute Id as "com.ibm.team.workitem.attribute.severity" I got this attribute Id when we look up in the process configuration tab.
Any particular reason behind it?
I don't know. That ID - which also only shows up in the Eclipse client, the Web UI shows internalSeverity does not work for me either. So I don't know. In the WCL I created a mapping for these ID's - to map them to their internal ID. So I would suggest to use the ID's shown in the Web Admin UI.
Feel free to write a defect for this.
Hi Ralph,
Thank you for all your effort.