Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

get/set the displayed name of an enumeration type attribute

hi
how do i get the displayed name of an enumeration type attribute ?
how do i set a string in the enumeration type attribute?
i would like to get the identifier of the string for that specific enumeration type attribute. (from String display name to Identifier to be able to do the setValue on workItem)

String value = "my displayed name";
IAttribute fAttribute ;

protected void execute( WorkItemWorkingCopy workingCopy, IProgressMonitor monitor )
throws TeamRepositoryException
{
IWorkItem workItem = workingCopy.getWorkItem();
Identifier attributeValue = workItem.getValue( fAttribute);
workItem.setValue (?)
...
}




can i have some code example that i can look into?
how can i access to the attribute type map?

thank you
stefania

0 votes



4 answers

Permanent link
Hi,

You can get the identifier like this:


/**
* Get identifier for a given string display name value
*
* @param workItem
* @param attrName
* @param displayName
* @return
*/
@SuppressWarnings("unchecked")
public Identifier getIdentifier(IWorkItem workItem, String attrName, String displayName
) {
IWorkItemServer workItemServer = getService(IWorkItemServer.class);
IAttribute attribute;
try {
attribute = workItemServer.findAttribute(workItem.getProjectArea(), attrName, null);
if (workItem.hasAttribute(attribute)) {
IEnumeration<ILiteral> enumeration= (IEnumeration<ILiteral>)workItemServer.resolveEnumeration(attribute, null);
List<ILiteral> enumerationLiterals = enumeration.getEnumerationLiterals();
for (ILiteral literal : enumerationLiterals) {
if (literal.getName().equalsIgnoreCase(displayName)) {
return literal.getIdentifier2();
}
}
return null;
} else {
return null;
}
} catch (Exception e) {
return null;
}
}




And to get directly the displayName of an attribute you can do something like this:


/**
* Get the display value of some enumeration attribute
* @param workItem
* @param attrName
* @return
*/
@SuppressWarnings("unchecked")
public String getAttributeDisplayName(IWorkItem workItem, String attrName) {
IWorkItemServer workItemServer = getService(IWorkItemServer.class);
IAttribute attr;
try {
attr = workItemServer.findAttribute(workItem.getProjectArea(), attrName, null);
if ((attr!=null) && (workItem.hasAttribute(attr))) {
Identifier ident = (Identifier) workItem.getValue(attr);
IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>)workItemServer.resolveEnumeration(attr, null);
return enumeration.findEnumerationLiteral(ident).getName();
} else {
return null;
}
} catch (Exception e) {
return null;
}
}




I hope it helps.

0 votes


Permanent link
hi
thank you for your help on this

i have to run this via client code not server code
i don't have access to this
IWorkItemServer workItemServer = getService(IWorkItemServer.class);
to call the .resolveEnumeration(attr, null);

what is the way to do the same with the client code?

IWorkItemClient workItemClient = (IWorkItemClient)repository
.getClientLibrary( IWorkItemClient.class );

i don't find the resolveEnumeration there.

thank you
Stefania

0 votes


Permanent link
never mind workItemClient has resolveEnumeration

workItemClient.resolveEnumeration(attr null);

thanks

0 votes


Permanent link
yes it worked
thank you again

0 votes

Your answer

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

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,937

Question asked: Mar 23 '11, 4:46 p.m.

Question was seen: 6,548 times

Last updated: Mar 23 '11, 4:46 p.m.

Confirmation Cancel Confirm