public abstract class AbstractPropertyDrivenActivationStrategy extends Object implements ActivationStrategy
An abstract activation strategy that is designed to support cases where the activation of a feature is driven based on the value of environmental/contextual properties.
AbstractPropertyDrivenActivationStrategy allows the name of the property can be passed via the
""name"" parameter and gracefully falls back on a property name that is derived from the
Feature itself (e.g. "FEATURE_NAME"). It will take care of the majority of
the work and only really requires implementations to provide the means to lookup the value of the property:
@Override
protected abstract String getPropertyValue(FeatureState featureState, FeatureUser user, String name) {
return doSomeStuffToGetPropertyValue(name);
}
By default, the value of the property will be converted into a boolean but implementations are free to override this,
where needed, by overriding the isActive(FeatureState, FeatureUser, String, String) method. However, it
would be ideal if all implementations tried to support the same value formats to allow for a unified experience. The
default conversion will fail fast if the property value does not match any of the predefined boolean representations
by throwing an IllegalArgumentException.
All implementations should honor the rule that the feature should not be activated if no matching property is found.
getPropertyValue(FeatureState, FeatureUser, String)| Modifier and Type | Field and Description |
|---|---|
static String |
PARAM_NAME |
static String |
PARAM_PROPERTY_VALUE |
| Constructor and Description |
|---|
AbstractPropertyDrivenActivationStrategy() |
| Modifier and Type | Method and Description |
|---|---|
Parameter[] |
getParameters()
Returns the list of configuration parameter definitions for the strategy.
|
protected String |
getPropertyName(FeatureState featureState,
String parameterName)
Returns the name of the property on which to base the activation of the feature.
|
protected String |
getPropertyNameParam() |
protected abstract String |
getPropertyValue(FeatureState featureState,
FeatureUser user,
String name)
Returns the value of the property with the specified
name on which to base the activation of the feature. |
boolean |
isActive(FeatureState featureState,
FeatureUser user)
This method is responsible to decide whether a feature is active or not.
|
protected boolean |
isActive(FeatureState featureState,
FeatureUser user,
String propertyName,
String propertyValue)
This method is called by
isActive(FeatureState, FeatureUser) with the property name and value to make
the decision as to whether the feature is active. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetId, getNamepublic static final String PARAM_NAME
public static final String PARAM_PROPERTY_VALUE
public AbstractPropertyDrivenActivationStrategy()
protected String getPropertyName(FeatureState featureState, String parameterName)
Returns the name of the property on which to base the activation of the feature.
This method will first attempt to use the value of the parameter with the name provided. If that does not return a valid property name (i.e. non-blank), then a property name will be constructed using a common prefix ("") and the name of the feature.
featureState - the FeatureState which represents the current configuration of the featureparameterName - the name of the parameter that potentially contains the property nameprotected abstract String getPropertyValue(FeatureState featureState, FeatureUser user, String name)
Returns the value of the property with the specified name on which to base the activation of the feature.
featureState - the FeatureState which represents the current configuration of the featureuser - the user for which to decide whether the feature is active (may be null)name - the name of the property whose value is to be returnedname or null if none could be found.public final boolean isActive(FeatureState featureState, FeatureUser user)
ActivationStrategyisActive in interface ActivationStrategyfeatureState - The feature state which represents the current configuration of the feature. The implementation of
the method typically uses FeatureState.getParameter(String) to access custom configuration paramater
values.user - The user for which to decide whether the feature is active. May be null if the user could not be
identified by the UserProvider.true if the feature should be active, else falseprotected String getPropertyNameParam()
protected boolean isActive(FeatureState featureState, FeatureUser user, String propertyName, String propertyValue)
This method is called by isActive(FeatureState, FeatureUser) with the property name and value to make
the decision as to whether the feature is active.
By default, this method will convert propertyValue into a boolean using
Strings.toBoolean(String) but implementations are free to override this, where needed. However, it would
be ideal if all implementations tried to support the same value formats to allow for a unified experience. The
default implementation throw an IllegalArgumentException if propertyValue does not match any of
the predefined boolean representations.
This method should never return true if propertyValue is null.
featureState - the FeatureState which represents the current configuration of the featureuser - the user for which to decide whether the feature is active (may be null)propertyName - the name of the property on which to base the activation of the featurepropertyValue - the (raw) value of the property on which to base the activation of the feature (may be null if
none was found)IllegalArgumentException - If propertyValue is non-null and does not match any of the predefined boolean
representations.public Parameter[] getParameters()
ActivationStrategy
Returns the list of configuration parameter definitions for the strategy. Parameters are typically built using a
ParameterBuilder class but users can also create custom implementations of the Parameter interface.
Example:
public Parameter[] getParameters() {
return new Parameter[] {
ParameterBuilder.create("country").label("Country Code").matching("[A-Z]+")
};
}
getParameters in interface ActivationStrategyParameterBuilderCopyright © 2018. All Rights Reserved.