/** * Code for enabling/disabling a feature based on a request ({@link CheckRequest}) and a config ({@link Config}) * * @param config * @param checkRequest * @return */ public CheckResponse processConfig(Config config, CheckRequest checkRequest) { if (config != null && config.getFeatureMap().containsKey(checkRequest.featureName)) { Feature feature = config.getFeatureMap().get(checkRequest.featureName); ResponseDecisionMeta responseDecisionMeta = handleFeature(feature, checkRequest); // if there is a decisive state (either enabled or disabled) initiate the callback and break return new CheckResponse(checkRequest.featureName, responseDecisionMeta.state, responseDecisionMeta.featureMetadata, responseDecisionMeta.ruleMetadata); } // a) feature not found or b) no state could be made based on the config // check if there was no default state in the request, send enabled (default toggle) String state; if (checkRequest.defaultState == null) { state = DEFAULT_STATE; } else { state = checkRequest.defaultState; } return new CheckResponse(checkRequest.featureName, state, null, null, false); }
private void assertValidConfig(Config config) { assertThat(config.getFeatureMap()).isNotNull(); assertThat(config.getFeatureMap().get("video")).isNotNull(); assertThat(config.getFeatureMap().get("audio")).isNotNull(); assertThat(config.getFeatureMap().get("speech")).isNotNull(); assertThat(config.getFeatureMap().get("random")).isNull(); }
public void setConfig(Config config) { // check for the config map if (config.getFeatureMap() == null) config.generateFeatureMap(); setSourceType(SourceType.CONFIG); // store source PersistUtils.storeSourceType(getContext(), SourceType.CONFIG); // store config storeConfigInMem(config); PersistUtils.storeConfig(getContext(), config); }