Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to extract the current project in a <condition> and <context-provider> for a project-centric navigation web-item and web-panel?

Igor Sereda [ALM Works]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 23, 2015

Our plugin can be enabled or disabled for a specific project.

So when we implement project-centric navigation and add web-item/web-panel that displays our view for a project, we need to add a <condition> to the web-item, so that it doesn't show when the plugin is not enabled for the specific project. The implementation of the <condition> must be able to understand which project is being displayed.

Likewise, <context-provider> for the web-panel must understand which project is being displayed to correctly prepare all the data.

Unfortunately, project ID or other identification is not available from JiraHelper – neither in AbstractJiraCondition, nor in AbstractJiraContextProvider. It is always null.

So far we had resorted to extracting project key from the HttpServletRequest, which is available from JiraHelper. We recognize a pattern /projects/PROJECTKEY and get the key from it. But that doesn't work if the current "project-centric" page has a different pattern – for example, if it's JIRA Agile's board, we're screwed.

Did someone figure out how to get project ID reliably? Atlassian, any comments? I didn't find anything about it in the docs.

Thank you.
Igor 

10 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Igor Sereda [ALM Works]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2015

Turns out the answer was staring me in the face all along.

When I wrote the condition and context-provider, I extended AbstractJiraCondition and AbstractJiraContextProvider, respectively - kind of by default, because other conditions and context providers in the project are based on these classes.

Turns out they do more harm than good, because the interfaces Condition and ContextProvider receive the context as a Map. But these abstract "default" implementation convert the map into JiraHelper, and pass only the JiraHelper to the subclasses. There are a lot of data in the Context – including the current project – but JiraHelper does not inherit it.

So the solution was: remove "extends AbstractJiraCondition" and replace with "implements Condition", and similar thing for the context provider, then implementing the interface methods correctly.

Thanks to @Filip Rogaczewski for help and clearing my eyesight.

Andrey November 1, 2015

Hi Igor, Could you please post the example of the resulting condition class here?

2 votes
Kerem Caglar [Solveka]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2015

Hi Igor,

For ContextProvider you can use the following link for your action

&lt;link linkId="project-zzz"&gt;/secure/ViewZZZ!default.jspa?projectKey=$projectKeyEncoded&lt;/link&gt;

 

You have to have a class attribute named projectKey to get the project key. For an example you can check source code for Issue Collectors plugin.

I am not sure how to do this with the condition. 

Igor Sereda [ALM Works]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2015

Thanks, Kerem. Yes this is possible, although this is not exactly using context-provider, but rather replacing web-panel with a WebWork action. It also requires "advanced implementation" as outlined in https://developer.atlassian.com/jiradev/jira-platform/projects/design-guide-jira-project-centric-view/development-guide-jira-project-centric-view - such as rendering the sidebar yourself. I'd like to stay with "basic implementation" if possible.

0 votes
Igor Sereda [ALM Works]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2015

Ah, got it - thanks. Yes, that would work as a workaround. I'm still hopeful for a straightforward solution though :)

0 votes
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2015

I meant that you can initially hide your panel and show it by JavaScript from your web-panel template.

0 votes
Igor Sereda [ALM Works]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2015

Volodymyr, thanks! But how does that help?

0 votes
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2015

Just have found this https://developer.atlassian.com/jiradev/jira-architecture/building-jira-add-ons/jira-plugins2-overview/jira-plugin-module-types/web-panel-plugin-module: Useful hints If you use web-panel to hook into view issue screen, then param with name=containerClass is really handy. It allows to add any CSS class to the enclosing div element (e.g. to make it initially hidden). The following code illustrates it: 1 <web-panel ....> 2 <param name="containerClass">my-extra-css-class-added-to-the-container</param> 3 </web-panel>

0 votes
Igor Sereda [ALM Works]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2015

That could be an option if web-panel is rendered in the browser, where project ID could be extracted. In any case that's a poor man's option, as the menu item will be shown always, even if there's nothing to show. If web-panel template is rendered on the server, I don't see a way to reliably extract project ID. That's what the question is about.

0 votes
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2015

Just a shot: Maybe it's possible to take decision in your WebPanel implementation and return empty HTML if needed.

0 votes
Igor Sereda [ALM Works]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2015

@Volodymyr Krupach I've looked into a number of plugin sources already, including Agile, and none of them have the answer. And JIRA Agile does not use web-panel for rendering the project page at all.

0 votes
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 23, 2015

Only suggestion is to look into JIRA Agile sources to find how the project is retrieved for "problematic places".

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events