It's all about the answers!

Ask a question

Ibm Rtc server-side custom attribute set value.

Pavel Cikota (13210) | asked Oct 09 '17, 5:41 a.m.
edited Apr 17 '18, 8:20 a.m. by Ralph Schoon (62.3k33643)


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); <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

permanent link
Luca Martinucci (1.0k291110) | answered Oct 09 '17, 6:33 a.m.


first, you should never set a work item attribute in a precondition.
The purpose of preconditions is to evaluate whether the current action can be performed or not, by reading attribute values.
If you want to set an attribute value, write a follow-up action instead.
Concerning your specific issue, I would rather retrieve a IEnumeration object than an Enumeration one.
I always use this code for retrieving enumerations, and it works fine:

IProgressMonitor monitor = new NullProgressMonitor();
IWorkItemCommon workItemCommon = pluginAbstractService.getService(IWorkItemCommon.class);
IEnumeration<?> enumeration workItemCommon.resolveEnumeration(attributeHandle, monitor);

Anyway, if you have a close look at my original post, you will find that I am using the "internal" Enumeration class to add an enumeration value to db-based enumeration at runtime (i.e., as the plugin is running).
If I understand, you need to set the value of a work item attribute to an already existing enumeration value.

Ralph Schoon selected this answer as the correct answer

Pavel Cikota commented Oct 09 '17, 8:19 a.m.

What is  pluginAbstractService in line IWorkItemCommon workItemCommon = pluginAbstractService.getService(IWorkItemCommon.class);?

If it my plugin AbstractService, and I can describe as this.getService(IWorkItemCommon.class) - it fallin down plugin. Whats other way to become  IWorkItemCommon workItemCommon?

Luca Martinucci commented Oct 09 '17, 8:34 a.m.
// where plugin=your plugin's class

AbstractService pluginAbstractService = (AbstractService) plugin;

Actually, this code snippet is in another class (named "PluginUtility") than my plugin's class; I pass the plugin object (from inside the plugin's class) this way:

PluginUtility utility;
utility = new PluginUtility(this);

Then, in PluginUtility:

public PluginUtility(Object currentPlugin) {
     plugin = currentPlugin;
AbstractService pluginAbstractService = (AbstractService) plugin;

Ralph Schoon commented Oct 09 '17, 8:50 a.m.

 AbstractService is only available if the extension point implementation class extends AbstractService as it should.

Your answer

Register or to post your answer.