Listener Looking for an Specific Issue Type Change

Dalectric
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 1, 2011

I currently have a listener that is triggered on an EventType.ISSUE_UPDATED_ID.

This then looks to see if the issue has been moved from a particular issue type to another by looking through the change history using the following method

List<ChangeHistory> changeHistories = mgr.getChangeHistoriesForUser(issueEvent.getIssue(), null);
ChangeHistory changeHistory = changeHistories.get(changeHistories.size() - 1);
List changeItems = changeHistory.getChangeItems();
GenericValue change = (GenericValue) changeItems.get(changeItems.size() - 1);

and then the conditional check

change.getString("oldstring").equals("TBD Issue Type") && change.getString("newstring").equals("Brand New Change")

This code works fine if an issue is moved singularly.

However if I bulk move issue I am getting inconsistent responses for the oldstring/newstring where instead of the issue Summary I'm getting the workflow or even the project name. I believe this is because the order the move is executed in is different for a bulk move to that of a single issue move.

What can I do to make this work for both a single move and a bulk move?

3 answers

1 accepted

2 votes
Answer accepted
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 1, 2011

I guess it is because you are always getting the last item on the Collection as changeItems.get(changeItems.size() - 1) . It is probably an unordered Collection and hence while moving you might get any one of project or summary etc as the last element.

Why don't you iterate on the list and always find the issueType changeItem by looking at the field in GenericValue?

Dalectric
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 1, 2011

I think I was incorrectly assuming the issue type change would always be at the end. What you suggest is a good idea, I guess this may add a little bit of time to the process but should be significant. I'll give it a go. Thanks

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 1, 2011

Cool..let me know how it goes.. It is just a sudden thought, so interested to know if it works :)

Dalectric
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 2, 2011

Works a treat. I'll post my code below

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 2, 2011

That's great! Cheers!!

0 votes
max cai November 12, 2012

Hi Steve,

Are you running this code on Jira 4.x or 5.x. I counld not found the class DefaultChangeHistoryManager in Jira 5.x and want to know how you create that object in your code.

thanks

Max

Dalectric
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 13, 2012

Hi Max

I'm using JIRA 5.0.7 and I've also changed my approach since I posted this code, so I don't need to iterate through the change history.

What I do now is use the following code:

GenericValue change = findIssueTypeChange(issueEvent);

Does this help?

0 votes
Dalectric
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 2, 2011

Iterating through the change items worked as suggested. Here's the code I've use to get it to work. (It may not be the best way to write the code, I'll admit that, but it does seem to work OK for me)

List<ChangeHistory> changeHistories = mgr.getChangeHistoriesForUser(issueEvent.getIssue(), null);
ChangeHistory changeHistory = changeHistories.get(changeHistories.size() - 1);
List changeItems = changeHistory.getChangeItems();
GenericValue change = null;

for (Iterator iterator = changeItems.iterator(); iterator.hasNext();)
{
GenericValue changetemp = (GenericValue) iterator.next();
if (changetemp.getString("field").equals("issuetype"))
{
change = changetemp;
break;
}
else
{
continue;
}
}

Suggest an answer

Log in or Sign up to answer