Skip to content

Commit b551357

Browse files
authored
feat: added enabled field in metadata. (#409)
1 parent 288036f commit b551357

File tree

5 files changed

+34
-12
lines changed

5 files changed

+34
-12
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private void sendImpression(@Nonnull ProjectConfig projectConfig,
237237
@Nonnull Map<String, ?> filteredAttributes,
238238
@Nonnull Variation variation,
239239
@Nonnull String ruleType) {
240-
sendImpression(projectConfig, experiment, userId, filteredAttributes, variation, "", ruleType);
240+
sendImpression(projectConfig, experiment, userId, filteredAttributes, variation, "", ruleType, true);
241241
}
242242

243243
/**
@@ -257,7 +257,8 @@ private void sendImpression(@Nonnull ProjectConfig projectConfig,
257257
@Nonnull Map<String, ?> filteredAttributes,
258258
@Nonnull Variation variation,
259259
@Nonnull String flagKey,
260-
@Nonnull String ruleType) {
260+
@Nonnull String ruleType,
261+
@Nonnull boolean enabled) {
261262

262263
UserEvent userEvent = UserEventFactory.createImpressionEvent(
263264
projectConfig,
@@ -266,7 +267,8 @@ private void sendImpression(@Nonnull ProjectConfig projectConfig,
266267
userId,
267268
filteredAttributes,
268269
flagKey,
269-
ruleType);
270+
ruleType,
271+
enabled);
270272

271273
if (userEvent == null) {
272274
return;
@@ -430,7 +432,8 @@ private Boolean isFeatureEnabled(@Nonnull ProjectConfig projectConfig,
430432
copiedAttributes,
431433
featureDecision.variation,
432434
featureKey,
433-
decisionSource.toString());
435+
decisionSource.toString(),
436+
featureEnabled);
434437

435438
if (featureDecision.variation != null) {
436439
// This information is only necessary for feature tests.

core-api/src/main/java/com/optimizely/ab/event/internal/UserEventFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public static ImpressionEvent createImpressionEvent(@Nonnull ProjectConfig proje
3737
@Nonnull String userId,
3838
@Nonnull Map<String, ?> attributes,
3939
@Nonnull String flagKey,
40-
@Nonnull String ruleType) {
40+
@Nonnull String ruleType,
41+
@Nonnull boolean enabled) {
4142

4243
if ((FeatureDecision.DecisionSource.ROLLOUT.toString().equals(ruleType) || variation == null) && !projectConfig.getSendFlagDecisions())
4344
{
@@ -69,6 +70,7 @@ public static ImpressionEvent createImpressionEvent(@Nonnull ProjectConfig proje
6970
.setRuleKey(experimentKey)
7071
.setRuleType(ruleType)
7172
.setVariationKey(variationKey)
73+
.setEnabled(enabled)
7274
.build();
7375

7476
return new ImpressionEvent.Builder()

core-api/src/main/java/com/optimizely/ab/event/internal/payload/DecisionMetadata.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,19 @@ public class DecisionMetadata {
2929
String ruleType;
3030
@JsonProperty("variation_key")
3131
String variationKey;
32+
@JsonProperty("enabled")
33+
boolean enabled;
3234

3335
@VisibleForTesting
3436
public DecisionMetadata() {
3537
}
3638

37-
public DecisionMetadata(String flagKey, String ruleKey, String ruleType, String variationKey) {
39+
public DecisionMetadata(String flagKey, String ruleKey, String ruleType, String variationKey, boolean enabled) {
3840
this.flagKey = flagKey;
3941
this.ruleKey = ruleKey;
4042
this.ruleType = ruleType;
4143
this.variationKey = variationKey;
44+
this.enabled = enabled;
4245
}
4346

4447
public String getRuleType() {
@@ -49,6 +52,10 @@ public String getRuleKey() {
4952
return ruleKey;
5053
}
5154

55+
public boolean getEnabled() {
56+
return enabled;
57+
}
58+
5259
public String getFlagKey() {
5360
return flagKey;
5461
}
@@ -67,6 +74,7 @@ public boolean equals(Object o) {
6774
if (!ruleType.equals(that.ruleType)) return false;
6875
if (!ruleKey.equals(that.ruleKey)) return false;
6976
if (!flagKey.equals(that.flagKey)) return false;
77+
if (enabled != that.enabled) return false;
7078
return variationKey.equals(that.variationKey);
7179
}
7280

@@ -85,6 +93,12 @@ public static class Builder {
8593
private String ruleKey;
8694
private String flagKey;
8795
private String variationKey;
96+
private boolean enabled;
97+
98+
public Builder setEnabled(boolean enabled) {
99+
this.enabled = enabled;
100+
return this;
101+
}
88102

89103
public Builder setRuleType(String ruleType) {
90104
this.ruleType = ruleType;
@@ -107,7 +121,7 @@ public Builder setVariationKey(String variationKey) {
107121
}
108122

109123
public DecisionMetadata build() {
110-
return new DecisionMetadata(flagKey, ruleKey, ruleType, variationKey);
124+
return new DecisionMetadata(flagKey, ruleKey, ruleType, variationKey, enabled);
111125
}
112126
}
113127
}

core-api/src/test/java/com/optimizely/ab/event/internal/EventFactoryTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void createImpressionEventPassingUserAgentAttribute() throws Exception {
103103
Map<String, String> attributeMap = new HashMap<String, String>();
104104
attributeMap.put(attribute.getKey(), "value");
105105
attributeMap.put(ControlAttribute.USER_AGENT_ATTRIBUTE.toString(), "Chrome");
106-
DecisionMetadata metadata = new DecisionMetadata(activatedExperiment.getKey(), activatedExperiment.getKey(), ruleType, "variationKey");
106+
DecisionMetadata metadata = new DecisionMetadata(activatedExperiment.getKey(), activatedExperiment.getKey(), ruleType, "variationKey", true);
107107
Decision expectedDecision = new Decision.Builder()
108108
.setCampaignId(activatedExperiment.getLayerId())
109109
.setExperimentId(activatedExperiment.getId())
@@ -1062,7 +1062,8 @@ public static LogEvent createImpressionEvent(ProjectConfig projectConfig,
10621062
userId,
10631063
attributes,
10641064
activatedExperiment.getKey(),
1065-
"experiment");
1065+
"experiment",
1066+
true);
10661067

10671068
return EventFactory.createLogEvent(userEvent);
10681069

core-api/src/test/java/com/optimizely/ab/event/internal/UserEventFactoryTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class UserEventFactoryTest {
6767
public void setUp() {
6868
experiment = new Experiment(EXPERIMENT_ID, EXPERIMENT_KEY, LAYER_ID);
6969
variation = new Variation(VARIATION_ID, VARIATION_KEY);
70-
decisionMetadata = new DecisionMetadata("", EXPERIMENT_KEY, "experiment", VARIATION_KEY);
70+
decisionMetadata = new DecisionMetadata("", EXPERIMENT_KEY, "experiment", VARIATION_KEY, true);
7171
}
7272

7373
@Test
@@ -80,7 +80,8 @@ public void createImpressionEventNull() {
8080
USER_ID,
8181
ATTRIBUTES,
8282
EXPERIMENT_KEY,
83-
"rollout"
83+
"rollout",
84+
false
8485
);
8586
assertNull(actual);
8687
}
@@ -94,7 +95,8 @@ public void createImpressionEvent() {
9495
USER_ID,
9596
ATTRIBUTES,
9697
"",
97-
"experiment"
98+
"experiment",
99+
true
98100
);
99101

100102
assertTrue(actual.getTimestamp() > 0);

0 commit comments

Comments
 (0)