It's all about the answers!

Ask a question

Programmatic custom enumerations


0
1
Susan Hanson (1.6k2201194) | asked Jan 18 '11, 9:16 a.m.
This is my first foray into Custom Enumerations with the SDK, and I hit a problem I'm not sure what is ...

After I login and get the workItemClient, I attempt to get the values of a custom enumeration where the attributeTypeId = "themeEnum" and the name = "themeEnum".

So I went to findAttribute of the "themeEnum" which is the ID in the process configuration source, and then
IAttribute attribute0= workItemClient.findAttribute(myProjectArea, "themeEnum", monitor);
IEnumeration<?> enumeration= workItemClient.resolveEnumeration(attribute0, monitor);

Eventually, I need to map a string value passed in through these enumerationLiterals to be able to set the enumeration programmatically.

However, I am getting a NullPointer:
Exception in thread "main" java.lang.NullPointerException
at com.ibm.team.workitem.client.internal.AuditableClient.resolveAuditable(AuditableClient.java:134)
at com.ibm.team.workitem.common.internal.EnumerationManager.resolve(EnumerationManager.java:168)
at com.ibm.team.workitem.common.internal.WorkItemCommon.resolveEnumeration(WorkItemCommon.java:453)
at com.ibm.ws.build.rtc.OpenFeature.main(OpenFeature.java:68)


I'm not sure what could be wrong since I have so very little code so far.
Susan

7 answers



permanent link
Eduardo Bello (4401922) | answered Jan 18 '11, 9:40 a.m.
Did you check if attribute0 is null? If findAttribute method didn't find any attribute with the name "themeEnum", will return null.

This is my first foray into Custom Enumerations with the SDK, and I hit a problem I'm not sure what is ...

After I login and get the workItemClient, I attempt to get the values of a custom enumeration where the attributeTypeId = "themeEnum" and the name = "themeEnum".

So I went to findAttribute of the "themeEnum" which is the ID in the process configuration source, and then
IAttribute attribute0= workItemClient.findAttribute(myProjectArea, "themeEnum", monitor);
IEnumeration<?> enumeration= workItemClient.resolveEnumeration(attribute0, monitor);

Eventually, I need to map a string value passed in through these enumerationLiterals to be able to set the enumeration programmatically.

However, I am getting a NullPointer:
Exception in thread "main" java.lang.NullPointerException
at com.ibm.team.workitem.client.internal.AuditableClient.resolveAuditable(AuditableClient.java:134)
at com.ibm.team.workitem.common.internal.EnumerationManager.resolve(EnumerationManager.java:168)
at com.ibm.team.workitem.common.internal.WorkItemCommon.resolveEnumeration(WorkItemCommon.java:453)
at com.ibm.ws.build.rtc.OpenFeature.main(OpenFeature.java:68)


I'm not sure what could be wrong since I have so very little code so far.
Susan

permanent link
Susan Hanson (1.6k2201194) | answered Jan 18 '11, 10:26 a.m.
Yes .. I had already somewhat determined that it was because it didn't find a "themeEnum" attribute, but I have double-checked in my project project process config that the name and attributeTypeId both are "themeEnum".

Susan


Did you check if attribute0 is null? If findAttribute method didn't find any attribute with the name "themeEnum", will return null.

This is my first foray into Custom Enumerations with the SDK, and I hit a problem I'm not sure what is ...

After I login and get the workItemClient, I attempt to get the values of a custom enumeration where the attributeTypeId = "themeEnum" and the name = "themeEnum".

So I went to findAttribute of the "themeEnum" which is the ID in the process configuration source, and then
IAttribute attribute0= workItemClient.findAttribute(myProjectArea, "themeEnum", monitor);
IEnumeration<?> enumeration= workItemClient.resolveEnumeration(attribute0, monitor);

Eventually, I need to map a string value passed in through these enumerationLiterals to be able to set the enumeration programmatically.

However, I am getting a NullPointer:
Exception in thread "main" java.lang.NullPointerException
at com.ibm.team.workitem.client.internal.AuditableClient.resolveAuditable(AuditableClient.java:134)
at com.ibm.team.workitem.common.internal.EnumerationManager.resolve(EnumerationManager.java:168)
at com.ibm.team.workitem.common.internal.WorkItemCommon.resolveEnumeration(WorkItemCommon.java:453)
at com.ibm.ws.build.rtc.OpenFeature.main(OpenFeature.java:68)


I'm not sure what could be wrong since I have so very little code so far.
Susan

permanent link
Eduardo Bello (4401922) | answered Jan 18 '11, 12:03 p.m.
You may try something like this following code, to list all attributes, then see if "themeEnum" appears


