Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions core-api/src/main/java/com/optimizely/ab/Optimizely.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import com.optimizely.ab.config.EventType;
import com.optimizely.ab.config.Experiment;
import com.optimizely.ab.config.FeatureFlag;
import com.optimizely.ab.config.LiveVariable;
import com.optimizely.ab.config.LiveVariableUsageInstance;
import com.optimizely.ab.config.FeatureVariable;
import com.optimizely.ab.config.FeatureVariableUsageInstance;
import com.optimizely.ab.config.ProjectConfig;
import com.optimizely.ab.config.Variation;
import com.optimizely.ab.config.parser.ConfigParseException;
Expand Down Expand Up @@ -203,9 +203,9 @@ public Variation activate(@Nonnull Experiment experiment,

@Nullable
private Variation activate(@Nonnull ProjectConfig projectConfig,
@Nonnull Experiment experiment,
@Nonnull String userId,
@Nonnull Map<String, ?> attributes) {
@Nonnull Experiment experiment,
@Nonnull String userId,
@Nonnull Map<String, ?> attributes) {
if (!isValid) {
logger.error("Optimizely instance is not valid, failing activate call.");
return null;
Expand Down Expand Up @@ -310,12 +310,12 @@ public void track(@Nonnull String eventName,

// create the conversion event request parameters, then dispatch
LogEvent conversionEvent = eventFactory.createConversionEvent(
projectConfig,
userId,
eventType.getId(),
eventType.getKey(),
copiedAttributes,
eventTags);
projectConfig,
userId,
eventType.getId(),
eventType.getKey(),
copiedAttributes,
eventTags);

logger.info("Tracking event \"{}\" for user \"{}\".", eventName, userId);

Expand Down Expand Up @@ -348,7 +348,7 @@ public void track(@Nonnull String eventName,
*/
@Nonnull
public Boolean isFeatureEnabled(@Nonnull String featureKey,
@Nonnull String userId) {
@Nonnull String userId) {
return isFeatureEnabled(featureKey, userId, Collections.<String, String>emptyMap());
}

Expand All @@ -365,8 +365,8 @@ public Boolean isFeatureEnabled(@Nonnull String featureKey,
*/
@Nonnull
public Boolean isFeatureEnabled(@Nonnull String featureKey,
@Nonnull String userId,
@Nonnull Map<String, ?> attributes) {
@Nonnull String userId,
@Nonnull Map<String, ?> attributes) {
if (!isValid) {
logger.error("Optimizely instance is not valid, failing isFeatureEnabled call.");
return false;
Expand Down Expand Up @@ -451,7 +451,7 @@ public Boolean getFeatureVariableBoolean(@Nonnull String featureKey,
variableKey,
userId,
attributes,
LiveVariable.VariableType.BOOLEAN
FeatureVariable.VariableType.BOOLEAN
);
if (variableValue != null) {
return Boolean.parseBoolean(variableValue);
Expand Down Expand Up @@ -500,7 +500,7 @@ public Double getFeatureVariableDouble(@Nonnull String featureKey,
variableKey,
userId,
attributes,
LiveVariable.VariableType.DOUBLE
FeatureVariable.VariableType.DOUBLE
);
if (variableValue != null) {
try {
Expand Down Expand Up @@ -554,7 +554,7 @@ public Integer getFeatureVariableInteger(@Nonnull String featureKey,
variableKey,
userId,
attributes,
LiveVariable.VariableType.INTEGER
FeatureVariable.VariableType.INTEGER
);
if (variableValue != null) {
try {
Expand Down Expand Up @@ -608,15 +608,15 @@ public String getFeatureVariableString(@Nonnull String featureKey,
variableKey,
userId,
attributes,
LiveVariable.VariableType.STRING);
FeatureVariable.VariableType.STRING);
}

@VisibleForTesting
String getFeatureVariableValueForType(@Nonnull String featureKey,
@Nonnull String variableKey,
@Nonnull String userId,
@Nonnull Map<String, ?> attributes,
@Nonnull LiveVariable.VariableType variableType) {
@Nonnull FeatureVariable.VariableType variableType) {
if (featureKey == null) {
logger.warn("The featureKey parameter must be nonnull.");
return null;
Expand All @@ -633,7 +633,7 @@ String getFeatureVariableValueForType(@Nonnull String featureKey,
return null;
}

LiveVariable variable = featureFlag.getVariableKeyToLiveVariableMap().get(variableKey);
FeatureVariable variable = featureFlag.getVariableKeyToFeatureVariableMap().get(variableKey);
if (variable == null) {
logger.info("No feature variable was found for key \"{}\" in feature flag \"{}\".",
variableKey, featureKey);
Expand All @@ -650,10 +650,10 @@ String getFeatureVariableValueForType(@Nonnull String featureKey,
Map<String, ?> copiedAttributes = copyAttributes(attributes);
FeatureDecision featureDecision = decisionService.getVariationForFeature(featureFlag, userId, copiedAttributes);
if (featureDecision.variation != null) {
LiveVariableUsageInstance liveVariableUsageInstance =
featureDecision.variation.getVariableIdToLiveVariableUsageInstanceMap().get(variable.getId());
if (liveVariableUsageInstance != null) {
variableValue = liveVariableUsageInstance.getValue();
FeatureVariableUsageInstance featureVariableUsageInstance =
featureDecision.variation.getVariableIdToFeatureVariableUsageInstanceMap().get(variable.getId());
if (featureVariableUsageInstance != null) {
variableValue = featureVariableUsageInstance.getValue();
} else {
variableValue = variable.getDefaultValue();
}
Expand Down

This file was deleted.

20 changes: 10 additions & 10 deletions core-api/src/main/java/com/optimizely/ab/config/FeatureFlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ public class FeatureFlag implements IdKeyMapped {
private final String key;
private final String rolloutId;
private final List<String> experimentIds;
private final List<LiveVariable> variables;
private final Map<String, LiveVariable> variableKeyToLiveVariableMap;
private final List<FeatureVariable> variables;
private final Map<String, FeatureVariable> variableKeyToFeatureVariableMap;

@JsonCreator
public FeatureFlag(@JsonProperty("id") String id,
@JsonProperty("key") String key,
@JsonProperty("rolloutId") String rolloutId,
@JsonProperty("experimentIds") List<String> experimentIds,
@JsonProperty("variables") List<LiveVariable> variables) {
@JsonProperty("variables") List<FeatureVariable> variables) {
this.id = id;
this.key = key;
this.rolloutId = rolloutId;
this.experimentIds = experimentIds;
this.variables = variables;
this.variableKeyToLiveVariableMap = ProjectConfigUtils.generateNameMapping(variables);
this.variableKeyToFeatureVariableMap = ProjectConfigUtils.generateNameMapping(variables);
}

public String getId() {
Expand All @@ -66,12 +66,12 @@ public List<String> getExperimentIds() {
return experimentIds;
}

public List<LiveVariable> getVariables() {
public List<FeatureVariable> getVariables() {
return variables;
}

public Map<String, LiveVariable> getVariableKeyToLiveVariableMap() {
return variableKeyToLiveVariableMap;
public Map<String, FeatureVariable> getVariableKeyToFeatureVariableMap() {
return variableKeyToFeatureVariableMap;
}

@Override
Expand All @@ -82,7 +82,7 @@ public String toString() {
", rolloutId='" + rolloutId + '\'' +
", experimentIds=" + experimentIds +
", variables=" + variables +
", variableKeyToLiveVariableMap=" + variableKeyToLiveVariableMap +
", variableKeyToFeatureVariableMap=" + variableKeyToFeatureVariableMap +
'}';
}

Expand All @@ -98,7 +98,7 @@ public boolean equals(Object o) {
if (!rolloutId.equals(that.rolloutId)) return false;
if (!experimentIds.equals(that.experimentIds)) return false;
if (!variables.equals(that.variables)) return false;
return variableKeyToLiveVariableMap.equals(that.variableKeyToLiveVariableMap);
return variableKeyToFeatureVariableMap.equals(that.variableKeyToFeatureVariableMap);
}

@Override
Expand All @@ -108,7 +108,7 @@ public int hashCode() {
result = 31 * result + rolloutId.hashCode();
result = 31 * result + experimentIds.hashCode();
result = 31 * result + variables.hashCode();
result = 31 * result + variableKeyToLiveVariableMap.hashCode();
result = 31 * result + variableKeyToFeatureVariableMap.hashCode();
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import javax.annotation.Nullable;

/**
* Represents a live variable definition at the project level
* Represents a feature variable definition at the project level
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class LiveVariable implements IdKeyMapped {
public class FeatureVariable implements IdKeyMapped {

public enum VariableStatus {
@SerializedName("active")
Expand Down Expand Up @@ -106,11 +106,11 @@ public static VariableType fromString(String variableTypeString) {
private final VariableStatus status;

@JsonCreator
public LiveVariable(@JsonProperty("id") String id,
@JsonProperty("key") String key,
@JsonProperty("defaultValue") String defaultValue,
@JsonProperty("status") VariableStatus status,
@JsonProperty("type") VariableType type) {
public FeatureVariable(@JsonProperty("id") String id,
@JsonProperty("key") String key,
@JsonProperty("defaultValue") String defaultValue,
@JsonProperty("status") VariableStatus status,
@JsonProperty("type") VariableType type) {
this.id = id;
this.key = key;
this.defaultValue = defaultValue;
Expand Down Expand Up @@ -141,7 +141,7 @@ public VariableType getType() {

@Override
public String toString() {
return "LiveVariable{" +
return "FeatureVariable{" +
"id='" + id + '\'' +
", key='" + key + '\'' +
", defaultValue='" + defaultValue + '\'' +
Expand All @@ -155,7 +155,7 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

LiveVariable variable = (LiveVariable) o;
FeatureVariable variable = (FeatureVariable) o;

if (!id.equals(variable.id)) return false;
if (!key.equals(variable.key)) return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016-2017, Optimizely and contributors
* Copyright 2016-2017, 2019, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,17 +21,17 @@
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Represents the value of a live variable for a variation
* Represents the value of a feature variable for a variation
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class LiveVariableUsageInstance implements IdMapped {
public class FeatureVariableUsageInstance implements IdMapped {

private final String id;
private final String value;

@JsonCreator
public LiveVariableUsageInstance(@JsonProperty("id") String id,
@JsonProperty("value") String value) {
public FeatureVariableUsageInstance(@JsonProperty("id") String id,
@JsonProperty("value") String value) {
this.id = id;
this.value = value;
}
Expand All @@ -49,7 +49,7 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

LiveVariableUsageInstance that = (LiveVariableUsageInstance) o;
FeatureVariableUsageInstance that = (FeatureVariableUsageInstance) o;

return id.equals(that.id) && value.equals(that.value);
}
Expand Down
Loading