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.

  1. Open the user-role-project-tab project in your IDE.

  2. In command prompt, create a new plugin module using the command atlas-create-jira-plugin-module

    • Choose option 8 for Issue Tab Panel
    • Enter new class name: UserRoleIssueTabPanel
    • Enter package name: com.jiradev.jira.plugins.panels.issue (notice the similarity in package name from user-role-project-tab plugin)
    • Show advanced setup: N
    • Add another plugin module: N

  3. Take a look at the atlassian-plugin.xml file. You will see a new issue-tabpanel definition. You will also notice that there are two new files available in your project. UserRoleIssueTabPanel.java and user-role-issue-tab-panel.vm.
  4. Let us start by modifying the code for the java class.
    If your class is still using import com.opensymphony.user.User which is deprecated, replace with import com.atlassian.jira.user.ApplicationUser;;
    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;
        }
    }
    
    
  5. 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 TreeMap people = 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());
        }
    }
    
    
  6. The last part is the view. We can simply re-use all the code we wrote in user-role-project-tab-panel.vm file. You can also change the definition of your issue-tabpanel to point to the same view as your project tabpanel. Try out both ways.
  7. Debug the project and step through the code. You should see a new issue tabpanel on your view issue screen.




Share


Show your support by tweeting about this tutorial. Is Jiradev something you would recommend? Let me know.

Contribute


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.

Contribute

Feedback


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.