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 import static com.atlassian.sal.api.features.ValidFeatureKeyPredicate.checkFeatureKey;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 public class DarkFeatureEnabledCondition implements Condition
26 {
27 private static final String FEATURE_KEY_INIT_PARAMETER_NAME = "featureKey";
28 private final DarkFeatureManager darkFeatureManager;
29 private String featureKey;
30
31 public DarkFeatureEnabledCondition(final DarkFeatureManager darkFeatureManager)
32 {
33 this.darkFeatureManager = darkFeatureManager;
34 }
35
36 @Override
37 public void init(final Map<String, String> params) throws PluginParseException
38 {
39 if (params.containsKey(FEATURE_KEY_INIT_PARAMETER_NAME))
40 {
41 featureKey = checkFeatureKey(params.get(FEATURE_KEY_INIT_PARAMETER_NAME));
42 }
43 else
44 {
45 throw new PluginParseException("Parameter '" + FEATURE_KEY_INIT_PARAMETER_NAME + "' is mandatory.");
46 }
47 }
48
49 @Override
50 public boolean shouldDisplay(final Map<String, Object> stringObjectMap)
51 {
52 try
53 {
54 return darkFeatureManager.isFeatureEnabledForCurrentUser(featureKey);
55 }
56 catch (RuntimeException e)
57 {
58 return false;
59 }
60 }
61 }