Skip to content

Commit 7ac2b72

Browse files
mnoman09thomaszurkan-optimizely
authored andcommitted
Refactored code and removed liveVariable tests and its parsing Completely removed LiveVariable all traces (#263)
1 parent 6b54035 commit 7ac2b72

21 files changed

+270
-598
lines changed

core-api/src/main/java/com/optimizely/ab/Optimizely.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import com.optimizely.ab.config.EventType;
2424
import com.optimizely.ab.config.Experiment;
2525
import com.optimizely.ab.config.FeatureFlag;
26-
import com.optimizely.ab.config.LiveVariable;
27-
import com.optimizely.ab.config.LiveVariableUsageInstance;
26+
import com.optimizely.ab.config.FeatureVariable;
27+
import com.optimizely.ab.config.FeatureVariableUsageInstance;
2828
import com.optimizely.ab.config.ProjectConfig;
2929
import com.optimizely.ab.config.Variation;
3030
import com.optimizely.ab.config.parser.ConfigParseException;
@@ -203,9 +203,9 @@ public Variation activate(@Nonnull Experiment experiment,
203203

204204
@Nullable
205205
private Variation activate(@Nonnull ProjectConfig projectConfig,
206-
@Nonnull Experiment experiment,
207-
@Nonnull String userId,
208-
@Nonnull Map<String, ?> attributes) {
206+
@Nonnull Experiment experiment,
207+
@Nonnull String userId,
208+
@Nonnull Map<String, ?> attributes) {
209209
if (!isValid) {
210210
logger.error("Optimizely instance is not valid, failing activate call.");
211211
return null;
@@ -310,12 +310,12 @@ public void track(@Nonnull String eventName,
310310

311311
// create the conversion event request parameters, then dispatch
312312
LogEvent conversionEvent = eventFactory.createConversionEvent(
313-
projectConfig,
314-
userId,
315-
eventType.getId(),
316-
eventType.getKey(),
317-
copiedAttributes,
318-
eventTags);
313+
projectConfig,
314+
userId,
315+
eventType.getId(),
316+
eventType.getKey(),
317+
copiedAttributes,
318+
eventTags);
319319

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

@@ -348,7 +348,7 @@ public void track(@Nonnull String eventName,
348348
*/
349349
@Nonnull
350350
public Boolean isFeatureEnabled(@Nonnull String featureKey,
351-
@Nonnull String userId) {
351+
@Nonnull String userId) {
352352
return isFeatureEnabled(featureKey, userId, Collections.<String, String>emptyMap());
353353
}
354354

@@ -365,8 +365,8 @@ public Boolean isFeatureEnabled(@Nonnull String featureKey,
365365
*/
366366
@Nonnull
367367
public Boolean isFeatureEnabled(@Nonnull String featureKey,
368-
@Nonnull String userId,
369-
@Nonnull Map<String, ?> attributes) {
368+
@Nonnull String userId,
369+
@Nonnull Map<String, ?> attributes) {
370370
if (!isValid) {
371371
logger.error("Optimizely instance is not valid, failing isFeatureEnabled call.");
372372
return false;
@@ -451,7 +451,7 @@ public Boolean getFeatureVariableBoolean(@Nonnull String featureKey,
451451
variableKey,
452452
userId,
453453
attributes,
454-
LiveVariable.VariableType.BOOLEAN
454+
FeatureVariable.VariableType.BOOLEAN
455455
);
456456
if (variableValue != null) {
457457
return Boolean.parseBoolean(variableValue);
@@ -500,7 +500,7 @@ public Double getFeatureVariableDouble(@Nonnull String featureKey,
500500
variableKey,
501501
userId,
502502
attributes,
503-
LiveVariable.VariableType.DOUBLE
503+
FeatureVariable.VariableType.DOUBLE
504504
);
505505
if (variableValue != null) {
506506
try {
@@ -554,7 +554,7 @@ public Integer getFeatureVariableInteger(@Nonnull String featureKey,
554554
variableKey,
555555
userId,
556556
attributes,
557-
LiveVariable.VariableType.INTEGER
557+
FeatureVariable.VariableType.INTEGER
558558
);
559559
if (variableValue != null) {
560560
try {
@@ -608,15 +608,15 @@ public String getFeatureVariableString(@Nonnull String featureKey,
608608
variableKey,
609609
userId,
610610
attributes,
611-
LiveVariable.VariableType.STRING);
611+
FeatureVariable.VariableType.STRING);
612612
}
613613

614614
@VisibleForTesting
615615
String getFeatureVariableValueForType(@Nonnull String featureKey,
616616
@Nonnull String variableKey,
617617
@Nonnull String userId,
618618
@Nonnull Map<String, ?> attributes,
619-
@Nonnull LiveVariable.VariableType variableType) {
619+
@Nonnull FeatureVariable.VariableType variableType) {
620620
if (featureKey == null) {
621621
logger.warn("The featureKey parameter must be nonnull.");
622622
return null;
@@ -633,7 +633,7 @@ String getFeatureVariableValueForType(@Nonnull String featureKey,
633633
return null;
634634
}
635635

636-
LiveVariable variable = featureFlag.getVariableKeyToLiveVariableMap().get(variableKey);
636+
FeatureVariable variable = featureFlag.getVariableKeyToFeatureVariableMap().get(variableKey);
637637
if (variable == null) {
638638
logger.info("No feature variable was found for key \"{}\" in feature flag \"{}\".",
639639
variableKey, featureKey);
@@ -650,10 +650,10 @@ String getFeatureVariableValueForType(@Nonnull String featureKey,
650650
Map<String, ?> copiedAttributes = copyAttributes(attributes);
651651
FeatureDecision featureDecision = decisionService.getVariationForFeature(featureFlag, userId, copiedAttributes);
652652
if (featureDecision.variation != null) {
653-
LiveVariableUsageInstance liveVariableUsageInstance =
654-
featureDecision.variation.getVariableIdToLiveVariableUsageInstanceMap().get(variable.getId());
655-
if (liveVariableUsageInstance != null) {
656-
variableValue = liveVariableUsageInstance.getValue();
653+
FeatureVariableUsageInstance featureVariableUsageInstance =
654+
featureDecision.variation.getVariableIdToFeatureVariableUsageInstanceMap().get(variable.getId());
655+
if (featureVariableUsageInstance != null) {
656+
variableValue = featureVariableUsageInstance.getValue();
657657
} else {
658658
variableValue = variable.getDefaultValue();
659659
}

core-api/src/main/java/com/optimizely/ab/UnknownLiveVariableException.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

core-api/src/main/java/com/optimizely/ab/config/FeatureFlag.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ public class FeatureFlag implements IdKeyMapped {
3333
private final String key;
3434
private final String rolloutId;
3535
private final List<String> experimentIds;
36-
private final List<LiveVariable> variables;
37-
private final Map<String, LiveVariable> variableKeyToLiveVariableMap;
36+
private final List<FeatureVariable> variables;
37+
private final Map<String, FeatureVariable> variableKeyToFeatureVariableMap;
3838

3939
@JsonCreator
4040
public FeatureFlag(@JsonProperty("id") String id,
4141
@JsonProperty("key") String key,
4242
@JsonProperty("rolloutId") String rolloutId,
4343
@JsonProperty("experimentIds") List<String> experimentIds,
44-
@JsonProperty("variables") List<LiveVariable> variables) {
44+
@JsonProperty("variables") List<FeatureVariable> variables) {
4545
this.id = id;
4646
this.key = key;
4747
this.rolloutId = rolloutId;
4848
this.experimentIds = experimentIds;
4949
this.variables = variables;
50-
this.variableKeyToLiveVariableMap = ProjectConfigUtils.generateNameMapping(variables);
50+
this.variableKeyToFeatureVariableMap = ProjectConfigUtils.generateNameMapping(variables);
5151
}
5252

5353
public String getId() {
@@ -66,12 +66,12 @@ public List<String> getExperimentIds() {
6666
return experimentIds;
6767
}
6868

69-
public List<LiveVariable> getVariables() {
69+
public List<FeatureVariable> getVariables() {
7070
return variables;
7171
}
7272

73-
public Map<String, LiveVariable> getVariableKeyToLiveVariableMap() {
74-
return variableKeyToLiveVariableMap;
73+
public Map<String, FeatureVariable> getVariableKeyToFeatureVariableMap() {
74+
return variableKeyToFeatureVariableMap;
7575
}
7676

7777
@Override
@@ -82,7 +82,7 @@ public String toString() {
8282
", rolloutId='" + rolloutId + '\'' +
8383
", experimentIds=" + experimentIds +
8484
", variables=" + variables +
85-
", variableKeyToLiveVariableMap=" + variableKeyToLiveVariableMap +
85+
", variableKeyToFeatureVariableMap=" + variableKeyToFeatureVariableMap +
8686
'}';
8787
}
8888

@@ -98,7 +98,7 @@ public boolean equals(Object o) {
9898
if (!rolloutId.equals(that.rolloutId)) return false;
9999
if (!experimentIds.equals(that.experimentIds)) return false;
100100
if (!variables.equals(that.variables)) return false;
101-
return variableKeyToLiveVariableMap.equals(that.variableKeyToLiveVariableMap);
101+
return variableKeyToFeatureVariableMap.equals(that.variableKeyToFeatureVariableMap);
102102
}
103103

104104
@Override
@@ -108,7 +108,7 @@ public int hashCode() {
108108
result = 31 * result + rolloutId.hashCode();
109109
result = 31 * result + experimentIds.hashCode();
110110
result = 31 * result + variables.hashCode();
111-
result = 31 * result + variableKeyToLiveVariableMap.hashCode();
111+
result = 31 * result + variableKeyToFeatureVariableMap.hashCode();
112112
return result;
113113
}
114114
}

core-api/src/main/java/com/optimizely/ab/config/LiveVariable.java renamed to core-api/src/main/java/com/optimizely/ab/config/FeatureVariable.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
import javax.annotation.Nullable;
2626

2727
/**
28-
* Represents a live variable definition at the project level
28+
* Represents a feature variable definition at the project level
2929
*/
3030
@JsonIgnoreProperties(ignoreUnknown = true)
31-
public class LiveVariable implements IdKeyMapped {
31+
public class FeatureVariable implements IdKeyMapped {
3232

3333
public enum VariableStatus {
3434
@SerializedName("active")
@@ -106,11 +106,11 @@ public static VariableType fromString(String variableTypeString) {
106106
private final VariableStatus status;
107107

108108
@JsonCreator
109-
public LiveVariable(@JsonProperty("id") String id,
110-
@JsonProperty("key") String key,
111-
@JsonProperty("defaultValue") String defaultValue,
112-
@JsonProperty("status") VariableStatus status,
113-
@JsonProperty("type") VariableType type) {
109+
public FeatureVariable(@JsonProperty("id") String id,
110+
@JsonProperty("key") String key,
111+
@JsonProperty("defaultValue") String defaultValue,
112+
@JsonProperty("status") VariableStatus status,
113+
@JsonProperty("type") VariableType type) {
114114
this.id = id;
115115
this.key = key;
116116
this.defaultValue = defaultValue;
@@ -141,7 +141,7 @@ public VariableType getType() {
141141

142142
@Override
143143
public String toString() {
144-
return "LiveVariable{" +
144+
return "FeatureVariable{" +
145145
"id='" + id + '\'' +
146146
", key='" + key + '\'' +
147147
", defaultValue='" + defaultValue + '\'' +
@@ -155,7 +155,7 @@ public boolean equals(Object o) {
155155
if (this == o) return true;
156156
if (o == null || getClass() != o.getClass()) return false;
157157

158-
LiveVariable variable = (LiveVariable) o;
158+
FeatureVariable variable = (FeatureVariable) o;
159159

160160
if (!id.equals(variable.id)) return false;
161161
if (!key.equals(variable.key)) return false;

core-api/src/main/java/com/optimizely/ab/config/LiveVariableUsageInstance.java renamed to core-api/src/main/java/com/optimizely/ab/config/FeatureVariableUsageInstance.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016-2017, Optimizely and contributors
3+
* Copyright 2016-2017, 2019, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -21,17 +21,17 @@
2121
import com.fasterxml.jackson.annotation.JsonProperty;
2222

2323
/**
24-
* Represents the value of a live variable for a variation
24+
* Represents the value of a feature variable for a variation
2525
*/
2626
@JsonIgnoreProperties(ignoreUnknown = true)
27-
public class LiveVariableUsageInstance implements IdMapped {
27+
public class FeatureVariableUsageInstance implements IdMapped {
2828

2929
private final String id;
3030
private final String value;
3131

3232
@JsonCreator
33-
public LiveVariableUsageInstance(@JsonProperty("id") String id,
34-
@JsonProperty("value") String value) {
33+
public FeatureVariableUsageInstance(@JsonProperty("id") String id,
34+
@JsonProperty("value") String value) {
3535
this.id = id;
3636
this.value = value;
3737
}
@@ -49,7 +49,7 @@ public boolean equals(Object o) {
4949
if (this == o) return true;
5050
if (o == null || getClass() != o.getClass()) return false;
5151

52-
LiveVariableUsageInstance that = (LiveVariableUsageInstance) o;
52+
FeatureVariableUsageInstance that = (FeatureVariableUsageInstance) o;
5353

5454
return id.equals(that.id) && value.equals(that.value);
5555
}

0 commit comments

Comments
 (0)