问题描述
那么,如何获得 自定义 字段的 上一个 值 在Jira IssueEventListener中?我正在为issueUpdated(IssueEvent)事件编写自定义处理程序,如果某个自定义字段已更改,我想更改处理程序的行为。为了检测更改的类型,我想比较以前的值和当前的值。
So how does one obtain the previous value of a custom field in a Jira IssueEventListener? I am writing a custom handler for the issueUpdated(IssueEvent) event and I would like to alter the handler's behavior if a certain custom field has changed. To detect the type of change I would like to compare the previous and current values.
(我不是在问如何获取其当前值。 em>值-我知道如何从相关问题中获得收益)
(I'm am not asking about how to obtain its current value - I know how to get that from the related Issue)
我正在针对Windows上的Jira 4.0.2进行开发。
I am developing against Jira 4.0.2 on Windows.
是否是扫描更改历史记录中最后一个已知值的最佳方法?
Is the best way to scan the change history for the last known value?
List changes = changeHistoryManager.getChangeHistoriesForUser(issue, user);
推荐答案
我假设原始海报正在编写JIRA Java插件。我不能确定如何在JIRA v4.0.2中完成此任务,但是这是我如何通过JIRA v5.0.2来做到这一点(解决方案可能完全相同):
I'm assuming the original poster is writing a JIRA plugin with Java. I cannot be certain of how to accomplish this task in JIRA v4.0.2, but here is how I managed to do so with JIRA v5.0.2 (the solutions may very well be the same):
public void workflowEvent( IssueEvent event )
{
Long eventTypeId = event.getEventTypeId();
if( eventTypeId.equals( EventType.ISSUE_UPDATED_ID ) )
{
List<GenericValue> changeItemList = null;
try
{
changeItemList = event.getChangeLog().getRelated( "ChildChangeItem" );
}
catch( GenericEntityException e )
{
// Error or do what you need to do here.
e.printStackTrace();
}
if( changeItemList == null )
{
// Same deal here.
return;
}
Iterator<GenericValue> changeItemListIterator = changeItemList.iterator();
while( changeItemListIterator.hasNext() )
{
GenericValue changeItem = ( GenericValue )changeItemListIterator.next();
String fieldName = changeItem.get( "field" ).toString();
if( fieldName.equals( customFieldName ) ) // Name of custom field.
{
Object oldValue = changeItem.get( "oldvalue" );
Object newValue = changeItem.get( "newvalue" );
}
}
}
}
有些changeItem的可能键值为:
Some possible key values for changeItem are:
- newvalue
- oldstring
- field
- id
- fieldtype
- newstring
- oldvalue
- group
- newvalue
- oldstring
- field
- id
- fieldtype
- newstring
- oldvalue
- group
对于许多自定义字段类型,对象oldValue可能只是一个串。但我认为并非每种情况都如此。
For many of the custom field types Object oldValue is probably just a String. But I don't think that's true for every case.
这篇关于吉拉:如何获取自定义IssueEventListener中的自定义字段的先前值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!