View Javadoc

1   package com.atlassian.sal.api.features;
2   
3   import com.atlassian.plugin.PluginParseException;
4   import com.atlassian.plugin.web.Condition;
5   
6   import java.util.Map;
7   
8   /**
9    * A parameterised plugin module condition for enabling modules in the presence of a dark feature.
10   * Pass a param with key "key" containing the dark feature key.
11   */
12  public class DarkFeatureEnabledCondition implements Condition
13  {
14      private final DarkFeatureManager darkFeatureManager;
15  
16      private String key;
17  
18      public DarkFeatureEnabledCondition(DarkFeatureManager darkFeatureManager)
19      {
20          this.darkFeatureManager = darkFeatureManager;
21      }
22  
23      @Override
24      public void init(Map<String, String> params) throws PluginParseException
25      {
26          key = params.get("key");
27      }
28  
29      @Override
30      public boolean shouldDisplay(Map<String, Object> stringObjectMap)
31      {
32          return key == null || darkFeatureManager.isUserFeatureEnabled(key);
33      }
34  }