It's all about the answers!

Ask a question

get/set the displayed name of an enumeration type attribute


Stefania Axo (12621513) | asked Mar 23 '11, 4:46 p.m.
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

4 answers



permanent link
Eduardo Bello (4401922) | answered Mar 24 '11, 10:17 a.m.
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.

permanent link
Stefania Axo (12621513) | answered Apr 14 '11, 7:21 p.m.
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

permanent link
Stefania Axo (12621513) | answered Apr 15 '11, 10:03 a.m.
never mind workItemClient has resolveEnumeration

workItemClient.resolveEnumeration(attr null);

thanks

permanent link
Stefania Axo (12621513) | answered Apr 15 '11, 12:09 p.m.
yes it worked
thank you again

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.