List<IAttribute> listAttributes = workItemClient.findAttributes(myProjectArea, monitor);
for (IAttribute attribute : listAttributes) {
System.out.println(attribute.getIdentifier()); // or getDisplayName()
}


Yes .. I had already somewhat determined that it was because it didn't find a "themeEnum" attribute, but I have double-checked in my project project process config that the name and attributeTypeId both are "themeEnum".

Susan

permanent link
Susan Hanson (1.6k2201194) | answered Jan 18 '11, 12:26 p.m.
I believe I am starting to see the error of my ways :-)

List<IAttribute> attribList = workItemClient.findAttributes(myProjectArea, myMonitor));
for (int y=0;y<attribList.size();y++) {
IAttribute ia = attribList.get(y);
if (ia.getDisplayName().equals("Requirement Number")) {
workItem.setValue(ia,reqNumber);
}

So here, I am able to get all the attributes, including custom ones, and list them, and even set them as long as they are not enumerations (so far). I do believe that my original problem stemmed from the fact that my Enumeration is called themeEnum but the actual attribute in my workItem is "releaseTheme" which then pulls the value to display from the themeEnum. So now I just need to determine how to set:
1) the value into a field whos values come from an Enumeration
2) the same as above for a multi-select field.

So I'm off reading more doc .. but I'm good so far! Thanks for the help!
Susan

You may try something like this following code, to list all attributes, then see if "themeEnum" appears


List<IAttribute> listAttributes = workItemClient.findAttributes(myProjectArea, monitor);
for (IAttribute attribute : listAttributes) {
System.out.println(attribute.getIdentifier()); // or getDisplayName()
}


Yes .. I had already somewhat determined that it was because it didn't find a "themeEnum" attribute, but I have double-checked in my project project process config that the name and attributeTypeId both are "themeEnum".

Susan

permanent link
Susan Hanson (1.6k2201194) | answered Jan 18 '11, 8:12 p.m.
I am attempting to create a WorkItem programmatically, and I have almost all of it completed. My last item is to set the value into a field which is backed by an Enumeration. (forgive me if my terminology is off).

I am able to create my WorkItem via the Eclipse client and then "dump" the data out programmatically. My "dump" shows this:
Quality Attributes : qualityAttributes.literal.l6,qualityAttributes.literal.l12

my attribute display name is "Quality Attributes" and it is displayed as a multi-select list in the UI, and it has 2 items "selected", hence you see the literal.l6 and l12.

Programmatically, what I have is the display of those literals, basically "Capability" and "Documentation". I can easily go into my process config and hardcode into my java that "if display.equals("Capability") then use "qualityAttributes.literal.l6", but I was hoping to be able to get all of the Enumeration items, and compare the display name to what I need, and then use that literal value.

I've tried a couple things that I have found in the forums, but nothing quite works to get what I need, which is all available items defined in the Enumeration itself, not the values of a specific attribute. As well, I had a hard time finding a way to go from the displayName to the literal value, instead of the other way around (which seems rather easy).

Susan

permanent link
Eduardo Bello (4401922) | answered Jan 19 '11, 7:48 a.m.
I'm not sure if I did understand it right... I think that you need an ILiteral object. This piece of code might help you to figure out

I suppose you already have an IAttribute object, found with findAttribute() method.




IEnumeration<ILiteral> enumeration= (IEnumeration<ILiteral>)workItemClient.resolveEnumeration(attribute, monitor);
List<ILiteral> enumerationLiterals = enumeration.getEnumerationLiterals();
for (ILiteral literal : enumerationLiterals) {
System.out.println(literal.getIdentifier2().getStringIdentifier() + ' ' + literal.getName());
}


The code above will list all literals and names for a given enumeration (resolved by an attribute).

So, I imagine that you want some function like this one:


public Identifier getIdentifier(IAttribute attribute, String displayName) {
IEnumeration<ILiteral> enumeration;
try {
enumeration = (IEnumeration<ILiteral>)workItemClient.resolveEnumeration(attribute, null);
List<ILiteral> enumerationLiterals = enumeration.getEnumerationLiterals();
for (ILiteral literal : enumerationLiterals) {
if (literal.getName().equalsIgnoreCase(displayName)) {
return literal.getIdentifier2();
}
}
return null;
} catch (TeamRepositoryException e) {
return null;
}
}



Then you use like this:


IAttribute attribute0= workItemClient.findAttribute(myProjectArea, "themeEnum", monitor);
if ((attribute0!=null) && (workItem.hasAttribute(attribute0))) {
workItem.setValue(attribute0, getIdentifier(attribute0, "Capability"));
}







I am attempting to create a WorkItem programmatically, and I have almost all of it completed. My last item is to set the value into a field which is backed by an Enumeration. (forgive me if my terminology is off).

