1
1
/****************************************************************************
2
- * Copyright 2016-2020 , Optimizely, Inc. and contributors *
2
+ * Copyright 2016-2021 , 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. *
34
34
import com .optimizely .ab .optimizelyconfig .OptimizelyConfig ;
35
35
import com .optimizely .ab .optimizelyconfig .OptimizelyConfigManager ;
36
36
import com .optimizely .ab .optimizelyconfig .OptimizelyConfigService ;
37
- import com .optimizely .ab .optimizelydecision .DecisionMessage ;
38
- import com .optimizely .ab .optimizelydecision .DecisionReasons ;
39
- import com .optimizely .ab .optimizelydecision .DefaultDecisionReasons ;
40
- import com .optimizely .ab .optimizelydecision .OptimizelyDecideOption ;
41
- import com .optimizely .ab .optimizelydecision .OptimizelyDecision ;
37
+ import com .optimizely .ab .optimizelydecision .*;
42
38
import com .optimizely .ab .optimizelyjson .OptimizelyJSON ;
43
39
import org .slf4j .Logger ;
44
40
import org .slf4j .LoggerFactory ;
@@ -427,7 +423,7 @@ private Boolean isFeatureEnabled(@Nonnull ProjectConfig projectConfig,
427
423
428
424
Map <String , ?> copiedAttributes = copyAttributes (attributes );
429
425
FeatureDecision .DecisionSource decisionSource = FeatureDecision .DecisionSource .ROLLOUT ;
430
- FeatureDecision featureDecision = decisionService .getVariationForFeature (featureFlag , userId , copiedAttributes , projectConfig );
426
+ FeatureDecision featureDecision = decisionService .getVariationForFeature (featureFlag , userId , copiedAttributes , projectConfig ). getResult () ;
431
427
Boolean featureEnabled = false ;
432
428
SourceInfo sourceInfo = new RolloutSourceInfo ();
433
429
if (featureDecision .decisionSource != null ) {
@@ -736,7 +732,7 @@ <T> T getFeatureVariableValueForType(@Nonnull String featureKey,
736
732
737
733
String variableValue = variable .getDefaultValue ();
738
734
Map <String , ?> copiedAttributes = copyAttributes (attributes );
739
- FeatureDecision featureDecision = decisionService .getVariationForFeature (featureFlag , userId , copiedAttributes , projectConfig );
735
+ FeatureDecision featureDecision = decisionService .getVariationForFeature (featureFlag , userId , copiedAttributes , projectConfig ). getResult () ;
740
736
Boolean featureEnabled = false ;
741
737
if (featureDecision .variation != null ) {
742
738
if (featureDecision .variation .getFeatureEnabled ()) {
@@ -869,7 +865,7 @@ public OptimizelyJSON getAllFeatureVariables(@Nonnull String featureKey,
869
865
}
870
866
871
867
Map <String , ?> copiedAttributes = copyAttributes (attributes );
872
- FeatureDecision featureDecision = decisionService .getVariationForFeature (featureFlag , userId , copiedAttributes , projectConfig );
868
+ FeatureDecision featureDecision = decisionService .getVariationForFeature (featureFlag , userId , copiedAttributes , projectConfig ). getResult () ;
873
869
Boolean featureEnabled = false ;
874
870
Variation variation = featureDecision .variation ;
875
871
@@ -970,7 +966,7 @@ private Variation getVariation(@Nonnull ProjectConfig projectConfig,
970
966
@ Nonnull String userId ,
971
967
@ Nonnull Map <String , ?> attributes ) throws UnknownExperimentException {
972
968
Map <String , ?> copiedAttributes = copyAttributes (attributes );
973
- Variation variation = decisionService .getVariation (experiment , userId , copiedAttributes , projectConfig );
969
+ Variation variation = decisionService .getVariation (experiment , userId , copiedAttributes , projectConfig ). getResult () ;
974
970
975
971
String notificationType = NotificationCenter .DecisionNotificationType .AB_TEST .toString ();
976
972
@@ -1084,7 +1080,7 @@ public Variation getForcedVariation(@Nonnull String experimentKey,
1084
1080
return null ;
1085
1081
}
1086
1082
1087
- return decisionService .getForcedVariation (experiment , userId );
1083
+ return decisionService .getForcedVariation (experiment , userId ). getResult () ;
1088
1084
}
1089
1085
1090
1086
/**
@@ -1182,13 +1178,14 @@ OptimizelyDecision decide(@Nonnull OptimizelyUserContext user,
1182
1178
DecisionReasons decisionReasons = DefaultDecisionReasons .newInstance (allOptions );
1183
1179
1184
1180
Map <String , ?> copiedAttributes = new HashMap <>(attributes );
1185
- FeatureDecision flagDecision = decisionService .getVariationForFeature (
1181
+ DecisionResponse < FeatureDecision > decisionVariation = decisionService .getVariationForFeature (
1186
1182
flag ,
1187
1183
userId ,
1188
1184
copiedAttributes ,
1189
1185
projectConfig ,
1190
- allOptions ,
1191
- decisionReasons );
1186
+ allOptions );
1187
+ FeatureDecision flagDecision = decisionVariation .getResult ();
1188
+ decisionReasons .merge (decisionVariation .getReasons ());
1192
1189
1193
1190
Boolean flagEnabled = false ;
1194
1191
if (flagDecision .variation != null ) {
@@ -1200,11 +1197,12 @@ OptimizelyDecision decide(@Nonnull OptimizelyUserContext user,
1200
1197
1201
1198
Map <String , Object > variableMap = new HashMap <>();
1202
1199
if (!allOptions .contains (OptimizelyDecideOption .EXCLUDE_VARIABLES )) {
1203
- variableMap = getDecisionVariableMap (
1200
+ DecisionResponse < Map < String , Object >> decisionVariables = getDecisionVariableMap (
1204
1201
flag ,
1205
1202
flagDecision .variation ,
1206
- flagEnabled ,
1207
- decisionReasons );
1203
+ flagEnabled );
1204
+ variableMap = decisionVariables .getResult ();
1205
+ decisionReasons .merge (decisionVariables .getReasons ());
1208
1206
}
1209
1207
OptimizelyJSON optimizelyJSON = new OptimizelyJSON (variableMap );
1210
1208
@@ -1305,10 +1303,12 @@ private List<OptimizelyDecideOption> getAllOptions(List<OptimizelyDecideOption>
1305
1303
return copiedOptions ;
1306
1304
}
1307
1305
1308
- private Map <String , Object > getDecisionVariableMap (@ Nonnull FeatureFlag flag ,
1309
- @ Nonnull Variation variation ,
1310
- @ Nonnull Boolean featureEnabled ,
1311
- @ Nonnull DecisionReasons decisionReasons ) {
1306
+ @ Nonnull
1307
+ private DecisionResponse <Map <String , Object >> getDecisionVariableMap (@ Nonnull FeatureFlag flag ,
1308
+ @ Nonnull Variation variation ,
1309
+ @ Nonnull Boolean featureEnabled ) {
1310
+ DecisionReasons reasons = new DecisionReasons ();
1311
+
1312
1312
Map <String , Object > valuesMap = new HashMap <String , Object >();
1313
1313
for (FeatureVariable variable : flag .getVariables ()) {
1314
1314
String value = variable .getDefaultValue ();
@@ -1321,15 +1321,15 @@ private Map<String, Object> getDecisionVariableMap(@Nonnull FeatureFlag flag,
1321
1321
1322
1322
Object convertedValue = convertStringToType (value , variable .getType ());
1323
1323
if (convertedValue == null ) {
1324
- decisionReasons .addError (DecisionMessage .VARIABLE_VALUE_INVALID .reason (variable .getKey ()));
1324
+ reasons .addError (DecisionMessage .VARIABLE_VALUE_INVALID .reason (variable .getKey ()));
1325
1325
} else if (convertedValue instanceof OptimizelyJSON ) {
1326
1326
convertedValue = ((OptimizelyJSON ) convertedValue ).toMap ();
1327
1327
}
1328
1328
1329
1329
valuesMap .put (variable .getKey (), convertedValue );
1330
1330
}
1331
1331
1332
- return valuesMap ;
1332
+ return new DecisionResponse ( valuesMap , reasons ) ;
1333
1333
}
1334
1334
1335
1335
/**
0 commit comments