Hi,
I am creating a new page, accessible from the project side bar.
I used a WebItem to display the link and a WebPanel to render the page.
The problem is, I need the project object (or project key) in the contextProvider of the WebPanel.
I created a custom contextProvider that implements AbstractJiraContextProvider. This provides a JiraHelper object. However the getProject() call on this helper returns null.
I suspect I will need to pass the project key as a parameter from the WebItem to the WebPanel, but it is unclear to me how I would do this. The documentation does not provide a straight answer.
Any suggestions?
The Atlassian-plugin.xml items
<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>
The context Provider
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());
if(uc == null){
throw new Exception("its the uc");
}
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;
}
}