How can I return a List of Comments to a custom tabpanel plugin?

jaysit May 15, 2014

I'm trying to write a plugin module to show subtask comments in the screen for a parent issue. Here's what I've got so far:

public class SubtaskCommentsIssueTabPanel extends AbstractIssueTabPanel implements IssueTabPanel
{
    private static final Logger log = LoggerFactory.getLogger(SubtaskCommentsIssueTabPanel.class);

    public List getActions(Issue issue, User remoteUser) {

      List<IssueAction> issueactions = new ArrayList();

      Collection<Issue> subtasks = ComponentAccessor.getSubTaskManager().getSubTaskObjects(issue);

      for (Issue subtask : subtasks) {

        List<Comment> comments = ComponentAccessor.getCommentManager().getComments(subtask);

        for (Comment comment : comments) {
          issueactions.add(comment);
        }

      }

      return issueactions;
    }

    public boolean showPanel(Issue issue, User remoteUser)
    {
        return true;
    }
}

This doesn't compile, because on line 16 I'm trying to add a Comment to a List<IssueAction>. If I return a List<Comment>, then nothing appears in the new tab.

How can I make this work? Admittedly I'm new to Java as well so this process has involved a lot of throwing stuff at the wall and seeing what sticks.

1 answer

0 votes
Paresh Gandhi
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 15, 2014
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import org.apache.log4j.Logger
import static org.apache.log4j.Level.DEBUG
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.util.ErrorCollection
import com.atlassian.jira.issue.index.IssueIndexManager
import java.sql.Timestamp
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import java.text.DateFormat
import java.util.Date
import java.text.SimpleDateFormat

class SummaryStatusDate extends AbstractIssueEventListener {
	Logger log = Logger.getLogger(SummaryStatusDate.class)
	@Override
	void workflowEvent(IssueEvent event) {
		log.setLevel(org.apache.log4j.Level.DEBUG)
		def field = event.getChangeLog().getRelated('ChildChangeItem').any{it.field.toString().equalsIgnoreCase("Summary Updated")}				
		if (field){			
			SimpleDateFormat format2 = new SimpleDateFormat("dd/MMM/yy hh:mm aa")
			def today = format2.format((new Date()))
			Issue issue = event.getIssue()						
			ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getUser()			
			ComponentManager componentManager = ComponentManager.getInstance()
			CommentManager commentManager = componentManager.getCommentManager()
			commentManager.create(issue, user, "Summary Status Updated on " + today , false)
		}
	}
}

This may help.

Suggest an answer

Log in or Sign up to answer