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. |
Accepted answer
Ralph Schoon (63.6k●3●36●46)
| answered Nov 09 '15, 2:20 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER edited Nov 09 '15, 2:50 a.m.
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.
vikrant kamble selected this answer as the correct answer
Comments Hi Ralph,
Ralph Schoon
commented Nov 09 '15, 2:48 a.m.
| edited Nov 09 '15, 2:51 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.
vikrant kamble
commented Nov 09 '15, 4:09 a.m.
Hi Ralph,
Ralph Schoon
commented Nov 09 '15, 4:27 a.m.
| edited Nov 09 '15, 4:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.
vikrant kamble
commented Nov 09 '15, 5:23 a.m.
Hi Ralph,
showing 5 of 7
show 2 more comments
|
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.