Skip to content

Commit 968343f

Browse files
authored
Evaluation options, prereqs & imp disabled in Android implementation (#150)
1 parent 31901cb commit 968343f

File tree

14 files changed

+299
-122
lines changed

14 files changed

+299
-122
lines changed

splitio_android/android/src/main/java/io/split/splitio/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static class Argument {
4141
static final String SDK_CONFIGURATION = "sdkConfiguration";
4242
static final String SPLIT_NAME = "splitName";
4343
static final String ATTRIBUTES = "attributes";
44+
static final String EVALUATION_OPTIONS = "evaluationOptions";
4445
static final String EVENT_TYPE = "eventType";
4546
static final String TRAFFIC_TYPE = "trafficType";
4647
static final String VALUE = "value";

splitio_android/android/src/main/java/io/split/splitio/EvaluationWrapper.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
import java.util.List;
44
import java.util.Map;
55

6+
import io.split.android.client.EvaluationOptions;
67
import io.split.android.client.SplitResult;
78

89
interface EvaluationWrapper {
9-
String getTreatment(String matchingKey, String bucketingKey, String splitName, Map<String, Object> attributes);
10+
String getTreatment(String matchingKey, String bucketingKey, String splitName, Map<String, Object> attributes, EvaluationOptions evaluationOptions);
1011

11-
Map<String, String> getTreatments(String matchingKey, String bucketingKey, List<String> splitNames, Map<String, Object> attributes);
12+
Map<String, String> getTreatments(String matchingKey, String bucketingKey, List<String> splitNames, Map<String, Object> attributes, EvaluationOptions evaluationOptions);
1213

13-
SplitResult getTreatmentWithConfig(String matchingKey, String bucketingKey, String splitName, Map<String, Object> attributes);
14+
SplitResult getTreatmentWithConfig(String matchingKey, String bucketingKey, String splitName, Map<String, Object> attributes, EvaluationOptions evaluationOptions);
1415

15-
Map<String, SplitResult> getTreatmentsWithConfig(String matchingKey, String bucketingKey, List<String> splitNames, Map<String, Object> attributes);
16+
Map<String, SplitResult> getTreatmentsWithConfig(String matchingKey, String bucketingKey, List<String> splitNames, Map<String, Object> attributes, EvaluationOptions evaluationOptions);
1617

17-
Map<String, String> getTreatmentsByFlagSet(String matchingKey, String bucketingKey, String flagSet, Map<String, Object> attributes);
18+
Map<String, String> getTreatmentsByFlagSet(String matchingKey, String bucketingKey, String flagSet, Map<String, Object> attributes, EvaluationOptions evaluationOptions);
1819

19-
Map<String, String> getTreatmentsByFlagSets(String matchingKey, String bucketingKey, List<String> flagSets, Map<String, Object> attributes);
20+
Map<String, String> getTreatmentsByFlagSets(String matchingKey, String bucketingKey, List<String> flagSets, Map<String, Object> attributes, EvaluationOptions evaluationOptions);
2021

21-
Map<String, SplitResult> getTreatmentsWithConfigByFlagSet(String matchingKey, String bucketingKey, String flagSet, Map<String, Object> attributes);
22+
Map<String, SplitResult> getTreatmentsWithConfigByFlagSet(String matchingKey, String bucketingKey, String flagSet, Map<String, Object> attributes, EvaluationOptions evaluationOptions);
2223

23-
Map<String, SplitResult> getTreatmentsWithConfigByFlagSets(String matchingKey, String bucketingKey, List<String> flagSets, Map<String, Object> attributes);
24+
Map<String, SplitResult> getTreatmentsWithConfigByFlagSets(String matchingKey, String bucketingKey, List<String> flagSets, Map<String, Object> attributes, EvaluationOptions evaluationOptions);
2425
}

splitio_android/android/src/main/java/io/split/splitio/SplitMethodParserImpl.java

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static io.split.splitio.Constants.Argument.ATTRIBUTES;
55
import static io.split.splitio.Constants.Argument.ATTRIBUTE_NAME;
66
import static io.split.splitio.Constants.Argument.BUCKETING_KEY;
7+
import static io.split.splitio.Constants.Argument.EVALUATION_OPTIONS;
78
import static io.split.splitio.Constants.Argument.EVENT_TYPE;
89
import static io.split.splitio.Constants.Argument.FLAG_SET;
910
import static io.split.splitio.Constants.Argument.FLAG_SETS;
@@ -57,9 +58,11 @@
5758
import java.util.Map;
5859

5960
import io.flutter.plugin.common.MethodChannel;
61+
import io.split.android.client.EvaluationOptions;
6062
import io.split.android.client.SplitClient;
6163
import io.split.android.client.SplitResult;
6264
import io.split.android.client.api.SplitView;
65+
import io.split.android.client.dtos.Prerequisite;
6366
import io.split.android.client.events.SplitEvent;
6467
import io.split.android.client.events.SplitEventTask;
6568

@@ -115,56 +118,64 @@ public void onMethodCall(String methodName, Object arguments, @NonNull MethodCha
115118
mArgumentParser.getStringArgument(MATCHING_KEY, arguments),
116119
mArgumentParser.getStringArgument(BUCKETING_KEY, arguments),
117120
mArgumentParser.getStringArgument(SPLIT_NAME, arguments),
118-
mArgumentParser.getMapArgument(ATTRIBUTES, arguments)));
121+
mArgumentParser.getMapArgument(ATTRIBUTES, arguments),
122+
buildEvaluationOptions(mArgumentParser.getMapArgument(EVALUATION_OPTIONS, arguments))));
119123
break;
120124
case GET_TREATMENTS:
121125
result.success(getTreatments(
122126
mArgumentParser.getStringArgument(MATCHING_KEY, arguments),
123127
mArgumentParser.getStringArgument(BUCKETING_KEY, arguments),
124128
mArgumentParser.getStringListArgument(SPLIT_NAME, arguments),
125-
mArgumentParser.getMapArgument(ATTRIBUTES, arguments)));
129+
mArgumentParser.getMapArgument(ATTRIBUTES, arguments),
130+
buildEvaluationOptions(mArgumentParser.getMapArgument(EVALUATION_OPTIONS, arguments))));
126131
break;
127132
case GET_TREATMENT_WITH_CONFIG:
128133
result.success(getTreatmentWithConfig(
129134
mArgumentParser.getStringArgument(MATCHING_KEY, arguments),
130135
mArgumentParser.getStringArgument(BUCKETING_KEY, arguments),
131136
mArgumentParser.getStringArgument(SPLIT_NAME, arguments),
132-
mArgumentParser.getMapArgument(ATTRIBUTES, arguments)));
137+
mArgumentParser.getMapArgument(ATTRIBUTES, arguments),
138+
buildEvaluationOptions(mArgumentParser.getMapArgument(EVALUATION_OPTIONS, arguments))));
133139
break;
134140
case GET_TREATMENTS_WITH_CONFIG:
135141
result.success(getTreatmentsWithConfig(
136142
mArgumentParser.getStringArgument(MATCHING_KEY, arguments),
137143
mArgumentParser.getStringArgument(BUCKETING_KEY, arguments),
138144
mArgumentParser.getStringListArgument(SPLIT_NAME, arguments),
139-
mArgumentParser.getMapArgument(ATTRIBUTES, arguments)));
145+
mArgumentParser.getMapArgument(ATTRIBUTES, arguments),
146+
buildEvaluationOptions(mArgumentParser.getMapArgument(EVALUATION_OPTIONS, arguments))));
140147
break;
141148
case GET_TREATMENTS_BY_FLAG_SET:
142149
result.success(getTreatmentsByFlagSet(
143150
mArgumentParser.getStringArgument(MATCHING_KEY, arguments),
144151
mArgumentParser.getStringArgument(BUCKETING_KEY, arguments),
145152
mArgumentParser.getStringArgument(FLAG_SET, arguments),
146-
mArgumentParser.getMapArgument(ATTRIBUTES, arguments)));
153+
mArgumentParser.getMapArgument(ATTRIBUTES, arguments),
154+
buildEvaluationOptions(mArgumentParser.getMapArgument(EVALUATION_OPTIONS, arguments))));
147155
break;
148156
case GET_TREATMENTS_BY_FLAG_SETS:
149157
result.success(getTreatmentsByFlagSets(
150158
mArgumentParser.getStringArgument(MATCHING_KEY, arguments),
151159
mArgumentParser.getStringArgument(BUCKETING_KEY, arguments),
152160
mArgumentParser.getStringListArgument(FLAG_SETS, arguments),
153-
mArgumentParser.getMapArgument(ATTRIBUTES, arguments)));
161+
mArgumentParser.getMapArgument(ATTRIBUTES, arguments),
162+
buildEvaluationOptions(mArgumentParser.getMapArgument(EVALUATION_OPTIONS, arguments))));
154163
break;
155164
case GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET:
156165
result.success(getTreatmentsWithConfigByFlagSet(
157166
mArgumentParser.getStringArgument(MATCHING_KEY, arguments),
158167
mArgumentParser.getStringArgument(BUCKETING_KEY, arguments),
159168
mArgumentParser.getStringArgument(FLAG_SET, arguments),
160-
mArgumentParser.getMapArgument(ATTRIBUTES, arguments)));
169+
mArgumentParser.getMapArgument(ATTRIBUTES, arguments),
170+
buildEvaluationOptions(mArgumentParser.getMapArgument(EVALUATION_OPTIONS, arguments))));
161171
break;
162172
case GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS:
163173
result.success(getTreatmentsWithConfigByFlagSets(
164174
mArgumentParser.getStringArgument(MATCHING_KEY, arguments),
165175
mArgumentParser.getStringArgument(BUCKETING_KEY, arguments),
166176
mArgumentParser.getStringListArgument(FLAG_SETS, arguments),
167-
mArgumentParser.getMapArgument(ATTRIBUTES, arguments)));
177+
mArgumentParser.getMapArgument(ATTRIBUTES, arguments),
178+
buildEvaluationOptions(mArgumentParser.getMapArgument(EVALUATION_OPTIONS, arguments))));
168179
break;
169180
case TRACK:
170181
result.success(track(
@@ -277,23 +288,26 @@ private SplitClient getClient(String matchingKey, String bucketingKey) {
277288
private String getTreatment(String matchingKey,
278289
String bucketingKey,
279290
String splitName,
280-
Map<String, Object> attributes) {
281-
return mSplitWrapper.getTreatment(matchingKey, bucketingKey, splitName, attributes);
291+
Map<String, Object> attributes,
292+
EvaluationOptions evaluationOptions) {
293+
return mSplitWrapper.getTreatment(matchingKey, bucketingKey, splitName, attributes, evaluationOptions);
282294
}
283295

284296
private Map<String, String> getTreatments(String matchingKey,
285297
String bucketingKey,
286298
List<String> splitNames,
287-
Map<String, Object> attributes) {
288-
return mSplitWrapper.getTreatments(matchingKey, bucketingKey, splitNames, attributes);
299+
Map<String, Object> attributes,
300+
EvaluationOptions evaluationOptions) {
301+
return mSplitWrapper.getTreatments(matchingKey, bucketingKey, splitNames, attributes, evaluationOptions);
289302
}
290303

291304
private Map<String, Map<String, String>> getTreatmentWithConfig(
292305
String matchingKey,
293306
String bucketingKey,
294307
String splitName,
295-
Map<String, Object> attributes) {
296-
SplitResult treatment = mSplitWrapper.getTreatmentWithConfig(matchingKey, bucketingKey, splitName, attributes);
308+
Map<String, Object> attributes,
309+
EvaluationOptions evaluationOptions) {
310+
SplitResult treatment = mSplitWrapper.getTreatmentWithConfig(matchingKey, bucketingKey, splitName, attributes, evaluationOptions);
297311

298312
return Collections.singletonMap(splitName, getSplitResultMap(treatment));
299313
}
@@ -302,42 +316,47 @@ private Map<String, Map<String, String>> getTreatmentsWithConfig(
302316
String matchingKey,
303317
String bucketingKey,
304318
List<String> splitNames,
305-
Map<String, Object> attributes) {
306-
Map<String, SplitResult> treatmentsWithConfig = mSplitWrapper.getTreatmentsWithConfig(matchingKey, bucketingKey, splitNames, attributes);
319+
Map<String, Object> attributes,
320+
EvaluationOptions evaluationOptions) {
321+
Map<String, SplitResult> treatmentsWithConfig = mSplitWrapper.getTreatmentsWithConfig(matchingKey, bucketingKey, splitNames, attributes, evaluationOptions);
307322
return mapToSplitResults(treatmentsWithConfig);
308323
}
309324

310325
private Map<String, String> getTreatmentsByFlagSet(
311326
String matchingKey,
312327
String bucketingKey,
313328
String flagSet,
314-
Map<String, Object> attributes) {
315-
return mSplitWrapper.getTreatmentsByFlagSet(matchingKey, bucketingKey, flagSet, attributes);
329+
Map<String, Object> attributes,
330+
EvaluationOptions evaluationOptions) {
331+
return mSplitWrapper.getTreatmentsByFlagSet(matchingKey, bucketingKey, flagSet, attributes, evaluationOptions);
316332
}
317333

318334
private Map<String, String> getTreatmentsByFlagSets(
319335
String matchingKey,
320336
String bucketingKey,
321337
List<String> flagSets,
322-
Map<String, Object> attributes) {
323-
return mSplitWrapper.getTreatmentsByFlagSets(matchingKey, bucketingKey, flagSets, attributes);
338+
Map<String, Object> attributes,
339+
EvaluationOptions evaluationOptions) {
340+
return mSplitWrapper.getTreatmentsByFlagSets(matchingKey, bucketingKey, flagSets, attributes, evaluationOptions);
324341
}
325342

326343
private Map<String, Map<String, String>> getTreatmentsWithConfigByFlagSet(
327344
String matchingKey,
328345
String bucketingKey,
329346
String flagSet,
330-
Map<String, Object> attributes) {
331-
Map<String, SplitResult> treatmentsWithConfig = mSplitWrapper.getTreatmentsWithConfigByFlagSet(matchingKey, bucketingKey, flagSet, attributes);
347+
Map<String, Object> attributes,
348+
EvaluationOptions evaluationOptions) {
349+
Map<String, SplitResult> treatmentsWithConfig = mSplitWrapper.getTreatmentsWithConfigByFlagSet(matchingKey, bucketingKey, flagSet, attributes, evaluationOptions);
332350
return mapToSplitResults(treatmentsWithConfig);
333351
}
334352

335353
private Map<String, Map<String, String>> getTreatmentsWithConfigByFlagSets(
336354
String matchingKey,
337355
String bucketingKey,
338356
List<String> flagSets,
339-
Map<String, Object> attributes) {
340-
Map<String, SplitResult> treatmentsWithConfig = mSplitWrapper.getTreatmentsWithConfigByFlagSets(matchingKey, bucketingKey, flagSets, attributes);
357+
Map<String, Object> attributes,
358+
EvaluationOptions evaluationOptions) {
359+
Map<String, SplitResult> treatmentsWithConfig = mSplitWrapper.getTreatmentsWithConfigByFlagSets(matchingKey, bucketingKey, flagSets, attributes, evaluationOptions);
341360
return mapToSplitResults(treatmentsWithConfig);
342361
}
343362

@@ -474,8 +493,31 @@ private static Map<String, Object> getSplitViewAsMap(@Nullable SplitView splitVi
474493
splitViewMap.put("configs", splitView.configs);
475494
splitViewMap.put("defaultTreatment", splitView.defaultTreatment);
476495
splitViewMap.put("sets", splitView.sets);
496+
splitViewMap.put("prerequisites", getPrerequisiteMap(splitView.prerequisites));
477497
splitViewMap.put("impressionsDisabled", splitView.impressionsDisabled);
478498

479499
return splitViewMap;
480500
}
501+
502+
private static List<Map<String, Object>> getPrerequisiteMap(List<Prerequisite> prerequisites) {
503+
List<Map<String, Object>> prerequisiteList = new ArrayList<>();
504+
505+
for (Prerequisite prerequisite : prerequisites) {
506+
Map<String, Object> prerequisiteMap = new HashMap<>();
507+
prerequisiteMap.put("n", prerequisite.getFlagName());
508+
prerequisiteMap.put("t", prerequisite.getTreatments());
509+
prerequisiteList.add(prerequisiteMap);
510+
}
511+
512+
return prerequisiteList;
513+
}
514+
515+
@Nullable
516+
private EvaluationOptions buildEvaluationOptions(Map<String, Object> properties) {
517+
if (properties == null || properties.isEmpty()) {
518+
return null;
519+
}
520+
521+
return new EvaluationOptions(properties);
522+
}
481523
}

0 commit comments

Comments
 (0)