11package dev .openfeature .contrib .providers .flipt ;
22
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 ;
73import dev .openfeature .sdk .EvaluationContext ;
84import dev .openfeature .sdk .EventProvider ;
95import dev .openfeature .sdk .ImmutableMetadata ;
1410import dev .openfeature .sdk .Value ;
1511import dev .openfeature .sdk .exceptions .GeneralError ;
1612import 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 ;
1717import lombok .AccessLevel ;
1818import lombok .Getter ;
1919import lombok .Setter ;
@@ -41,7 +41,7 @@ public class FliptProvider extends EventProvider {
4141
4242 @ Setter (AccessLevel .PROTECTED )
4343 @ Getter
44- private FliptApiClient fliptApiClient ;
44+ private FliptClient fliptClient ;
4545
4646 @ Setter (AccessLevel .PROTECTED )
4747 @ Getter
@@ -51,6 +51,7 @@ public class FliptProvider extends EventProvider {
5151
5252 /**
5353 * Constructor.
54+ *
5455 * @param fliptProviderConfig FliptProviderConfig
5556 */
5657 public FliptProvider (FliptProviderConfig fliptProviderConfig ) {
@@ -59,6 +60,7 @@ public FliptProvider(FliptProviderConfig fliptProviderConfig) {
5960
6061 /**
6162 * Initialize the provider.
63+ *
6264 * @param evaluationContext evaluation context
6365 * @throws Exception on error
6466 */
@@ -69,7 +71,7 @@ public void initialize(EvaluationContext evaluationContext) throws Exception {
6971 throw new GeneralError ("already initialized" );
7072 }
7173 super .initialize (evaluationContext );
72- fliptApiClient = fliptProviderConfig .getFliptApiClientBuilder ().build ();
74+ fliptClient = fliptProviderConfig .getFliptClientBuilder ().build ();
7375
7476 state = ProviderState .READY ;
7577 log .info ("finished initializing provider, state: {}" , state );
@@ -103,45 +105,45 @@ public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defa
103105
104106 Map <String , String > contextMap = ContextTransformer .transform (ctx );
105107 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 ();
107109
108110 BooleanEvaluationResponse response = null ;
109111 try {
110- response = fliptApiClient .evaluation ().boolean_ (request );
112+ response = fliptClient .evaluation ().evaluateBoolean (request );
111113 } catch (Exception e ) {
112114 log .error ("Error evaluating boolean" , e );
113115 throw new GeneralError (e .getMessage ());
114116 }
115117
116118 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 ();
120122 }
121123
122124 @ Override
123125 public ProviderEvaluation <String > getStringEvaluation (String key , String defaultValue , EvaluationContext ctx ) {
124126 ProviderEvaluation <Value > valueProviderEvaluation = getObjectEvaluation (key , new Value (defaultValue ), ctx );
125127 return ProviderEvaluation .<String >builder ()
126- .value (valueProviderEvaluation .getValue ().asString ())
127- .variant (valueProviderEvaluation .getVariant ())
128+ .value (valueProviderEvaluation .getValue ().asString ())
129+ .variant (valueProviderEvaluation .getVariant ())
128130 .errorCode (valueProviderEvaluation .getErrorCode ())
129131 .reason (valueProviderEvaluation .getReason ())
130132 .flagMetadata (valueProviderEvaluation .getFlagMetadata ())
131- .build ();
133+ .build ();
132134 }
133135
134136 @ Override
135137 public ProviderEvaluation <Integer > getIntegerEvaluation (String key , Integer defaultValue , EvaluationContext ctx ) {
136138 ProviderEvaluation <Value > valueProviderEvaluation = getObjectEvaluation (key , new Value (defaultValue ), ctx );
137139 Integer value = getIntegerValue (valueProviderEvaluation , defaultValue );
138140 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 ();
145147 }
146148
147149 private static Integer getIntegerValue (ProviderEvaluation <Value > valueProviderEvaluation , Integer defaultValue ) {
@@ -158,12 +160,12 @@ public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double default
158160 ProviderEvaluation <Value > valueProviderEvaluation = getObjectEvaluation (key , new Value (defaultValue ), ctx );
159161 Double value = getDoubleValue (valueProviderEvaluation , defaultValue );
160162 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 ();
167169 }
168170
169171 private static Double getDoubleValue (ProviderEvaluation <Value > valueProviderEvaluation , Double defaultValue ) {
@@ -185,22 +187,22 @@ public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultVa
185187 }
186188 Map <String , String > contextMap = ContextTransformer .transform (ctx );
187189 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 ();
189191
190192 VariantEvaluationResponse response ;
191193 try {
192- response = fliptApiClient .evaluation ().variant (request );
194+ response = fliptClient .evaluation ().evaluateVariant (request );
193195 } catch (Exception e ) {
194196 log .error ("Error evaluating variant" , e );
195197 throw new GeneralError (e .getMessage ());
196198 }
197199
198- if (!response .getMatch ()) {
200+ if (!response .isMatch ()) {
199201 log .debug ("non matching variant for {} : {}" , key , response .getReason ());
200202 return ProviderEvaluation .<Value >builder ()
201- .value (defaultValue )
202- .reason (DEFAULT .name ())
203- .build ();
203+ .value (defaultValue )
204+ .reason (DEFAULT .name ())
205+ .build ();
204206 }
205207
206208 ImmutableMetadata .ImmutableMetadataBuilder flagMetadataBuilder = ImmutableMetadata .builder ();
@@ -209,11 +211,11 @@ public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultVa
209211 }
210212
211213 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 ();
217219 }
218220
219221 @ Override
0 commit comments