It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Jay 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 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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in United States

Unofficial downtown meetup week of June 3 or 4?

Hello everyone!  It's been a while since Houston's had a Atlassian Community Event (formerly Atlassian User Group meeting) so I wanted to gauge interest in an unofficial downtown meetup after wo...

33 views 0 0
View post

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you