JiraIssueChangeHistory

Once you have a Jira issue, you can obtain it's change log, for instance to find it's resolved date.

A given change entry has a map, much like JiraIssueProperties:

 
[GenericEntity:ChangeItem][oldvalue,null][group,11438][newvalue,null]
[field,Assignee][oldstring,tchiverton][newstring,rfry][id,12159]
[fieldtype,jira]
 

and a datestamp, .getTimePerformed().

Each instance of a change entry may have a different value for field, such as status, and a corresponding set of newvalues, such as 'Resolved'.

You can obtain the changes for an issue thus:

 
private Date findResolvedDate(GenericValue issue,User remoteUser) throws GenericEntityException {
        DefaultActionManager am = new DefaultActionManager();
        List changes = am.getChangeHistory(issue,remoteUser);

        Iterator it = changes.iterator();
        while (it.hasNext()) {
            ChangeHistory change = (ChangeHistory) it.next();
            List chng = change.getChangeItems();
            Date chgTime = change.getTimePerformed();
            // -- get last status change - it is the most recent  ---
            for (int i = chng.size()-1 ; i>=0 ; i--) {
                GenericEntity chgItem = (GenericEntity) chng.get(i);
//log.debug(" change items ="+chgItem +", date="+chgTime);
                if (chgItem.getString("field").equalsIgnoreCase("status") &&
                    chgItem.getString("newstring").equalsIgnoreCase("resolved")
                ) {
log.debug(" resolved @"+chgTime);
                    return chgTime;
                }
            }
        }
 
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Jun 23, 2005

    E Joseph Guay says:

    Please note that if you want to find the last change date, you need to iterate o...

    Please note that if you want to find the last change date, you need to iterate over the changes. (This was a mistake in the original code that I shared earlier. Here is a snippet to find the date stamp for the last status change:

    lastStatusChange = issue.getTimestamp("created");
    try

    Unknown macro: { changes = am.getChangeHistory(issue,user); }
    catch (GenericEntityException e)
    Unknown macro: { //throw new DataAccessException(e); changes = null; }

    if (changes!=null) {
    // – get last status change - it is the most recent —
    getlastchange: for (int k = changes.size()1; k>=0; k-) {
    ChangeHistory change = (ChangeHistory) changes.get(k);
    List chng = change.getChangeItems();
    Date chgTime = change.getTimePerformed();

    for (int i = 0 ; i<chng.size() ; i++) {
    GenericEntity chgItem = (GenericEntity) chng.get;
    if (chgItem.getString("field").equalsIgnoreCase("status"))

    Unknown macro: { lastStatusChange = chgTime; break getlastchange; }

    }
    }
    }