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
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
Hi,
You can get the identifier like this:
And to get directly the displayName of an attribute you can do something like this:
I hope it helps.
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.
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
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