1
1
/****************************************************************************
2
- * Copyright 2016-2023 , Optimizely, Inc. and contributors *
2
+ * Copyright 2016-2024 , 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. *
42
42
import javax .annotation .Nonnull ;
43
43
import javax .annotation .Nullable ;
44
44
import javax .annotation .concurrent .ThreadSafe ;
45
- import javax .xml .catalog .CatalogFeatures .Feature ;
46
45
47
46
import java .io .Closeable ;
48
47
import java .util .*;
@@ -1193,111 +1192,6 @@ private OptimizelyUserContext createUserContextCopy(@Nonnull String userId, @Non
1193
1192
return new OptimizelyUserContext (this , userId , attributes , Collections .EMPTY_MAP , null , false );
1194
1193
}
1195
1194
1196
- // OptimizelyDecision decide(@Nonnull OptimizelyUserContext user,
1197
- // @Nonnull String key,
1198
- // @Nonnull List<OptimizelyDecideOption> options) {
1199
- //
1200
- // ProjectConfig projectConfig = getProjectConfig();
1201
- // if (projectConfig == null) {
1202
- // return OptimizelyDecision.newErrorDecision(key, user, DecisionMessage.SDK_NOT_READY.reason());
1203
- // }
1204
- //
1205
- // FeatureFlag flag = projectConfig.getFeatureKeyMapping().get(key);
1206
- // if (flag == null) {
1207
- // return OptimizelyDecision.newErrorDecision(key, user, DecisionMessage.FLAG_KEY_INVALID.reason(key));
1208
- // }
1209
- //
1210
- // String userId = user.getUserId();
1211
- // Map<String, Object> attributes = user.getAttributes();
1212
- // Boolean decisionEventDispatched = false;
1213
- // List<OptimizelyDecideOption> allOptions = getAllOptions(options);
1214
- // DecisionReasons decisionReasons = DefaultDecisionReasons.newInstance(allOptions);
1215
- //
1216
- // Map<String, ?> copiedAttributes = new HashMap<>(attributes);
1217
- // FeatureDecision flagDecision;
1218
- //
1219
- // // Check Forced Decision
1220
- // OptimizelyDecisionContext optimizelyDecisionContext = new OptimizelyDecisionContext(flag.getKey(), null);
1221
- // DecisionResponse<Variation> forcedDecisionVariation = decisionService.validatedForcedDecision(optimizelyDecisionContext, projectConfig, user);
1222
- // decisionReasons.merge(forcedDecisionVariation.getReasons());
1223
- // if (forcedDecisionVariation.getResult() != null) {
1224
- // flagDecision = new FeatureDecision(null, forcedDecisionVariation.getResult(), FeatureDecision.DecisionSource.FEATURE_TEST);
1225
- // } else {
1226
- // // Regular decision
1227
- // DecisionResponse<FeatureDecision> decisionVariation = decisionService.getVariationForFeature(
1228
- // flag,
1229
- // user,
1230
- // projectConfig,
1231
- // allOptions);
1232
- // flagDecision = decisionVariation.getResult();
1233
- // decisionReasons.merge(decisionVariation.getReasons());
1234
- // }
1235
- //
1236
- // Boolean flagEnabled = false;
1237
- // if (flagDecision.variation != null) {
1238
- // if (flagDecision.variation.getFeatureEnabled()) {
1239
- // flagEnabled = true;
1240
- // }
1241
- // }
1242
- // logger.info("Feature \"{}\" is enabled for user \"{}\"? {}", key, userId, flagEnabled);
1243
- //
1244
- // Map<String, Object> variableMap = new HashMap<>();
1245
- // if (!allOptions.contains(OptimizelyDecideOption.EXCLUDE_VARIABLES)) {
1246
- // DecisionResponse<Map<String, Object>> decisionVariables = getDecisionVariableMap(
1247
- // flag,
1248
- // flagDecision.variation,
1249
- // flagEnabled);
1250
- // variableMap = decisionVariables.getResult();
1251
- // decisionReasons.merge(decisionVariables.getReasons());
1252
- // }
1253
- // OptimizelyJSON optimizelyJSON = new OptimizelyJSON(variableMap);
1254
- //
1255
- // FeatureDecision.DecisionSource decisionSource = FeatureDecision.DecisionSource.ROLLOUT;
1256
- // if (flagDecision.decisionSource != null) {
1257
- // decisionSource = flagDecision.decisionSource;
1258
- // }
1259
- //
1260
- // List<String> reasonsToReport = decisionReasons.toReport();
1261
- // String variationKey = flagDecision.variation != null ? flagDecision.variation.getKey() : null;
1262
- // // TODO: add ruleKey values when available later. use a copy of experimentKey until then.
1263
- // // add to event metadata as well (currently set to experimentKey)
1264
- // String ruleKey = flagDecision.experiment != null ? flagDecision.experiment.getKey() : null;
1265
- //
1266
- // if (!allOptions.contains(OptimizelyDecideOption.DISABLE_DECISION_EVENT)) {
1267
- // decisionEventDispatched = sendImpression(
1268
- // projectConfig,
1269
- // flagDecision.experiment,
1270
- // userId,
1271
- // copiedAttributes,
1272
- // flagDecision.variation,
1273
- // key,
1274
- // decisionSource.toString(),
1275
- // flagEnabled);
1276
- // }
1277
- //
1278
- // DecisionNotification decisionNotification = DecisionNotification.newFlagDecisionNotificationBuilder()
1279
- // .withUserId(userId)
1280
- // .withAttributes(copiedAttributes)
1281
- // .withFlagKey(key)
1282
- // .withEnabled(flagEnabled)
1283
- // .withVariables(variableMap)
1284
- // .withVariationKey(variationKey)
1285
- // .withRuleKey(ruleKey)
1286
- // .withReasons(reasonsToReport)
1287
- // .withDecisionEventDispatched(decisionEventDispatched)
1288
- // .build();
1289
- // notificationCenter.send(decisionNotification);
1290
- //
1291
- // return new OptimizelyDecision(
1292
- // variationKey,
1293
- // flagEnabled,
1294
- // optimizelyJSON,
1295
- // ruleKey,
1296
- // key,
1297
- // user,
1298
- // reasonsToReport);
1299
- // }
1300
- //
1301
1195
Optional <FeatureDecision > getForcedDecision (@ Nonnull String flagKey ,
1302
1196
@ Nonnull DecisionReasons decisionReasons ,
1303
1197
@ Nonnull ProjectConfig projectConfig ,
@@ -1313,7 +1207,6 @@ Optional<FeatureDecision> getForcedDecision(@Nonnull String flagKey,
1313
1207
return Optional .empty ();
1314
1208
}
1315
1209
1316
- // TODO: UPS refactor cleanup
1317
1210
OptimizelyDecision decide (@ Nonnull OptimizelyUserContext user ,
1318
1211
@ Nonnull String key ,
1319
1212
@ Nonnull List <OptimizelyDecideOption > options ) {
@@ -1322,106 +1215,6 @@ OptimizelyDecision decide(@Nonnull OptimizelyUserContext user,
1322
1215
return OptimizelyDecision .newErrorDecision (key , user , DecisionMessage .SDK_NOT_READY .reason ());
1323
1216
}
1324
1217
return decideForKeys (user , Arrays .asList (key ), options ).get (key );
1325
-
1326
- // ProjectConfig projectConfig = getProjectConfig();
1327
- // if (projectConfig == null) {
1328
- // return OptimizelyDecision.newErrorDecision(key, user, DecisionMessage.SDK_NOT_READY.reason());
1329
- // }
1330
- //
1331
- // FeatureFlag flag = projectConfig.getFeatureKeyMapping().get(key);
1332
- // if (flag == null) {
1333
- // return OptimizelyDecision.newErrorDecision(key, user, DecisionMessage.FLAG_KEY_INVALID.reason(key));
1334
- // }
1335
- //
1336
- // String userId = user.getUserId();
1337
- // Map<String, Object> attributes = user.getAttributes();
1338
- // Boolean decisionEventDispatched = false;
1339
- // List<OptimizelyDecideOption> allOptions = getAllOptions(options);
1340
- // DecisionReasons decisionReasons = DefaultDecisionReasons.newInstance(allOptions);
1341
- //
1342
- // Map<String, ?> copiedAttributes = new HashMap<>(attributes);
1343
- // FeatureDecision flagDecision;
1344
- //
1345
- // // Check Forced Decision
1346
- // OptimizelyDecisionContext optimizelyDecisionContext = new OptimizelyDecisionContext(flag.getKey(), null);
1347
- // DecisionResponse<Variation> forcedDecisionVariation = decisionService.validatedForcedDecision(optimizelyDecisionContext, projectConfig, user);
1348
- // decisionReasons.merge(forcedDecisionVariation.getReasons());
1349
- // if (forcedDecisionVariation.getResult() != null) {
1350
- // flagDecision = new FeatureDecision(null, forcedDecisionVariation.getResult(), FeatureDecision.DecisionSource.FEATURE_TEST);
1351
- // } else {
1352
- // // Regular decision
1353
- // DecisionResponse<FeatureDecision> decisionVariation = decisionService.getVariationForFeature(
1354
- // flag,
1355
- // user,
1356
- // projectConfig,
1357
- // allOptions);
1358
- // flagDecision = decisionVariation.getResult();
1359
- // decisionReasons.merge(decisionVariation.getReasons());
1360
- // }
1361
- //
1362
- // Boolean flagEnabled = false;
1363
- // if (flagDecision.variation != null) {
1364
- // if (flagDecision.variation.getFeatureEnabled()) {
1365
- // flagEnabled = true;
1366
- // }
1367
- // }
1368
- // logger.info("Feature \"{}\" is enabled for user \"{}\"? {}", key, userId, flagEnabled);
1369
- //
1370
- // Map<String, Object> variableMap = new HashMap<>();
1371
- // if (!allOptions.contains(OptimizelyDecideOption.EXCLUDE_VARIABLES)) {
1372
- // DecisionResponse<Map<String, Object>> decisionVariables = getDecisionVariableMap(
1373
- // flag,
1374
- // flagDecision.variation,
1375
- // flagEnabled);
1376
- // variableMap = decisionVariables.getResult();
1377
- // decisionReasons.merge(decisionVariables.getReasons());
1378
- // }
1379
- // OptimizelyJSON optimizelyJSON = new OptimizelyJSON(variableMap);
1380
- //
1381
- // FeatureDecision.DecisionSource decisionSource = FeatureDecision.DecisionSource.ROLLOUT;
1382
- // if (flagDecision.decisionSource != null) {
1383
- // decisionSource = flagDecision.decisionSource;
1384
- // }
1385
- //
1386
- // List<String> reasonsToReport = decisionReasons.toReport();
1387
- // String variationKey = flagDecision.variation != null ? flagDecision.variation.getKey() : null;
1388
- // // TODO: add ruleKey values when available later. use a copy of experimentKey until then.
1389
- // // add to event metadata as well (currently set to experimentKey)
1390
- // String ruleKey = flagDecision.experiment != null ? flagDecision.experiment.getKey() : null;
1391
- //
1392
- // if (!allOptions.contains(OptimizelyDecideOption.DISABLE_DECISION_EVENT)) {
1393
- // decisionEventDispatched = sendImpression(
1394
- // projectConfig,
1395
- // flagDecision.experiment,
1396
- // userId,
1397
- // copiedAttributes,
1398
- // flagDecision.variation,
1399
- // key,
1400
- // decisionSource.toString(),
1401
- // flagEnabled);
1402
- // }
1403
- //
1404
- // DecisionNotification decisionNotification = DecisionNotification.newFlagDecisionNotificationBuilder()
1405
- // .withUserId(userId)
1406
- // .withAttributes(copiedAttributes)
1407
- // .withFlagKey(key)
1408
- // .withEnabled(flagEnabled)
1409
- // .withVariables(variableMap)
1410
- // .withVariationKey(variationKey)
1411
- // .withRuleKey(ruleKey)
1412
- // .withReasons(reasonsToReport)
1413
- // .withDecisionEventDispatched(decisionEventDispatched)
1414
- // .build();
1415
- // notificationCenter.send(decisionNotification);
1416
- //
1417
- // return new OptimizelyDecision(
1418
- // variationKey,
1419
- // flagEnabled,
1420
- // optimizelyJSON,
1421
- // ruleKey,
1422
- // key,
1423
- // user,
1424
- // reasonsToReport);
1425
1218
}
1426
1219
1427
1220
private OptimizelyDecision createOptimizelyDecision (
@@ -1505,7 +1298,6 @@ private OptimizelyDecision createOptimizelyDecision(
1505
1298
reasonsToReport );
1506
1299
}
1507
1300
1508
- // TODO: UPS refactor cleanup
1509
1301
Map <String , OptimizelyDecision > decideForKeys (@ Nonnull OptimizelyUserContext user ,
1510
1302
@ Nonnull List <String > keys ,
1511
1303
@ Nonnull List <OptimizelyDecideOption > options ) {
@@ -1570,31 +1362,6 @@ Map<String, OptimizelyDecision> decideForKeys(@Nonnull OptimizelyUserContext use
1570
1362
1571
1363
return decisionMap ;
1572
1364
}
1573
-
1574
- // Map<String, OptimizelyDecision> decideForKeys(@Nonnull OptimizelyUserContext user,
1575
- // @Nonnull List<String> keys,
1576
- // @Nonnull List<OptimizelyDecideOption> options) {
1577
- // Map<String, OptimizelyDecision> decisionMap = new HashMap<>();
1578
- //
1579
- // ProjectConfig projectConfig = getProjectConfig();
1580
- // if (projectConfig == null) {
1581
- // logger.error("Optimizely instance is not valid, failing isFeatureEnabled call.");
1582
- // return decisionMap;
1583
- // }
1584
- //
1585
- // if (keys.isEmpty()) return decisionMap;
1586
- //
1587
- // List<OptimizelyDecideOption> allOptions = getAllOptions(options);
1588
- //
1589
- // for (String key : keys) {
1590
- // OptimizelyDecision decision = decide(user, key, options);
1591
- // if (!allOptions.contains(OptimizelyDecideOption.ENABLED_FLAGS_ONLY) || decision.getEnabled()) {
1592
- // decisionMap.put(key, decision);
1593
- // }
1594
- // }
1595
- //
1596
- // return decisionMap;
1597
- // }
1598
1365
1599
1366
Map <String , OptimizelyDecision > decideAll (@ Nonnull OptimizelyUserContext user ,
1600
1367
@ Nonnull List <OptimizelyDecideOption > options ) {
0 commit comments