1
1
package dev .openfeature .contrib .providers .flipt ;
2
2
3
- import com .flipt .api .FliptApiClient ;
4
- import com .flipt .api .resources .evaluation .types .BooleanEvaluationResponse ;
5
- import com .flipt .api .resources .evaluation .types .EvaluationRequest ;
6
- import com .flipt .api .resources .evaluation .types .VariantEvaluationResponse ;
7
3
import dev .openfeature .sdk .EvaluationContext ;
8
4
import dev .openfeature .sdk .EventProvider ;
9
5
import dev .openfeature .sdk .ImmutableMetadata ;
14
10
import dev .openfeature .sdk .Value ;
15
11
import dev .openfeature .sdk .exceptions .GeneralError ;
16
12
import dev .openfeature .sdk .exceptions .ProviderNotReadyError ;
13
+ import io .flipt .api .FliptClient ;
14
+ import io .flipt .api .evaluation .models .BooleanEvaluationResponse ;
15
+ import io .flipt .api .evaluation .models .EvaluationRequest ;
16
+ import io .flipt .api .evaluation .models .VariantEvaluationResponse ;
17
17
import lombok .AccessLevel ;
18
18
import lombok .Getter ;
19
19
import lombok .Setter ;
@@ -41,7 +41,7 @@ public class FliptProvider extends EventProvider {
41
41
42
42
@ Setter (AccessLevel .PROTECTED )
43
43
@ Getter
44
- private FliptApiClient fliptApiClient ;
44
+ private FliptClient fliptClient ;
45
45
46
46
@ Setter (AccessLevel .PROTECTED )
47
47
@ Getter
@@ -51,6 +51,7 @@ public class FliptProvider extends EventProvider {
51
51
52
52
/**
53
53
* Constructor.
54
+ *
54
55
* @param fliptProviderConfig FliptProviderConfig
55
56
*/
56
57
public FliptProvider (FliptProviderConfig fliptProviderConfig ) {
@@ -59,6 +60,7 @@ public FliptProvider(FliptProviderConfig fliptProviderConfig) {
59
60
60
61
/**
61
62
* Initialize the provider.
63
+ *
62
64
* @param evaluationContext evaluation context
63
65
* @throws Exception on error
64
66
*/
@@ -69,7 +71,7 @@ public void initialize(EvaluationContext evaluationContext) throws Exception {
69
71
throw new GeneralError ("already initialized" );
70
72
}
71
73
super .initialize (evaluationContext );
72
- fliptApiClient = fliptProviderConfig .getFliptApiClientBuilder ().build ();
74
+ fliptClient = fliptProviderConfig .getFliptClientBuilder ().build ();
73
75
74
76
state = ProviderState .READY ;
75
77
log .info ("finished initializing provider, state: {}" , state );
@@ -103,45 +105,45 @@ public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defa
103
105
104
106
Map <String , String > contextMap = ContextTransformer .transform (ctx );
105
107
EvaluationRequest request = EvaluationRequest .builder ().namespaceKey (fliptProviderConfig .getNamespace ())
106
- .flagKey (key ).entityId (ctx .getTargetingKey ()).context (contextMap ).build ();
108
+ .flagKey (key ).entityId (ctx .getTargetingKey ()).context (contextMap ).build ();
107
109
108
110
BooleanEvaluationResponse response = null ;
109
111
try {
110
- response = fliptApiClient .evaluation ().boolean_ (request );
112
+ response = fliptClient .evaluation ().evaluateBoolean (request );
111
113
} catch (Exception e ) {
112
114
log .error ("Error evaluating boolean" , e );
113
115
throw new GeneralError (e .getMessage ());
114
116
}
115
117
116
118
return ProviderEvaluation .<Boolean >builder ()
117
- .value (response .getEnabled ())
118
- .reason (response .getReason ().toString ())
119
- .build ();
119
+ .value (response .isEnabled ())
120
+ .reason (response .getReason ().toString ())
121
+ .build ();
120
122
}
121
123
122
124
@ Override
123
125
public ProviderEvaluation <String > getStringEvaluation (String key , String defaultValue , EvaluationContext ctx ) {
124
126
ProviderEvaluation <Value > valueProviderEvaluation = getObjectEvaluation (key , new Value (defaultValue ), ctx );
125
127
return ProviderEvaluation .<String >builder ()
126
- .value (valueProviderEvaluation .getValue ().asString ())
127
- .variant (valueProviderEvaluation .getVariant ())
128
+ .value (valueProviderEvaluation .getValue ().asString ())
129
+ .variant (valueProviderEvaluation .getVariant ())
128
130
.errorCode (valueProviderEvaluation .getErrorCode ())
129
131
.reason (valueProviderEvaluation .getReason ())
130
132
.flagMetadata (valueProviderEvaluation .getFlagMetadata ())
131
- .build ();
133
+ .build ();
132
134
}
133
135
134
136
@ Override
135
137
public ProviderEvaluation <Integer > getIntegerEvaluation (String key , Integer defaultValue , EvaluationContext ctx ) {
136
138
ProviderEvaluation <Value > valueProviderEvaluation = getObjectEvaluation (key , new Value (defaultValue ), ctx );
137
139
Integer value = getIntegerValue (valueProviderEvaluation , defaultValue );
138
140
return ProviderEvaluation .<Integer >builder ()
139
- .value (value )
140
- .variant (valueProviderEvaluation .getVariant ())
141
- .errorCode (valueProviderEvaluation .getErrorCode ())
142
- .reason (valueProviderEvaluation .getReason ())
143
- .flagMetadata (valueProviderEvaluation .getFlagMetadata ())
144
- .build ();
141
+ .value (value )
142
+ .variant (valueProviderEvaluation .getVariant ())
143
+ .errorCode (valueProviderEvaluation .getErrorCode ())
144
+ .reason (valueProviderEvaluation .getReason ())
145
+ .flagMetadata (valueProviderEvaluation .getFlagMetadata ())
146
+ .build ();
145
147
}
146
148
147
149
private static Integer getIntegerValue (ProviderEvaluation <Value > valueProviderEvaluation , Integer defaultValue ) {
@@ -158,12 +160,12 @@ public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double default
158
160
ProviderEvaluation <Value > valueProviderEvaluation = getObjectEvaluation (key , new Value (defaultValue ), ctx );
159
161
Double value = getDoubleValue (valueProviderEvaluation , defaultValue );
160
162
return ProviderEvaluation .<Double >builder ()
161
- .value (value )
162
- .variant (valueProviderEvaluation .getVariant ())
163
- .errorCode (valueProviderEvaluation .getErrorCode ())
164
- .reason (valueProviderEvaluation .getReason ())
165
- .flagMetadata (valueProviderEvaluation .getFlagMetadata ())
166
- .build ();
163
+ .value (value )
164
+ .variant (valueProviderEvaluation .getVariant ())
165
+ .errorCode (valueProviderEvaluation .getErrorCode ())
166
+ .reason (valueProviderEvaluation .getReason ())
167
+ .flagMetadata (valueProviderEvaluation .getFlagMetadata ())
168
+ .build ();
167
169
}
168
170
169
171
private static Double getDoubleValue (ProviderEvaluation <Value > valueProviderEvaluation , Double defaultValue ) {
@@ -185,22 +187,22 @@ public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultVa
185
187
}
186
188
Map <String , String > contextMap = ContextTransformer .transform (ctx );
187
189
EvaluationRequest request = EvaluationRequest .builder ().namespaceKey (fliptProviderConfig .getNamespace ())
188
- .flagKey (key ).entityId (ctx .getTargetingKey ()).context (contextMap ).build ();
190
+ .flagKey (key ).entityId (ctx .getTargetingKey ()).context (contextMap ).build ();
189
191
190
192
VariantEvaluationResponse response ;
191
193
try {
192
- response = fliptApiClient .evaluation ().variant (request );
194
+ response = fliptClient .evaluation ().evaluateVariant (request );
193
195
} catch (Exception e ) {
194
196
log .error ("Error evaluating variant" , e );
195
197
throw new GeneralError (e .getMessage ());
196
198
}
197
199
198
- if (!response .getMatch ()) {
200
+ if (!response .isMatch ()) {
199
201
log .debug ("non matching variant for {} : {}" , key , response .getReason ());
200
202
return ProviderEvaluation .<Value >builder ()
201
- .value (defaultValue )
202
- .reason (DEFAULT .name ())
203
- .build ();
203
+ .value (defaultValue )
204
+ .reason (DEFAULT .name ())
205
+ .build ();
204
206
}
205
207
206
208
ImmutableMetadata .ImmutableMetadataBuilder flagMetadataBuilder = ImmutableMetadata .builder ();
@@ -209,11 +211,11 @@ public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultVa
209
211
}
210
212
211
213
return ProviderEvaluation .<Value >builder ()
212
- .value (new Value (response .getVariantKey ()))
213
- .variant (response .getVariantKey ())
214
- .reason (TARGETING_MATCH .name ())
215
- .flagMetadata (flagMetadataBuilder .build ())
216
- .build ();
214
+ .value (new Value (response .getVariantKey ()))
215
+ .variant (response .getVariantKey ())
216
+ .reason (TARGETING_MATCH .name ())
217
+ .flagMetadata (flagMetadataBuilder .build ())
218
+ .build ();
217
219
}
218
220
219
221
@ Override
0 commit comments