Problem in accessing enumeration in work item using client java API
HI All,
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.
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
So what is the question? Note that you have to provide a valid attribute ID for the code to even work. The ID for Severity is com.ibm.team.workitem.common.model.IWorkItem.SEVERITY_PROPERTY which returns "internalSeverity". The ID you can look up in the process configuration is "com.ibm.team.workitem.attribute.severity" which you also should be able to use.
Comments
showing 5 of 7
show 2 more comments