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>
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
Hello,
Define in your web-item a link like the below:
<link>/projects/$pathEncodedProjectKey?selectedItem=com.snowlinesoftware.irae:project-treemap-web-panel&projectKey=$pathEncodedProjectKey</link>
See, the projectKey parameter will have value $pathEncodedProjectKey which is the key of your project. Then, in your class extending AbstractJiraContextProvider in the getContextMap method you just get it from the jiraHelper as a GET parameter:
String projectKey = jiraHelper.getRequest().getParameter("projectKey");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.