5
5
import com .eppo .sdk .dto .AssignmentLogData ;
6
6
import com .eppo .sdk .dto .EppoClientConfig ;
7
7
import com .eppo .sdk .dto .EppoValue ;
8
+ import com .eppo .sdk .dto .EppoValueType ;
8
9
import com .eppo .sdk .dto .ExperimentConfiguration ;
9
10
import com .eppo .sdk .dto .Rule ;
10
11
import com .eppo .sdk .dto .SubjectAttributes ;
@@ -55,7 +56,7 @@ private EppoClient(ConfigurationStore configurationStore, Timer poller, EppoClie
55
56
* @param subjectAttributes
56
57
* @return
57
58
*/
58
- public Optional <String > getAssignment (
59
+ private Optional <EppoValue > getAssignment (
59
60
String subjectKey ,
60
61
String flagKey ,
61
62
SubjectAttributes subjectAttributes
@@ -74,7 +75,7 @@ public Optional<String> getAssignment(
74
75
// Check if subject has override variations
75
76
EppoValue subjectVariationOverride = this .getSubjectVariationOverride (subjectKey , configuration );
76
77
if (!subjectVariationOverride .isNull ()) {
77
- return Optional .of (subjectVariationOverride . stringValue () );
78
+ return Optional .of (subjectVariationOverride );
78
79
}
79
80
80
81
// Check if disabled
@@ -104,14 +105,14 @@ public Optional<String> getAssignment(
104
105
this .eppoClientConfig .getAssignmentLogger ()
105
106
.logAssignment (new AssignmentLogData (
106
107
flagKey ,
107
- assignedVariation .getValue ().stringValue (),
108
+ assignedVariation .getTypedValue ().stringValue (),
108
109
subjectKey ,
109
110
subjectAttributes
110
111
));
111
112
} catch (Exception e ){
112
113
// Ignore Exception
113
114
}
114
- return Optional .of (assignedVariation .getValue (). stringValue ());
115
+ return Optional .of (assignedVariation .getTypedValue ());
115
116
}
116
117
117
118
/**
@@ -121,16 +122,125 @@ public Optional<String> getAssignment(
121
122
* @param experimentKey
122
123
* @return
123
124
*/
124
- public Optional <String > getAssignment (String subjectKey , String experimentKey ) {
125
+ private Optional <EppoValue > getAssignment (String subjectKey , String experimentKey ) {
125
126
return this .getAssignment (subjectKey , experimentKey , new SubjectAttributes ());
126
127
}
127
128
129
+ /**
130
+ * This function will return typed assignment value
131
+ * @param subjectKey
132
+ * @param experimentKey
133
+ * @param type
134
+ * @param subjectAttributes
135
+ * @return
136
+ */
137
+ private Optional <?> getTypedAssignment (String subjectKey , String experimentKey , EppoValueType type , SubjectAttributes subjectAttributes ) {
138
+ Optional <EppoValue > value = this .getAssignment (subjectKey , experimentKey , subjectAttributes );
139
+ if (value .isEmpty ()) {
140
+ return Optional .empty ();
141
+ }
142
+
143
+ switch (type ) {
144
+ case BOOLEAN :
145
+ return Optional .of (value .get ().boolValue ());
146
+ case NUMBER :
147
+ return Optional .of (value .get ().doubleValue ());
148
+ default :
149
+ return Optional .of (value .get ().stringValue ());
150
+ }
151
+ }
152
+
153
+ /**
154
+ * This function will return string assignment value
155
+ * @param subjectKey
156
+ * @param experimentKey
157
+ * @param subjectAttributes
158
+ * @return
159
+ */
160
+ public Optional <String > getStringAssignment (String subjectKey , String experimentKey , SubjectAttributes subjectAttributes ) {
161
+ return (Optional <String >) this .getTypedAssignment (subjectKey , experimentKey , EppoValueType .STRING , subjectAttributes );
162
+ }
163
+
164
+ /**
165
+ * This function will return string assignment value without passing subjectAttributes
166
+ * @param subjectKey
167
+ * @param experimentKey
168
+ * @return
169
+ */
170
+ public Optional <String > getStringAssignment (String subjectKey , String experimentKey ) {
171
+ return this .getStringAssignment (subjectKey , experimentKey , new SubjectAttributes ());
172
+ }
173
+
174
+ /**
175
+ * This function will return boolean assignment value
176
+ * @param subjectKey
177
+ * @param experimentKey
178
+ * @param subjectAttributes
179
+ * @return
180
+ */
181
+ public Optional <Boolean > getBooleanAssignment (String subjectKey , String experimentKey , SubjectAttributes subjectAttributes ) {
182
+ return (Optional <Boolean >) this .getTypedAssignment (subjectKey , experimentKey , EppoValueType .BOOLEAN , subjectAttributes );
183
+ }
184
+
185
+ /**
186
+ * This function will return boolean assignment value without passing subjectAttributes
187
+ * @param subjectKey
188
+ * @param experimentKey
189
+ * @return
190
+ */
191
+ public Optional <Boolean > getBooleanAssignment (String subjectKey , String experimentKey ) {
192
+ return this .getBooleanAssignment (subjectKey , experimentKey , new SubjectAttributes ());
193
+ }
194
+
195
+ /**
196
+ * This function will return double assignment value
197
+ * @param subjectKey
198
+ * @param experimentKey
199
+ * @param subjectAttributes
200
+ * @return
201
+ */
202
+ public Optional <Double > getDoubleAssignment (String subjectKey , String experimentKey , SubjectAttributes subjectAttributes ) {
203
+ return (Optional <Double >) this .getTypedAssignment (subjectKey , experimentKey , EppoValueType .NUMBER , subjectAttributes );
204
+ }
205
+
206
+ /**
207
+ * This function will return long assignment value without passing subjectAttributes
208
+ * @param subjectKey
209
+ * @param experimentKey
210
+ * @return
211
+ */
212
+ public Optional <Double > getDoubleAssignment (String subjectKey , String experimentKey ) {
213
+ return this .getDoubleAssignment (subjectKey , experimentKey , new SubjectAttributes ());
214
+ }
215
+
216
+ /**
217
+ * This function will return json string assignment value
218
+ * @param subjectKey
219
+ * @param experimentKey
220
+ * @param subjectAttributes
221
+ * @return
222
+ */
223
+ public Optional <String > getJSONAssignment (String subjectKey , String experimentKey , SubjectAttributes subjectAttributes ) {
224
+ return this .getStringAssignment (subjectKey , experimentKey , subjectAttributes );
225
+ }
226
+
227
+ /**
228
+ * This function will return json string assignment value without passing subjectAttributes
229
+ * @param subjectKey
230
+ * @param experimentKey
231
+ * @return
232
+ */
233
+ public Optional <String > getJSONAssignment (String subjectKey , String experimentKey ) {
234
+ return this .getJSONAssignment (subjectKey , experimentKey , new SubjectAttributes ());
235
+ }
236
+
128
237
/**
129
238
* This function is used to check if the Experiment is in the same
130
239
*
131
240
* @param subjectKey
132
241
* @param experimentKey
133
- * @param experimentConfiguration
242
+ * @param subjectShards
243
+ * @param percentageExposure
134
244
* @return
135
245
*/
136
246
private boolean isInExperimentSample (
@@ -148,7 +258,8 @@ private boolean isInExperimentSample(
148
258
*
149
259
* @param subjectKey
150
260
* @param experimentKey
151
- * @param experimentConfiguration
261
+ * @param subjectShards
262
+ * @param subjectShards
152
263
* @return
153
264
*/
154
265
private Variation getAssignedVariation (
@@ -178,7 +289,7 @@ private EppoValue getSubjectVariationOverride(
178
289
ExperimentConfiguration experimentConfiguration
179
290
) {
180
291
String hexedSubjectKey = Shard .getHex (subjectKey );
181
- return experimentConfiguration .getOverrides ().getOrDefault (hexedSubjectKey , new EppoValue ());
292
+ return experimentConfiguration .getTypedOverrides ().getOrDefault (hexedSubjectKey , new EppoValue ());
182
293
}
183
294
184
295
/***
0 commit comments