It's all about the answers!

Ask a question

Problem in accessing enumeration in work item using client java API


vikrant kamble (1323897) | asked Nov 09 '15, 1:31 a.m.
edited Nov 09 '15, 1:36 a.m.
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


permanent link
Ralph Schoon (63.6k33646) | 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
vikrant kamble commented Nov 09 '15, 2:38 a.m. | edited Nov 09 '15, 2:39 a.m.

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.


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,
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?


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.


Ralph Schoon commented Nov 09 '15, 4:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Feel free to write a defect for this.



vikrant kamble commented Nov 09 '15, 5:23 a.m.

Hi Ralph,
Thank you for all your effort.

showing 5 of 7 show 2 more comments

Your answer


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