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?
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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cool..let me know how it goes.. It is just a sudden thought, so interested to know if it works :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Works a treat. I'll post my code below
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's great! Cheers!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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;
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.