1 package com.atlassian.sal.api.features;
2
3 import com.atlassian.fugue.Option;
4
5 import java.util.Set;
6
7 /**
8 * Provides a cross-product method for determining whether a dark feature is enabled.
9 *
10 * Implementing products can back these checks with their own internal dark feature management system, but must follow
11 * the enable and disable dark features on startup based on system properties and the contents of an optional properties file.
12 *
13 * Dark feature keys must begin with atlassian.darkfeature. Values must be either true or false.
14 * Location of dark features property file can be overridden with darkfeatures.properties.file system property.
15 *
16 * See SystemDarkFeatureInitializer in sal-core for implementation.
17 */
18 public interface DarkFeatureManager
19 {
20 // prefix for all dark feature property keys
21 public static final String ATLASSIAN_DARKFEATURE_PREFIX = "atlassian.darkfeature.";
22
23 // system property for disabling all dark features
24 public static final String DISABLE_ALL_DARKFEATURES_PROPERTY = "atlassian.darkfeature.disabled";
25
26 // system property for overriding location of dark features property file
27 public static final String DARKFEATURES_PROPERTIES_FILE_PROPERTY = "darkfeatures.properties.file";
28
29 // default properties file
30 public static final String DARKFEATURES_PROPERTIES_FILE_PROPERTY_DEFAULT = "atlassian-darkfeatures.properties";
31
32 /**
33 * Checks if a dark feature is enabled
34 * @param darkFeatureSystemPropertyKey key of the feature to be checked
35 * @return true if enabled, false otherwise
36 */
37 public boolean isSystemFeatureEnabled(String darkFeatureSystemPropertyKey);
38
39 /**
40 * Checks if a dark feature is enabled for the current user (must be called within the context of a request)
41 * @param darkFeatureSystemPropertyKey key of the feature to be checked
42 * @return true if enabled, false otherwise
43 */
44 public boolean isUserFeatureEnabled(String darkFeatureSystemPropertyKey);
45
46 /**
47 * Checks if a dark feature is enabled for the user with name username
48 *
49 * @param username the name of the user being queried
50 * @param darkFeatureSystemPropertyKey key of the feature to be checked
51 * @return an Option.Some containing Boolean.TRUE if enabled for the user, containing Boolean.FALSE otherwise. If no user
52 * exists with name username then returns Option.None
53 */
54 public Option<Boolean> isUserFeatureEnabledForUser(String username, String darkFeatureSystemPropertyKey);
55
56 /**
57 * Gets all enabled dark features for the current user (must be called within the context of a request)
58 *
59 * @return a Set containing the keys for all dark features applicable for the current user (a union of all system
60 * dark features and user dark features enabled for current user).
61 */
62 public Set<String> getAllEnabledFeaturesForCurrentUser();
63
64 /**
65 * Gets all enabled dark features for a given user
66 *
67 * @param username the name of the user being queried
68 * @return a Set containing the keys for all dark features applicable for the given user (a union of all system
69 * dark features and user dark features enabled for given user).
70 */
71 public Option<Set<String>> getAllEnanbedFeaturesForUser(String username);
72 }