|
1 | 1 | /****************************************************************************
|
2 |
| - * Copyright 2016-2022, Optimizely, Inc. and contributors * |
| 2 | + * Copyright 2016-2023, Optimizely, Inc. and contributors * |
3 | 3 | * *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); *
|
5 | 5 | * you may not use this file except in compliance with the License. *
|
@@ -436,7 +436,7 @@ private Boolean isFeatureEnabled(@Nonnull ProjectConfig projectConfig,
|
436 | 436 |
|
437 | 437 | Map<String, ?> copiedAttributes = copyAttributes(attributes);
|
438 | 438 | FeatureDecision.DecisionSource decisionSource = FeatureDecision.DecisionSource.ROLLOUT;
|
439 |
| - FeatureDecision featureDecision = decisionService.getVariationForFeature(featureFlag, createUserContext(userId, copiedAttributes), projectConfig).getResult(); |
| 439 | + FeatureDecision featureDecision = decisionService.getVariationForFeature(featureFlag, createUserContextCopy(userId, copiedAttributes), projectConfig).getResult(); |
440 | 440 | Boolean featureEnabled = false;
|
441 | 441 | SourceInfo sourceInfo = new RolloutSourceInfo();
|
442 | 442 | if (featureDecision.decisionSource != null) {
|
@@ -745,7 +745,7 @@ <T> T getFeatureVariableValueForType(@Nonnull String featureKey,
|
745 | 745 |
|
746 | 746 | String variableValue = variable.getDefaultValue();
|
747 | 747 | Map<String, ?> copiedAttributes = copyAttributes(attributes);
|
748 |
| - FeatureDecision featureDecision = decisionService.getVariationForFeature(featureFlag, createUserContext(userId, copiedAttributes), projectConfig).getResult(); |
| 748 | + FeatureDecision featureDecision = decisionService.getVariationForFeature(featureFlag, createUserContextCopy(userId, copiedAttributes), projectConfig).getResult(); |
749 | 749 | Boolean featureEnabled = false;
|
750 | 750 | if (featureDecision.variation != null) {
|
751 | 751 | if (featureDecision.variation.getFeatureEnabled()) {
|
@@ -880,7 +880,7 @@ public OptimizelyJSON getAllFeatureVariables(@Nonnull String featureKey,
|
880 | 880 | }
|
881 | 881 |
|
882 | 882 | Map<String, ?> copiedAttributes = copyAttributes(attributes);
|
883 |
| - FeatureDecision featureDecision = decisionService.getVariationForFeature(featureFlag, createUserContext(userId, copiedAttributes), projectConfig, Collections.emptyList()).getResult(); |
| 883 | + FeatureDecision featureDecision = decisionService.getVariationForFeature(featureFlag, createUserContextCopy(userId, copiedAttributes), projectConfig, Collections.emptyList()).getResult(); |
884 | 884 | Boolean featureEnabled = false;
|
885 | 885 | Variation variation = featureDecision.variation;
|
886 | 886 |
|
@@ -982,7 +982,7 @@ private Variation getVariation(@Nonnull ProjectConfig projectConfig,
|
982 | 982 | @Nonnull String userId,
|
983 | 983 | @Nonnull Map<String, ?> attributes) throws UnknownExperimentException {
|
984 | 984 | Map<String, ?> copiedAttributes = copyAttributes(attributes);
|
985 |
| - Variation variation = decisionService.getVariation(experiment, createUserContext(userId, copiedAttributes), projectConfig).getResult(); |
| 985 | + Variation variation = decisionService.getVariation(experiment, createUserContextCopy(userId, copiedAttributes), projectConfig).getResult(); |
986 | 986 | String notificationType = NotificationCenter.DecisionNotificationType.AB_TEST.toString();
|
987 | 987 |
|
988 | 988 | if (projectConfig.getExperimentFeatureKeyMapping().get(experiment.getId()) != null) {
|
@@ -1172,6 +1172,14 @@ public OptimizelyUserContext createUserContext(@Nonnull String userId) {
|
1172 | 1172 | return new OptimizelyUserContext(this, userId);
|
1173 | 1173 | }
|
1174 | 1174 |
|
| 1175 | + private OptimizelyUserContext createUserContextCopy(@Nonnull String userId, @Nonnull Map<String, ?> attributes) { |
| 1176 | + if (userId == null) { |
| 1177 | + logger.warn("The userId parameter must be nonnull."); |
| 1178 | + return null; |
| 1179 | + } |
| 1180 | + return new OptimizelyUserContext(this, userId, attributes, Collections.EMPTY_MAP, null, false); |
| 1181 | + } |
| 1182 | + |
1175 | 1183 | OptimizelyDecision decide(@Nonnull OptimizelyUserContext user,
|
1176 | 1184 | @Nonnull String key,
|
1177 | 1185 | @Nonnull List<OptimizelyDecideOption> options) {
|
|
0 commit comments