I have a web-panel which should display based on some particular project. I didnt come across any jira built in condition which could work for me to achieve this task. So i have added a class.java file and i have hardcoded an issue. Using this issue i get the project key, and i return true if my project key == "some project name" else false. Name of the package is [com.myplugin.samplecondition]
now in my web-panel i have defined this way.
<web-panel>
<condition class="com.myplugin.samplecondition">
</condition
>
</web-panel>
Is this all i have to do so that my condition class is accessible or should i be doing something more on this. I have just started coding on this so please bare with my doubts/questions.
Community moderators have prevented the ability to post new answers.
Hi,
could you post your implementation to see more details?
Mainly, your web-panel configuration should look like this if you class is named "class"
<web-panel> <condition class="com.myplugin.samplecondition.class"> </condition> </web-panel>
Based on the documentation your class has to implement the "Condition":
Condition elements must contain a class attribute with the fully-qualified name of a Java class. The referenced class:
com.atlassian.plugin.web.Condition
, andpublic interface Condition extends BaseCondition { /** * Called after creation and autowiring. * * @param params The optional map of parameters specified in XML. */ void init(Map<String,String> params) throws PluginParseException; /** * Determine whether the web fragment should be displayed * * @return true if the user should see the fragment, false otherwise */ boolean shouldDisplay(Map<String,Object> context); }
Using parameters (accessible in the init-Method) might be an option to get the list of "some particular projects".
<web-panel> <condition class="com.myplugin.samplecondition.class"> <param name="project">my-project</param> </condition> </web-panel>
You can also use spring-injected objects within your Condition class - here is an example how the JIRA permission manager is used by the :
public class UserIsAdminCondition extends AbstractWebCondition { private final PermissionManager permissionManager; public UserIsAdminCondition(PermissionManager permissionManager) { this.permissionManager = permissionManager; } public boolean shouldDisplay(ApplicationUser user, JiraHelper jiraHelper) { return permissionManager.hasPermission(Permissions.ADMINISTER, user); } }
Extending the https://docs.atlassian.com/jira/latest/com/atlassian/jira/plugin/webfragment/conditions/AbstractWebCondition.htmlor one of its sub-classes (instead of implementing the Condition interface) might give you access to a JiraHelper - to return the project in this context.
HTH, Sabine
Hi Sabine. Can you please post the complete implementation of active objects.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jayashree,
what do you mean with "implementation of active objects" - cannot see any relation to the topic. Just provide me more details or share your current implementation and I will try to help you.
Sabine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sabine..
ok i will explain about my requirement.
In JIRA's issue view page i wanted a gadget which is somewhat similar to the time estimate gadget which is present in jira.
I did develop the gadget and added it in the issue view page. But this is visible to all the projects. So i need to configure this to display this gadget only to some selected projects. So in the atlassian forum i got some answers telling that i use active objects to store the list of it. i dont know how to use them inspite of reading the document on this i am sometimes stuck.
We do have a condition tag the way you explained above so that we can add it to the webpanel to control the visibility of the gadget but there's no inbuilt function in jira which allows me to choose among some projects. So i am looking into the implementation of this. i want my gadget to get displayed for selected projects. i need to configure this somewhere.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I try to summarize what I understand: the project list, telling the condition to show the gadget , is now stored with Active Objects. Right?
So your condition, whenever it is used calls the AO Service to get the list of projects, checks whether the project the user is currently browsing on is in the list and if yes, displays your gadget. Can you post your atlassian-plugin.xml as well as the condition implementation. Would be great. Thx,
Sabine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Sabin for your advice relative to extend AbstractWebCondition to give access to JiraHelper.
My solution to the problem of viewing web-panel only for certain types of project is the following:
Condition of web-panel
<condition class="full.class.name.YourClassName"> <param name="project-caterogy-1">category1</param> <param name="project-caterogy-2">category2</param> </condition>
Class:
import com.atlassian.jira.plugin.webfragment.conditions.AbstractWebCondition; import java.util.Map; import com.atlassian.jira.plugin.webfragment.model.JiraHelper; import com.atlassian.jira.project.ProjectCategory; import com.atlassian.jira.project.ProjectManager; import com.atlassian.jira.project.Project; import com.atlassian.jira.user.ApplicationUser; import com.atlassian.plugin.PluginParseException; public class YourClassName extends AbstractWebCondition { /** * Called after creation and autowiring. * * @param params The optional map of parameters specified in XML. */ private Map<String,String> params; @Override public void init(Map<String,String> params) throws PluginParseException { this.params = params; } /** * Determine whether the web fragment should be displayed * * @return true if the user should see the fragment, false otherwise */ @Override public boolean shouldDisplay(ApplicationUser applicationUser, JiraHelper jiraHelper) { boolean out = false; try { if (params == null || params.isEmpty()) { System.out.println("No project-category parameter has been set into atlassian-plugin.xml."); return out; } Project currentProject = jiraHelper.getProjectObject(); ProjectCategory currentProjectCat = currentProject.getProjectCategoryObject(); for(String projectCategory : params.values()) { if (currentProjectCat.getName().equals(projectCategory)) { return true; } } }catch (Exception ex){ System.out.println("An exception is occured " +ex.getMessage()); return out; } return out; } }
Its works fine for me for multiple project categories.
Hope it can help...
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.