Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculated field in Jira

Tags:

java

jira

I'm writing a plug-in for Jira and I need to add custom calculated column to issue navigator. That's column should show last comment to issue. But in issue navigator values in this column are something like "ClassName@123456", not comment's body. What should I do to return comment's body to this column?

Code so far:

public class LastCommentField extends CalculatedCFType {
    private CommentManager commentManager = null;

    public LastCommentField(CommentManager commentManager) {
        this.commentManager=commentManager;
    }

    public Object getValueFromIssue(CustomField field, Issue issue) {
        Comment lastComment=null;
        List<Comment> comments = commentManager.getComments(issue);
        if(comments != null && !comments.isEmpty()) {
            lastComment = (Comment)comments.get(comments.size() - 1);
        }   
        return lastComment;
    }

    public String getStringFromSingularObject (Object object) {
        return object.toString();
    }

    public Object getSingularObjectFromString(String value) {
        return value;       
    }
}
like image 249
Dmitrii Avatar asked Nov 23 '25 15:11

Dmitrii


1 Answers

This functionality already exists in at least two plugins, e.g. https://marketplace.atlassian.com/plugins/net.customware.jira.utils.customware-jira-utilities

But in the code above, the singular object being used is a Comment object as documented at http://docs.atlassian.com/jira/4.4/com/atlassian/jira/issue/comments/Comment.html but you probably just want a String, so try

return lastComment.getBody();

like image 192
mdoar Avatar answered Nov 26 '25 05:11

mdoar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!