JIRA Plugins SDK: How to find out changed data?

我的梦境 提交于 2019-12-11 10:01:34

问题


I am using the JIRA plugins sdk to work on changed Issues.

I´ve implemented an IssueListener and I have access to the Issue itself and the IssueEvent.

How do I find out which property (summary, description, estimation ...) of my Issue has been changed ?


回答1:


The changelog is likely to contain what's been changed and there is a method on the IssueEvent object to get this (getChangeLog) and it returns a GenericValue object.

This post on the Atlassian Answers site gives some code related to an Atlassian tutorial on how to write JIRA Event Listeners.

The relevant code snippet is shown below:

if (eventTypeId.equals(EventType.ISSUE_UPDATED_ID)) {
    List<GenericValue> changeItems = null;

    try {
        GenericValue changeLog = issueEvent.getChangeLog();
        changeItems = changeLog.internalDelegator.findByAnd("ChangeItem", EasyMap.build("group",changeLog.get("id")));
    } catch (GenericEntityException e){
        System.out.println(e.getMessage());
    }

    log.info("number of changes: {}",changeItems.size());
    for (Iterator<GenericValue> iterator = changeItems.iterator(); iterator.hasNext();){
        GenericValue changetemp = (GenericValue) iterator.next();
            String field = changetemp.getString("field");
            String oldstring = changetemp.getString("oldstring");
            String newstring = changetemp.getString("newstring");
            StringBuilder fullstring = new StringBuilder();
            fullstring.append("Issue ");
            fullstring.append(issue.getKey());
            fullstring.append(" field ");
            fullstring.append(field);
            fullstring.append(" has been updated from ");
            fullstring.append(oldstring);
            fullstring.append(" to ");
            fullstring.append(newstring);
            log.info("changes {}", fullstring.toString());

            /* Do something here if a particular field you are
               looking for has being changed.
            */
            if(field == "Component") changeAssignee(changetemp, issue, user);
    }
}


来源:https://stackoverflow.com/questions/31986312/jira-plugins-sdk-how-to-find-out-changed-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!