[Jira] retrieving the current project key for project sidebar

I am trying to create a page displaying data about the current jira project. It should be accessible through the sidebar (project-centric-view).

The page has been made accessibel through a WebItem (link in the sidebar). The page itself is rendered as a WebPanel. I have provided the Panel with a contextrenderer (extends AbstractJiraContextProvider) which allows me to override the getContextMap(ApplicationUser, JiraHelper) method. 
I would need the projectId of the current project to retrieve the data I want to display, however the JiraHelper object returns null on the getProject() call.

So how do I get a hold of the projectId?

I suspect that I would need to pass it as a parameter, possibly form the WebItem, but how would I do this?

Any help would be appreciated.

 

atlassian-plugin.xml

 

<web-item key="overview-menu-item" name="Upsource Overview Link" 
              section="jira.project.sidebar.plugins.navigation"
              weigth="30" application="jira">
        <desctiption>Link to the upsource connectivity overview page for this project</desctiption>
        <label key="upsource-connectivity.overview.label"/>
        <link linkId="upsource-connectivity-overview-link">/projects/$pathEncodedProjectKey?selectedItem=com.atlassian.jira.jira-projects-plugin:upsource-overview-page</link>
        <param name="iconClass" value="aui-icon-large icon-sidebar-issues"/>
    </web-item>
  
    <web-panel key="upsource-overview-panel" location="com.atlassian.jira.jira-projects-plugin:upsource-overview-page">
        <description>Project overview of open upsource reviews</description>
        <resource name="view" type="velocity" location="templates/OverviewPanel.vsl"/>
        <context-provider class="com.nikon.developmenttools.impl.OverviewContextProvider"/>
    </web-panel>

ContextProvider class

 

 

public class OverviewContextProvider extends AbstractJiraContextProvider {

    @Inject
    private UpsourceConnectivityExtentionMethods methodContainer;
    
    public OverviewContextProvider(){}

    public UpsourceConnectivityExtentionMethods getMethodContainer() {
        return methodContainer;
    }

    public void setMethodContainer(UpsourceConnectivityExtentionMethods methodContainer) {
        this.methodContainer = methodContainer;
    }
    
    @Override
    public Map getContextMap(ApplicationUser au, JiraHelper jh) {
        Map contextMap = new HashMap();
        List<String> exceptionMessages = new ArrayList<String>();
        try{
            Project currentProject = (Project) (jh.getProject());
            if(currentProject == null){
                String message = "it's the currentproject"
                        + "\nqs: " + jh.getQueryString()
                        + "\ncontextparam: "+ jh.getContextParams().toString();
                throw new Exception(message);
            }
            UpsourceConfig uc = this.methodContainer.loadConfig(currentProject.getKey());
            HashMap<String, String> ucProperties = new HashMap<String, String>();
            ucProperties.put("host", uc.getHost());
            ucProperties.put("user", uc.getUsername());
            ucProperties.put("upsourceId", uc.getUpsourceProjectId());
            contextMap.put("config", ucProperties);
            ResultDTO result = this.methodContainer.getReviews(currentProject);
            if(result == null || result.getResult() == null){
                throw new Exception("its the result");
            }
            ReviewsDTO response = (ReviewsDTO) result.getResult();
            contextMap.put("reviewsDTO", response);
        }catch (UpsourceConnectionFailureException ucfe) {
            System.err.println("UPSOURCE CONNECTION EXCEPTION: " + ucfe.getMessage());
            if (ucfe.getCause() != null && ucfe.getCause().getCause() instanceof java.net.UnknownHostException) {
                exceptionMessages.add("Error resolving host, please check the Upsource Connectivity Settings for this project and your network settings.");
            } else {
                exceptionMessages.add(ucfe.toString());
            }
        } catch (UpsourceUnsetConfigException uuce) {
            System.err.println("UPSOURCE CONFIGRATION EXCEPTION: " + uuce.getMessage());
            exceptionMessages.add(uuce.getMessage());
        } catch (UpsourceConnectivityException uce) {
            System.err.println("UPSOURCE EXCEPTION: " + uce.getMessage());
            if (uce.getCause() != null) {
                exceptionMessages.add(uce.getCause().toString());
            } else {
                exceptionMessages.add(uce.toString());
            }
        } catch (Exception ex) {
            exceptionMessages.add(ex.toString());
            System.err.println("EXCEPTION: " + ex.toString());
        }
        contextMap.put("exceptionList", exceptionMessages);
        return contextMap;
    }
    
}

 

Overview Page

 

<div class="mod-header">
    <h2>Code Reviews</h2>
    #if( !$exceptionList.isEmpty() )
        <h3>Error</h3>
        #foreach( $exception in $exceptionList )
            <p>$exception.toString()</p>
        #end
    #end 
    #if($reviewsDTO.reviews.isEmpty())
        <p>No reviews available.</p>
    #else
    #foreach( $review in $reviewsDTO.reviews )
        <table>
        <tr>
        <td><h4>$review.reviewId.reviewId</h4></td>
        </tr>
        <tr>
        <td>State: #if($review.state == 1)
            Open
            #else
            Closed
            #end
            </td>
        </tr>
        <tr>
        <td><a href="${review.additionalProperties.get("link")}">Go to review ${review.reviewId.reviewId}</a></td>
        </tr>
        </table>
        <br/>
    #end
    #end
</div>

 

2 answers

0 votes
Sam Hall Community Champion Apr 05, 2017

Hi Robrecht - since this is development related, you might want to try asking this over at: https://community.developer.atlassian.com as well (if you haven't already).

There's a lot of helpful and experienced people over there. You might well get a quicker answer in there than on here.

Hi Robrecht,

I have same requirement and even me too facing the same issue in getting the projectId from the sidebar (project-centric-view).

Hope you might have got the solution for this. Could you please provide any link with the solution?

Thanks in advance!

-Kumar

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

24,186 views 2 7
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you