Skip to content

Commit 13d3ef1

Browse files
Linting issue
Signed-off-by: Thomas Poignant <[email protected]>
1 parent 949f971 commit 13d3ef1

File tree

1 file changed

+41
-20
lines changed

1 file changed

+41
-20
lines changed

Diff for: providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/GoFeatureFlagProvider.java

+41-20
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939

4040
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
4141

42+
/**
43+
* GoFeatureFlagProvider is the JAVA provider implementation for the feature flag solution GO Feature Flag.
44+
*/
4245
public class GoFeatureFlagProvider implements FeatureProvider {
4346
private static final String NAME = "GO Feature Flag Provider";
4447
private static final ObjectMapper requestMapper = new ObjectMapper();
@@ -48,7 +51,8 @@ public class GoFeatureFlagProvider implements FeatureProvider {
4851
private OkHttpClient httpClient;
4952

5053
/**
51-
* Constructor of the provider
54+
* Constructor of the provider.
55+
*
5256
* @param options - options to configure the provider
5357
* @throws InvalidOptions - if options are invalid
5458
*/
@@ -77,7 +81,7 @@ private void validateInputOptions(GoFeatureFlagProviderOptions options) throws I
7781
}
7882

7983
/**
80-
* initializeProvider is initializing the different class element used by the provider
84+
* initializeProvider is initializing the different class element used by the provider.
8185
*
8286
* @param options - Options used while creating the provider
8387
*/
@@ -113,32 +117,42 @@ public List<Hook> getProviderHooks() {
113117

114118

115119
@Override
116-
public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext evaluationContext) {
120+
public ProviderEvaluation<Boolean> getBooleanEvaluation(
121+
String key, Boolean defaultValue, EvaluationContext evaluationContext
122+
) {
117123
return resolveEvaluationGoFeatureFlagProxy(key, defaultValue, evaluationContext, Boolean.class);
118124
}
119125

120126
@Override
121-
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext evaluationContext) {
127+
public ProviderEvaluation<String> getStringEvaluation(
128+
String key, String defaultValue, EvaluationContext evaluationContext
129+
) {
122130
return resolveEvaluationGoFeatureFlagProxy(key, defaultValue, evaluationContext, String.class);
123131
}
124132

125133
@Override
126-
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext evaluationContext) {
134+
public ProviderEvaluation<Integer> getIntegerEvaluation(
135+
String key, Integer defaultValue, EvaluationContext evaluationContext
136+
) {
127137
return resolveEvaluationGoFeatureFlagProxy(key, defaultValue, evaluationContext, Integer.class);
128138
}
129139

130140
@Override
131-
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext evaluationContext) {
141+
public ProviderEvaluation<Double> getDoubleEvaluation(
142+
String key, Double defaultValue, EvaluationContext evaluationContext
143+
) {
132144
return resolveEvaluationGoFeatureFlagProxy(key, defaultValue, evaluationContext, Double.class);
133145
}
134146

135147
@Override
136-
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue, EvaluationContext evaluationContext) {
148+
public ProviderEvaluation<Value> getObjectEvaluation(
149+
String key, Value defaultValue, EvaluationContext evaluationContext
150+
) {
137151
return resolveEvaluationGoFeatureFlagProxy(key, defaultValue, evaluationContext, Value.class);
138152
}
139153

140154
/**
141-
* resolveEvaluationGoFeatureFlagProxy is calling the GO Feature Flag API to retrieve the flag value
155+
* resolveEvaluationGoFeatureFlagProxy is calling the GO Feature Flag API to retrieve the flag value.
142156
*
143157
* @param key - name of the feature flag
144158
* @param defaultValue - value used if something is not working as expected
@@ -147,7 +161,9 @@ public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultVa
147161
* @return a ProviderEvaluation that contains the open-feature response
148162
* @throws OpenFeatureError - if an error happen
149163
*/
150-
private <T> ProviderEvaluation<T> resolveEvaluationGoFeatureFlagProxy(String key, T defaultValue, EvaluationContext ctx, Class<? extends Object> expectedType) throws OpenFeatureError {
164+
private <T> ProviderEvaluation<T> resolveEvaluationGoFeatureFlagProxy(
165+
String key, T defaultValue, EvaluationContext ctx, Class<? extends Object> expectedType)
166+
throws OpenFeatureError {
151167
try {
152168
GoFeatureFlagUser user = GoFeatureFlagUser.fromEvaluationContext(ctx);
153169
GoFeatureFlagRequest<T> goffRequest = new GoFeatureFlagRequest<T>(user, defaultValue);
@@ -162,14 +178,17 @@ private <T> ProviderEvaluation<T> resolveEvaluationGoFeatureFlagProxy(String key
162178
Request request = new Request.Builder()
163179
.url(url)
164180
.addHeader("Content-Type", "application/json")
165-
.post(RequestBody.create(requestMapper.writeValueAsBytes(goffRequest), MediaType.get("application/json; charset=utf-8")))
181+
.post(RequestBody.create(
182+
requestMapper.writeValueAsBytes(goffRequest),
183+
MediaType.get("application/json; charset=utf-8")))
166184
.build();
167185

168186
try (Response response = this.httpClient.newCall(request).execute()) {
169187
if (response.code() >= HTTP_BAD_REQUEST) {
170188
throw new GeneralError("impossible to contact GO Feature Flag relay proxy instance");
171189
}
172-
GoFeatureFlagResponse<T> goffResp = responseMapper.readValue(response.body().string(), GoFeatureFlagResponse.class);
190+
GoFeatureFlagResponse<T> goffResp =
191+
responseMapper.readValue(response.body().string(), GoFeatureFlagResponse.class);
173192

174193
if (Reason.DISABLED.name().equalsIgnoreCase(goffResp.getReason())) {
175194
// we don't set a variant since we are using the default value, and we are not able to know
@@ -181,17 +200,18 @@ private <T> ProviderEvaluation<T> resolveEvaluationGoFeatureFlagProxy(String key
181200
throw new FlagNotFoundError("Flag " + key + " was not found in your configuration");
182201
}
183202

184-
boolean isPrimitive = expectedType == Boolean.class ||
185-
expectedType == String.class ||
186-
expectedType == Integer.class ||
187-
expectedType == Double.class;
203+
boolean isPrimitive = expectedType == Boolean.class
204+
|| expectedType == String.class
205+
|| expectedType == Integer.class
206+
|| expectedType == Double.class;
188207

189208
// Convert the value received from the API.
190209
T flagValue = isPrimitive
191210
? goffResp.getValue() : (T) objectToValue(goffResp.getValue());
192211

193212
if (flagValue.getClass() != expectedType) {
194-
throw new TypeMismatchError("Flag value " + key + " had unexpected type " + flagValue.getClass() + ", expected " + expectedType + ".");
213+
throw new TypeMismatchError("Flag value " + key + " had unexpected type "
214+
+ flagValue.getClass() + ", expected " + expectedType + ".");
195215
}
196216

197217
return ProviderEvaluation.<T>builder()
@@ -209,8 +229,7 @@ private <T> ProviderEvaluation<T> resolveEvaluationGoFeatureFlagProxy(String key
209229

210230

211231
/**
212-
* mapReason is mapping the reason in string received by the API
213-
* to our internal SDK reason enum.
232+
* mapReason is mapping the reason in string received by the API to our internal SDK reason enum.
214233
*
215234
* @param reason - string of the reason received from the API
216235
* @return an item from the enum
@@ -258,13 +277,15 @@ private Value objectToValue(Object object) {
258277
}
259278

260279
/**
261-
* mapToStructure transform a map coming from a JSON Object to a Structure type
280+
* mapToStructure transform a map coming from a JSON Object to a Structure type.
262281
*
263282
* @param map - JSON object return by the API
264283
* @return a Structure object in the SDK format
265284
*/
266285
private Structure mapToStructure(Map<String, Object> map) {
267286
return new Structure(
268-
map.entrySet().stream().filter(e -> e.getValue() != null).collect(Collectors.toMap(Map.Entry::getKey, e -> objectToValue(e.getValue()))));
287+
map.entrySet().stream()
288+
.filter(e -> e.getValue() != null)
289+
.collect(Collectors.toMap(Map.Entry::getKey, e -> objectToValue(e.getValue()))));
269290
}
270291
}

0 commit comments

Comments
 (0)