Requirement: Display a list of users associated with different roles of the project in an issue tab panel
Source code available at https://bitbucket.org/jiradev-tutorials/project-tab-panel
When developing plugins for a particular instance of JIRA, say for example for a particular company, it is easier to maintain the plugins if we deploy all the different modules as a single plugin. We are going to continue with the existing code we have from the user-role-project-tab plugin.
package com.jiradev.jira.plugins.panels.issue; import com.atlassian.core.util.collection.EasyList; import com.atlassian.jira.user.ApplicationUser; import com.atlassian.jira.plugin.issuetabpanel.IssueTabPanelModuleDescriptor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.atlassian.jira.plugin.issuetabpanel.AbstractIssueTabPanel; import com.atlassian.jira.plugin.issuetabpanel.IssueTabPanel; import com.atlassian.jira.issue.tabpanels.GenericMessageAction; import com.atlassian.jira.issue.Issue; import java.util.Collections; import java.util.List; public class UserRoleIssueTabPanel extends AbstractIssueTabPanel { private static final Logger log = LoggerFactory.getLogger(UserRoleIssueTabPanel.class); public List getActions(Issue issue, ApplicationUser remoteUser) { return EasyList.build(new UserRoleIssueAction(super.descriptor, issue.getProjectObject())); } public boolean showPanel(Issue issue, ApplicationUser remoteUser) { return true; } }
Notice that I have used a class called UserRoleIssueAction. This is a new class that I have written to populate the params map with the collection of project roles and users. The code you will see in the getVelocityParams method is the same as the project tabpanel code.
Create a new class called UserRoleIssueAction that extends AbstractIssueAction in the package com.jiradev.jira.plugins.panels.issue
package com.jiradev.jira.plugins.panels.issue; import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.plugin.issuetabpanel.AbstractIssueAction; import com.atlassian.jira.plugin.issuetabpanel.IssueTabPanelModuleDescriptor; import com.atlassian.jira.project.Project; import com.atlassian.jira.security.roles.ProjectRole; import com.atlassian.jira.security.roles.ProjectRoleActors; import com.atlassian.jira.security.roles.ProjectRoleManager; import java.util.Collection; import java.util.Date; import java.util.Map; import java.util.TreeMap; public class UserRoleIssueAction extends AbstractIssueAction { private ProjectRoleManager projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager.class); private TreeMappeople = new TreeMap (); private Project project; public UserRoleIssueAction(IssueTabPanelModuleDescriptor issueTabPanelModuleDescriptor, Project project){ super(issueTabPanelModuleDescriptor); this.project = project; } public Date getTimePerformed(){ return null; } public void populateVelocityParams(Map params){ //Get all the project roles Collection projectRoles = projectRoleManager.getProjectRoles(); //Iterate through each role and get the users associated with the role for (ProjectRole projectRole : projectRoles){ ProjectRoleActors roleActors = projectRoleManager.getProjectRoleActors(projectRole, project); people.put(projectRole.getName(),roleActors.getUsers()); } params.put("people",people); params.put("avatarService",ComponentAccessor.getAvatarService()); } }
Show your support by tweeting about this tutorial. Is Jiradev something you would recommend? Let me know.
Do you have a Jira plugin tutorial that can be used on this site? Please do share it with me and I can add it along with the ones available.
Your feedback can help improve the content on this site. If you have anything that you would like me to change/implement on the site.