I am able to create my WorkItem via the Eclipse client and then "dump" the data out programmatically. My "dump" shows this:
Quality Attributes : qualityAttributes.literal.l6,qualityAttributes.literal.l12

my attribute display name is "Quality Attributes" and it is displayed as a multi-select list in the UI, and it has 2 items "selected", hence you see the literal.l6 and l12.

Programmatically, what I have is the display of those literals, basically "Capability" and "Documentation". I can easily go into my process config and hardcode into my java that "if display.equals("Capability") then use "qualityAttributes.literal.l6", but I was hoping to be able to get all of the Enumeration items, and compare the display name to what I need, and then use that literal value.

I've tried a couple things that I have found in the forums, but nothing quite works to get what I need, which is all available items defined in the Enumeration itself, not the values of a specific attribute. As well, I had a hard time finding a way to go from the displayName to the literal value, instead of the other way around (which seems rather easy).

Susan

permanent link
Ralph Schoon (63.5k33646) | answered Feb 01 '11, 5:58 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi Eduardo,

I am helping Susan with her effort. Thanks to your help I was able to get to the identifier. here is the code:


....
Identifier<extends> literalID=getLiteralStartsWithString(points, workItemCommon, ia);
if(literalID!=null)
workItem.setValue(ia,literalID);
....

private static Identifier<extends> getLiteralStartsWithString(String name, IWorkItemCommon workItemCommon, IAttributeHandle ia) throws TeamRepositoryException{
Identifier<extends> literalID=null;
IEnumeration<extends> enumeration= workItemCommon.resolveEnumeration(ia, null);

List<extends> literals = enumeration.getEnumerationLiterals();
for (Iterator <extends> iterator = literals.iterator(); iterator
.hasNext();) {
ILiteral iLiteral = (ILiteral) iterator.next();
System.out.println("Literal: " + iLiteral.getName() + " id: " +iLiteral.getIdentifier2());
if(iLiteral.getName().startsWith(name)){
System.out.println("Literal Found... " + iLiteral.getName() + " " + iLiteral.getIdentifier2());
literalID = iLiteral.getIdentifier2();
break;
}
}
return literalID;
}



Many thanks again,

Ralph


I'm not sure if I did understand it right... I think that you need an ILiteral object. This piece of code might help you to figure out

I suppose you already have an IAttribute object, found with findAttribute() method.




IEnumeration<ILiteral> enumeration= (IEnumeration<ILiteral>)workItemClient.resolveEnumeration(attribute, monitor);
List<ILiteral> enumerationLiterals = enumeration.getEnumerationLiterals();
for (ILiteral literal : enumerationLiterals) {
System.out.println(literal.getIdentifier2().getStringIdentifier() + ' ' + literal.getName());
}


The code above will list all literals and names for a given enumeration (resolved by an attribute).

So, I imagine that you want some function like this one:


public Identifier getIdentifier(IAttribute attribute, String displayName) {
IEnumeration<ILiteral> enumeration;
try {
enumeration = (IEnumeration<ILiteral>)workItemClient.resolveEnumeration(attribute, null);
List<ILiteral> enumerationLiterals = enumeration.getEnumerationLiterals();
for (ILiteral literal : enumerationLiterals) {
if (literal.getName().equalsIgnoreCase(displayName)) {
return literal.getIdentifier2();
}
}
return null;
} catch (TeamRepositoryException e) {
return null;
}
}



Then you use like this:


IAttribute attribute0= workItemClient.findAttribute(myProjectArea, "themeEnum", monitor);
if ((attribute0!=null) && (workItem.hasAttribute(attribute0))) {
workItem.setValue(attribute0, getIdentifier(attribute0, "Capability"));
}







I am attempting to create a WorkItem programmatically, and I have almost all of it completed. My last item is to set the value into a field which is backed by an Enumeration. (forgive me if my terminology is off).

I am able to create my WorkItem via the Eclipse client and then "dump" the data out programmatically. My "dump" shows this:
Quality Attributes : qualityAttributes.literal.l6,qualityAttributes.literal.l12

my attribute display name is "Quality Attributes" and it is displayed as a multi-select list in the UI, and it has 2 items "selected", hence you see the literal.l6 and l12.

Programmatically, what I have is the display of those literals, basically "Capability" and "Documentation". I can easily go into my process config and hardcode into my java that "if display.equals("Capability") then use "qualityAttributes.literal.l6", but I was hoping to be able to get all of the Enumeration items, and compare the display name to what I need, and then use that literal value.

I've tried a couple things that I have found in the forums, but nothing quite works to get what I need, which is all available items defined in the Enumeration itself, not the values of a specific attribute. As well, I had a hard time finding a way to go from the displayName to the literal value, instead of the other way around (which seems rather easy).

Susan

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.