It's all about the answers!

Ask a question

Get custom attribute key and value in Server-Side plugin


Jaegon Yoo (9611314) | asked Oct 25 '10, 5:18 a.m.
Hello~

I'm developing a server-side plug-in to compare a custom attribute value of my own workitem between previous and current.

My code is like below.
I can successfully see some summary data.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Object data= operation.getOperationData();

if (data instanceof ISaveParameter) {
IAuditable auditable = ((ISaveParameter) data).getNewState();

if (auditable instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem) auditable;
System.out.println("Summary : " + workItem.getHTMLSummary());
// I need to get custom attribute key and value to compare previous and current.
...
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Is there any example code to get custom attribute of my workitem?
Any help will be appriciated.

Accepted answer


permanent link
Hakki Bozkurt (1631021) | answered Sep 11 '14, 2:43 a.m.
edited Sep 11 '14, 2:46 a.m.
IWorkItemCommon workItemService= (IWorkItemCommon) getService(IWorkItemCommon.class);
// You have to add this class in plugin.xml
IAttribute attribute= workItemService.findAttribute(operation.getProcessArea().getProjectArea(), "ur_attr_id", monitor);
String currentWI_TaskType = sourceworkItem.getValue(attribute).toString();   
// return object type data maybe you want to convert
plugin.xml (this is mine)

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="com.ibm.team.process.service.operationAdvisors">
      <operationAdvisor
            class="jazzdevapprovaladvisor.JazzDevApprovalSave"
            id="JazzDevApprovalAdvisor"
            name="JazzDev Approval Advisor"
            operationId="com.ibm.team.workitem.operation.workItemSave">
            <extensionService componentId="JazzDevApprovalAdvisor" 
            	implementationClass="jazzdevapprovaladvisor.JazzDevApprovalSave">
            	<prerequisites> 
					<requiredService interface="com.ibm.team.repository.service.IRepositoryItemService" />
					<optionalservice interface="com.ibm.team.repository.common.service.IContributorService"/> 
					<optionalservice interface="com.ibm.team.workitem.common.IWorkItemCommon"/>   
				</prerequisites>  
			 </extensionService>
      </operationAdvisor>
   </extension>
</plugin>
Ralph Schoon selected this answer as the correct answer

4 other answers



permanent link
Patrick Streule (4.9k21) | answered Oct 25 '10, 1:24 p.m.
JAZZ DEVELOPER
I'm developing a server-side plug-in to compare a custom attribute
value of my own workitem between previous and current.

My code is like below.
I can successfully see some summary data.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Object data= operation.getOperationData();

if (data instanceof ISaveParameter) {
IAuditable auditable = ((ISaveParameter) data).getNewState();

if (auditable instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem) auditable;
System.out.println(&quot;Summary : &quot; +
workItem.getHTMLSummary());
// I need to get custom attribute key and value to compare previous
and current.
...
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Is there any example code to get custom attribute of my workitem?
Any help will be appriciated.


You can use (pseudo-code):

IWorkItemCommon workItemService=
saveParameter.getAuditableCommon().getPeer(IWorkItemCommon.class);

IAttribute attribute= workItemService.findAttribute(projectArea, &quot;your
custom attribute id&quot;, monitor);

Object value= workItem.getValue(attribute);

--
Regards,
Patrick
RTC Work Item Component Lead

permanent link
Jaegon Yoo (9611314) | answered Oct 27 '10, 12:25 p.m.
Thanks for your comment.

I'm able to get current value of custom attribute.

However I need to get previous data to compare with current value.

How can I do this?

Thanks in advance.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public class OperationAdvisor extends AbstractService implements IOperationAdvisor {

public void run(AdvisableOperation operation,
IProcessConfigurationElement advisorConfiguration,
IAdvisorInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException {

try {

System.out.println(&quot;#################### starts ######################&quot;);


Object data= operation.getOperationData();

if (data instanceof ISaveParameter) {
IAuditable auditable = ((ISaveParameter) data).getNewState();

IWorkItemCommon workItemService = ((ISaveParameter)data).getSaveOperationParameter().getAuditableCommon().getPeer(IWorkItemCommon.class);


IAttribute attribute= workItemService.findAttribute(operation.getProcessArea().getProjectArea(), &quot;custom_attribute&quot;, monitor);

IWorkItem workItem = (IWorkItem) auditable;
System.out.println(&quot;value=&quot;+workItem.getValue(attribute));

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

permanent link
Patrick Streule (4.9k21) | answered Nov 08 '10, 6:53 a.m.
JAZZ DEVELOPER
Thanks for your comment.

I'm able to get current value of custom attribute.

However I need to get previous data to compare with current value.

How can I do this?

The ISaveParameter has two methods:

getNewState() --&gt; The work item with the current, modified values.
getOldState() --&gt; The original state as it exists in the repo.

--
Regards,
Patrick
RTC Work Item Component Lead

permanent link
Jaegon Yoo (9611314) | answered Nov 09 '10, 12:37 a.m.
I figured it out.
Thanks for your support.

Comments
ANIL ABRAHAM commented Sep 19 '12, 7:14 p.m.

"getPeer" is an deprecated method . What is the equivalent method ?

IWorkItemCommon workItemService = ((ISaveParameter)data).getSaveOperationParameter().getAuditableCommon().getPeer(IWorkItemCommon.class);


Muthukumar C commented Sep 20 '12, 5:44 a.m.

extend the Abstract class and then you can use the getservice() method to get the service of required class

Your answer


Register or to post your answer.