This question is about the atlassian JIRA plugin development. When I use event listener to handle JIRA's IssueEvent of comment deleted event, I can catch the comment deleted event with event type "com.atlassian.jira.event.type.EventType.ISSUE_COMMENT_DELETED_ID". But I don't know how can I get the comment id which has been deleted in this event. I've tried the IssueEvent.getComment for this situation, but it returns null.
Asked
Active
Viewed 576 times
2 Answers
1
There is a constant called COMMENTS_PARAM_NAME
in the IssueEvent class which suggests the deleted comments may be in a Map called 'params' that is part of the IssueEvent object (link goes to JavaDoc for the constant). Although this says it is for "issue delete events", it MAY be able to help you.
To see if this exists in your case, you could try (assuming you have a logger attached and the right level of logging setup):
Map<String, Object> paramsMap = issueEvent.getParams();
for (String key : paramsMap.keySet()) {
if (key.equals(IssueEvent.COMMENTS_PARAM_NAME)) {
log.debug("Comments Param List Exists");
}
}
and see if it prints to the atlassian logs.
If it does exist, then you could try using it like:
Map<String, Object> paramsMap = issueEvent.getParams();
List<Comment> deletedCommentsList = paramsMap.get(IssueEvent.COMMENTS_PARAM_NAME);
// Do whatever you need to do with the Comments
N.B. The getParams()
method is inherited from the JiraEvent class.

Sam
- 492
- 2
- 13
-
Unfortunately, I've tried these code for comment delete event happened. It only contains a key of "baseUrl". So this does not work. BTW, I've checked the code of IssueEvent.COMMENTS_PARAM_NAME, the java doc said as this: In case of issue delete events, a param with this key will store list of this issue's comments as a list of {@link Comment} objects. So seems that this param only works for issue delete events, but not comment delete events. – Gang Aug 28 '15 at 08:38
-
Yes, you're correct. My only other suggestion would be to check out this post I answered: [JIRA Plugins SDK: How to find out changed data?](http://stackoverflow.com/questions/31986312/jira-plugins-sdk-how-to-find-out-changed-data/32115164). This gets the changeLog from the issueEvent and uses it to find parts have changed. This may contain something about the comments. I'm not sure whether it will have the ID or not though... – Sam Aug 28 '15 at 15:10
-
Thanks, Sam. I've tried the change log way, it can get the comment body which has been removed, but the comment id missed. This only solved a little part of my problem, which the comment id is the most important one. – Gang Aug 31 '15 at 09:36
1
Based on change log you can extract
GenericValue genericValue = issueEvent.getChangeLog();
if (genericValue == null) {
return;
}
List<GenericValue> changeItems = null;
try {
changeItems = genericValue.getRelated("ChildChangeItem");
String fieldName, fieldType;
for (GenericValue changeItem : changeItems) {
fieldType = (String) changeItem.get("fieldtype");
fieldName = (String) changeItem.get("field");
if ("JIRA".equalsIgnoreCase(fieldType) && IssueFieldConstants.COMMENT.equalsIgnoreCase(fieldName)) {
**Object commentId = changeItem.get("id");**
if (commentId != null && commentId.toString().length()>0) {
}
}
}
} catch (GenericEntityException e) {}

bfontaine
- 18,169
- 13
- 73
- 107

Abdellah Lbaik
- 11
- 1