Get custom attribute key and value in Server-Side plugin
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.
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
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>
4 other answers
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.
You can use (pseudo-code):
IWorkItemCommon workItemService=
saveParameter.getAuditableCommon().getPeer(IWorkItemCommon.class);
IAttribute attribute= workItemService.findAttribute(projectArea, "your
custom attribute id", monitor);
Object value= workItem.getValue(attribute);
--
Regards,
Patrick
RTC Work Item Component Lead
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("#################### starts ######################");
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(), "custom_attribute", monitor);
IWorkItem workItem = (IWorkItem) auditable;
System.out.println("value="+workItem.getValue(attribute));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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("#################### starts ######################");
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(), "custom_attribute", monitor);
IWorkItem workItem = (IWorkItem) auditable;
System.out.println("value="+workItem.getValue(attribute));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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() --> The work item with the current, modified values.
getOldState() --> The original state as it exists in the repo.
--
Regards,
Patrick
RTC Work Item Component Lead
I figured it out.
Thanks for your support.
Thanks for your support.
Comments
"getPeer" is an deprecated method . What is the equivalent method ?
IWorkItemCommon workItemService = ((ISaveParameter)data).getSaveOperationParameter().getAuditableCommon().getPeer(IWorkItemCommon.class);
extend the Abstract class and then you can use the getservice() method to get the service of required class