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

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>

0 votes


Accepted answer

Permanent link

Pavel,

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

1 vote

Comments

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?

import com.ibm.team.repository.service.AbstractService;
// 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;

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

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,934
× 457
× 411
× 369
× 70

Question asked: Oct 09 '17, 5:41 a.m.

Question was seen: 3,150 times

Last updated: Apr 17 '18, 8:20 a.m.

Confirmation Cancel Confirm