JSONObject res = new JSONObject();
if (comment.getBody() != null) {
res.put("body", comment.getBody());
}
final Visibility commentVisibility = comment.getVisibility();
if (commentVisibility != null) {
final int buildNumber = serverInfo.getBuildNumber();
if (buildNumber >= ServerVersionConstants.BN_JIRA_4_3) {
JSONObject visibilityJson = new JSONObject();
final String commentVisibilityType;
if (buildNumber >= ServerVersionConstants.BN_JIRA_5) {
commentVisibilityType = commentVisibility.getType() == Visibility.Type.GROUP ? "group" : "role";
} else {
commentVisibilityType = commentVisibility.getType() == Visibility.Type.GROUP ? "GROUP" : "ROLE";
}
visibilityJson.put("type", commentVisibilityType);
visibilityJson.put("value", commentVisibility.getValue());
res.put(CommentJsonParser.VISIBILITY_KEY, visibilityJson);
} else {
if (commentVisibility.getType() == Visibility.Type.ROLE) {
res.put("role", commentVisibility.getValue());
} else {
res.put("group", commentVisibility.getValue());
}
}
}
return res;