Ibm Rtc server-side custom attribute set value.
Hello!
I try set value of enumeration type of Work Item on pre-condition on server-side plugin according this post , but I need to save a value of list. <o:p> </o:p>
I use IBM RTC 5.0.2.
<o:p>
</o:p>
If I understood correct, I need set value by workItem.setValue(IAttribute attr, Object val), where workItem is IWorkItem, and val is Identifier (for Enumeration Type of attribute). <o:p> </o:p>
I have found needed attribute, but I don't know, how found needed Identifier value (I have a text display name of needed value, or literal-link as simple text (String).) <o:p> </o:p>
Use this code to found needed Identifier, but when I try to get Enumeration (enumeration = (Enumeration) enumerationService.resolveEnumeration(attrHandle); ) - my plugin falling down. <o:p> </o:p>
public Identifier getVaLByString(String strVal, IAttribute attr, IWorkItem wi) { <o:p> </o:p>
IAttributeHandle attrHandle = getAttrHandle(attr, wi); <o:p> </o:p>
EnumerationService enumerationService = new EnumerationService(); <o:p> </o:p>
Enumeration enumeration = (Enumeration) enumerationService.resolveEnumeration(attrHandle); //FAIL, Plugin Falling down <o:p> </o:p>
// Enumeration enumeration = (Enumeration) enumerationService.resolveEnumeration(attr); // FAIL TOO! <o:p> </o:p>
List literals = enumeration.getEnumerationLiterals(); <o:p> </o:p>
<o:p> </o:p>
for (Iterator iterator = literals.iterator(); iterator.hasNext();) { //literalsParse <o:p> </o:p>
ILiteral iLiteral = (ILiteral) iterator.next(); <o:p> </o:p>
if (iLiteral.getIdentifier2().getStringIdentifier().equalsIgnoreCase(strVal)) return iLiteral.getIdentifier2(); <o:p> </o:p>
} //literalsParse <o:p> </o:p>
return null; <o:p> </o:p>
} <o:p> </o:p>
private IAttributeHandle getAttrHandle(IAttribute aT, IWorkItem wI) throws TeamRepositoryException { //getAttrHandle_WORK FINE! <o:p> </o:p>
IAttributeHandle out = null; <o:p> </o:p>
<o:p> </o:p>
List<IAttributeHandle> listHandle = wI.getCustomAttributes(); <o:p> </o:p>
IAttribute cA = null; <o:p> </o:p>
<o:p> </o:p>
for (IAttributeHandle cHandle : listHandle) { <o:p> </o:p>
IRepositoryItemService itemService = getService(IRepositoryItemService.class); <o:p> </o:p>
cA = (IAttribute) itemService.fetchItem(cHandle, IRepositoryItemService.COMPLETE); <o:p> </o:p>
<o:p> </o:p>
if (cA.equals(aT) || cA == aT || cA.getDisplayName().equals(aT.getDisplayName())) <o:p> </o:p>
return cHandle; <o:p> </o:p>
} <o:p> </o:p>
<o:p> </o:p>
return out; <o:p> </o:p>
} //getAttrHandle <o:p> </o:p>
A lot of examples uses Client library, but it doesn't work on server-side. <o:p> </o:p>
Accepted answer
Pavel,
Comments
What is pluginAbstractService in line IWorkItemCommon workItemCommon = pluginAbstractService.getService(IWorkItemCommon.class);?
AbstractService pluginAbstractService = (AbstractService) plugin;
AbstractService is only available if the extension point implementation class extends AbstractService as it should.