Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: autoformat #155

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public static void main(String[] args) throws InterruptedException {
context.add("deviceModel", "Macbook");

// Add Devcycle Custom Data values
Map<String,Object> customData = new LinkedHashMap<>();
Map<String, Object> customData = new LinkedHashMap<>();
customData.put("custom", "value");
context.add("customData", Structure.mapToStructure(customData));

// Add Devcycle Private Custom Data values
Map<String,Object> privateCustomData = new LinkedHashMap<>();
Map<String, Object> privateCustomData = new LinkedHashMap<>();
privateCustomData.put("private", "data");
context.add("privateCustomData", Structure.mapToStructure(privateCustomData));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,51 @@
import com.devcycle.sdk.server.common.api.APIUtils;
import com.devcycle.sdk.server.common.api.IDevCycleApi;
import com.devcycle.sdk.server.common.interceptor.AuthorizationHeaderInterceptor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.annotation.JsonInclude;

import okhttp3.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;

import java.util.Objects;

public final class DevCycleCloudApiClient {

private final OkHttpClient.Builder okBuilder;
private final Retrofit.Builder adapterBuilder;
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private static final String BUCKETING_URL = "https://bucketing-api.devcycle.com/";
private final OkHttpClient.Builder okBuilder;
private final Retrofit.Builder adapterBuilder;
private String bucketingUrl;

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
public DevCycleCloudApiClient(String apiKey, DevCycleCloudOptions options) {
OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
okBuilder = new OkHttpClient.Builder();

private static final String BUCKETING_URL = "https://bucketing-api.devcycle.com/";
private String bucketingUrl;
APIUtils.applyRestOptions(options.getRestOptions(), okBuilder);

public DevCycleCloudApiClient(String apiKey, DevCycleCloudOptions options) {
OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
okBuilder = new OkHttpClient.Builder();
okBuilder.addInterceptor(new AuthorizationHeaderInterceptor(apiKey));

APIUtils.applyRestOptions(options.getRestOptions(), okBuilder);
if (!isStringNullOrEmpty(options.getBaseURLOverride())) {
bucketingUrl = options.getBaseURLOverride();
} else {
bucketingUrl = BUCKETING_URL;
}

okBuilder.addInterceptor(new AuthorizationHeaderInterceptor(apiKey));
bucketingUrl = bucketingUrl.endsWith("/") ? bucketingUrl : bucketingUrl + "/";

if (!isStringNullOrEmpty(options.getBaseURLOverride())) {
bucketingUrl = options.getBaseURLOverride();
} else {
bucketingUrl = BUCKETING_URL;
adapterBuilder = new Retrofit.Builder()
.baseUrl(bucketingUrl)
.addConverterFactory(JacksonConverterFactory.create());
}

bucketingUrl = bucketingUrl.endsWith("/") ? bucketingUrl : bucketingUrl + "/";

adapterBuilder = new Retrofit.Builder()
.baseUrl(bucketingUrl)
.addConverterFactory(JacksonConverterFactory.create());
}

public IDevCycleApi initialize() {
return adapterBuilder
.client(okBuilder.build())
.build()
.create(IDevCycleApi.class);
}
public IDevCycleApi initialize() {
return adapterBuilder
.client(okBuilder.build())
.build()
.create(IDevCycleApi.class);
}

private Boolean isStringNullOrEmpty(String stringToCheck) {
return Objects.isNull(stringToCheck) || Objects.equals(stringToCheck, "");
}
private Boolean isStringNullOrEmpty(String stringToCheck) {
return Objects.isNull(stringToCheck) || Objects.equals(stringToCheck, "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@

public final class DevCycleCloudClient implements IDevCycleClient {

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private final IDevCycleApi api;
private final DevCycleCloudOptions dvcOptions;
private final DevCycleProvider openFeatureProvider;

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

public DevCycleCloudClient(String sdkKey) {
this(sdkKey, DevCycleCloudOptions.builder().build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.devcycle.sdk.server.common.api.IRestOptions;
import com.devcycle.sdk.server.common.logging.IDevCycleLogger;
import com.devcycle.sdk.server.common.model.IDevCycleOptions;

import lombok.Builder;
import lombok.Data;

Expand All @@ -22,5 +21,6 @@ public class DevCycleCloudOptions {
@Builder.Default
private IRestOptions restOptions = null;

public static class DevCycleCloudOptionsBuilder implements IDevCycleOptions { }
public static class DevCycleCloudOptionsBuilder implements IDevCycleOptions {
}
}
10 changes: 4 additions & 6 deletions src/main/java/com/devcycle/sdk/server/common/api/APIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
import okhttp3.OkHttpClient;

public class APIUtils {
public static void applyRestOptions(IRestOptions restOptions, OkHttpClient.Builder builder)
{
if(restOptions != null)
{
if(restOptions.getHostnameVerifier() != null){
public static void applyRestOptions(IRestOptions restOptions, OkHttpClient.Builder builder) {
if (restOptions != null) {
if (restOptions.getHostnameVerifier() != null) {
builder.hostnameVerifier(restOptions.getHostnameVerifier());
}

if(restOptions.getSocketFactory() != null && restOptions.getTrustManager() != null){
if (restOptions.getSocketFactory() != null && restOptions.getTrustManager() != null) {
builder.sslSocketFactory(restOptions.getSocketFactory(), restOptions.getTrustManager());
}
builder.addInterceptor(new CustomHeaderInterceptor(restOptions));
Expand Down
120 changes: 60 additions & 60 deletions src/main/java/com/devcycle/sdk/server/common/api/IDevCycleApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,70 @@
import java.util.Map;

public interface IDevCycleApi {
/**
* Get all features by key for user data
*
* @param user (required)
* @param enableEdgeDB (required)
* @return Call&lt;Map&lt;String, Feature&gt;&gt;
*/
@Headers({"Content-Type:application/json"})
@POST("v1/features")
Call<Map<String, Feature>> getFeatures(@Body DevCycleUser user, @Query("enableEdgeDB") Boolean enableEdgeDB);
/**
* Get all features by key for user data
*
* @param user (required)
* @param enableEdgeDB (required)
* @return Call&lt;Map&lt;String, Feature&gt;&gt;
*/
@Headers({"Content-Type:application/json"})
@POST("v1/features")
Call<Map<String, Feature>> getFeatures(@Body DevCycleUser user, @Query("enableEdgeDB") Boolean enableEdgeDB);

/**
* Get variable by key for user data
*
* @param user (required)
* @param key Variable key (required)
* @param enableEdgeDB (required)
* @return Call&lt;Variable&gt;
*/
@Headers({"Content-Type:application/json"})
@POST("v1/variables/{key}")
Call<Variable> getVariableByKey(@Body DevCycleUser user, @Path("key") String key, @Query("enableEdgeDB") Boolean enableEdgeDB);
/**
* Get variable by key for user data
*
* @param user (required)
* @param key Variable key (required)
* @param enableEdgeDB (required)
* @return Call&lt;Variable&gt;
*/
@Headers({"Content-Type:application/json"})
@POST("v1/variables/{key}")
Call<Variable> getVariableByKey(@Body DevCycleUser user, @Path("key") String key, @Query("enableEdgeDB") Boolean enableEdgeDB);

/**
* Get all variables by key for user data
*
* @param user (required)
* @param enableEdgeDB (required)
* @return Call&lt;Map&lt;String, Variable&gt;&gt;
*/
@Headers({"Content-Type:application/json"})
@POST("v1/variables")
Call<Map<String, BaseVariable>> getVariables(@Body DevCycleUser user, @Query("enableEdgeDB") Boolean enableEdgeDB);
/**
* Get all variables by key for user data
*
* @param user (required)
* @param enableEdgeDB (required)
* @return Call&lt;Map&lt;String, Variable&gt;&gt;
*/
@Headers({"Content-Type:application/json"})
@POST("v1/variables")
Call<Map<String, BaseVariable>> getVariables(@Body DevCycleUser user, @Query("enableEdgeDB") Boolean enableEdgeDB);

/**
* Post events to DevCycle for user
*
* @param userAndEvents (required)
* @param enableEdgeDB (required)
* @return Call&lt;DevCycleResponse&gt;
*/
@Headers({"Content-Type:application/json"})
@POST("v1/track")
Call<DevCycleResponse> track(@Body DevCycleUserAndEvents userAndEvents, @Query("enableEdgeDB") Boolean enableEdgeDB);
/**
* Post events to DevCycle for user
*
* @param userAndEvents (required)
* @param enableEdgeDB (required)
* @return Call&lt;DevCycleResponse&gt;
*/
@Headers({"Content-Type:application/json"})
@POST("v1/track")
Call<DevCycleResponse> track(@Body DevCycleUserAndEvents userAndEvents, @Query("enableEdgeDB") Boolean enableEdgeDB);

/**
* Get DevCycle project Config
*
* @param sdkToken (required)
* @param etag (nullable)
* @return Call&lt;ProjectConfig&gt;
*/
@Headers({"Content-Type:application/json"})
@GET("config/v1/server/{sdkToken}.json")
Call<ProjectConfig> getConfig(@Path("sdkToken") String sdkToken, @Header("If-None-Match") String etag);
/**
* Get DevCycle project Config
*
* @param sdkToken (required)
* @param etag (nullable)
* @return Call&lt;ProjectConfig&gt;
*/
@Headers({"Content-Type:application/json"})
@GET("config/v1/server/{sdkToken}.json")
Call<ProjectConfig> getConfig(@Path("sdkToken") String sdkToken, @Header("If-None-Match") String etag);

/**
* Post events to DevCycle for user
*
* @param eventsBatch (required)
* @return Call&lt;DevCycleResponse&gt;
*/
@Headers({"Content-Type:application/json"})
@POST("v1/events/batch")
Call<DevCycleResponse> publishEvents(@Body EventsBatch eventsBatch);
/**
* Post events to DevCycle for user
*
* @param eventsBatch (required)
* @return Call&lt;DevCycleResponse&gt;
*/
@Headers({"Content-Type:application/json"})
@POST("v1/events/batch")
Call<DevCycleResponse> publishEvents(@Body EventsBatch eventsBatch);
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ public interface IRestOptions {
/**
* @return A set of HTTP request headers that should be incorporated into all outgoing requests. return null if no headers are needed.
*/
Map<String,String> getHeaders();
Map<String, String> getHeaders();

/**
* @return A custom SSLSocketFactory to use when making requests. Return null if the default SSLSocket factory can be used
*/
SSLSocketFactory getSocketFactory();

/**
*
* @return Provide a trust manager to handle custom certificates. Return null if the default trust manager can be used
*/
X509TrustManager getTrustManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Response intercept(Chain chain) throws IOException {

// Is there already an authorization header on the request?
// If so, we need to rename ours to avoid conflicts
if(request.header(AUTHORIZATION_HEADER) != null) {
if (request.header(AUTHORIZATION_HEADER) != null) {
headerName = "DevCycle-" + AUTHORIZATION_HEADER;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* implementation
*/
public final class CustomHeaderInterceptor implements Interceptor {
private IRestOptions restOptions;
private final IRestOptions restOptions;

public CustomHeaderInterceptor(IRestOptions restOptions) {
this.restOptions = restOptions;
Expand All @@ -23,11 +23,11 @@ public CustomHeaderInterceptor(IRestOptions restOptions) {
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();

if(restOptions != null) {
if (restOptions != null) {
Request.Builder builder = request.newBuilder();

for (Map.Entry<String, String> entry : restOptions.getHeaders().entrySet()) {
if(entry.getValue() != null) {
if (entry.getValue() != null) {
builder.addHeader(entry.getKey(), entry.getValue());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
package com.devcycle.sdk.server.common.logging;

/**
* DevCycleLogger is a simple central entrypoint for the SDK to log messages without pinning the SDK to a
* specific logging framework. By default it logs to stdout but can e overriden by calling setCustomLogger()
*/
public class DevCycleLogger {
private static IDevCycleLogger logger = new SimpleDevCycleLogger(SimpleDevCycleLogger.Level.INFO);

public static void setCustomLogger(IDevCycleLogger logger) {
DevCycleLogger.logger = logger;
}

public static void debug(String message) {
if(logger != null){
if (logger != null) {
logger.debug(message);
}
}

public static void info(String message) {
if(logger != null) {
if (logger != null) {
logger.info(message);
}
}

public static void warning(String message) {
if(logger != null) {
if (logger != null) {
logger.warning(message);
}
}

public static void error(String message) {
if(logger != null) {
logger.error(message);
}
if (logger != null) {
logger.error(message);
}
}

public static void error(String message, Throwable t) {
if(logger != null) {
logger.error(message, t);
}
if (logger != null) {
logger.error(message, t);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
*/
public interface IDevCycleLogger {
void debug(String message);

void info(String message);

void warning(String message);

void error(String message);

void error(String message, Throwable t);
}
Loading
Loading