diff --git a/core-api/src/main/java/com/optimizely/ab/Optimizely.java b/core-api/src/main/java/com/optimizely/ab/Optimizely.java index acd9d05fd..3524cb24a 100644 --- a/core-api/src/main/java/com/optimizely/ab/Optimizely.java +++ b/core-api/src/main/java/com/optimizely/ab/Optimizely.java @@ -1633,10 +1633,20 @@ public Builder withUserProfileService(UserProfileService userProfileService) { /** * Override the SDK name and version (for client SDKs like android-sdk wrapping the core java-sdk) to be included in events. * - * @param clientEngine the client engine type. + * @param clientEngineName the client engine name ("java-sdk", "android-sdk", "flutter-sdk", etc.). * @param clientVersion the client SDK version. * @return An Optimizely builder */ + public Builder withClientInfo(String clientEngineName, String clientVersion) { + ClientEngineInfo.setClientEngineName(clientEngineName); + BuildVersionInfo.setClientVersion(clientVersion); + return this; + } + + /** + * @deprecated in favor of {@link withClientInfo(String, String)} which can set with arbitrary client names. + */ + @Deprecated public Builder withClientInfo(EventBatch.ClientEngine clientEngine, String clientVersion) { ClientEngineInfo.setClientEngine(clientEngine); BuildVersionInfo.setClientVersion(clientVersion); diff --git a/core-api/src/main/java/com/optimizely/ab/event/internal/BuildVersionInfo.java b/core-api/src/main/java/com/optimizely/ab/event/internal/BuildVersionInfo.java index d5620b4e9..f69be7cb5 100644 --- a/core-api/src/main/java/com/optimizely/ab/event/internal/BuildVersionInfo.java +++ b/core-api/src/main/java/com/optimizely/ab/event/internal/BuildVersionInfo.java @@ -37,9 +37,9 @@ public final class BuildVersionInfo { @Deprecated public final static String VERSION = readVersionNumber(); + public final static String DEFAULT_VERSION = readVersionNumber(); // can be overridden by other wrapper client (android-sdk, etc) - - private static String clientVersion = readVersionNumber(); + private static String clientVersion = DEFAULT_VERSION; public static void setClientVersion(String version) { if (version == null || version.isEmpty()) { diff --git a/core-api/src/main/java/com/optimizely/ab/event/internal/ClientEngineInfo.java b/core-api/src/main/java/com/optimizely/ab/event/internal/ClientEngineInfo.java index beb64be3d..85573d7fc 100644 --- a/core-api/src/main/java/com/optimizely/ab/event/internal/ClientEngineInfo.java +++ b/core-api/src/main/java/com/optimizely/ab/event/internal/ClientEngineInfo.java @@ -17,9 +17,13 @@ package com.optimizely.ab.event.internal; import com.optimizely.ab.event.internal.payload.EventBatch; +import com.optimizely.ab.notification.DecisionNotification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * ClientEngineInfo is a utility to globally get and set the ClientEngine used in * event tracking. The ClientEngine defaults to JAVA_SDK but can be overridden at @@ -28,9 +32,34 @@ public class ClientEngineInfo { private static final Logger logger = LoggerFactory.getLogger(ClientEngineInfo.class); + public static final String DEFAULT_NAME = "java-sdk"; + private static String clientEngineName = DEFAULT_NAME; + + public static void setClientEngineName(@Nullable String name) { + if (name == null || name.isEmpty()) { + logger.warn("ClientEngineName cannot be empty, defaulting to {}", ClientEngineInfo.clientEngineName); + return; + } + ClientEngineInfo.clientEngineName = name; + } + + @Nonnull + public static String getClientEngineName() { + return clientEngineName; + } + + private ClientEngineInfo() { + } + + @Deprecated public static final EventBatch.ClientEngine DEFAULT = EventBatch.ClientEngine.JAVA_SDK; + @Deprecated private static EventBatch.ClientEngine clientEngine = DEFAULT; + /** + * @deprecated in favor of {@link #setClientEngineName(String)} which can set with arbitrary client names. + */ + @Deprecated public static void setClientEngine(EventBatch.ClientEngine clientEngine) { if (clientEngine == null) { logger.warn("ClientEngine cannot be null, defaulting to {}", ClientEngineInfo.clientEngine.getClientEngineValue()); @@ -39,12 +68,15 @@ public static void setClientEngine(EventBatch.ClientEngine clientEngine) { logger.info("Setting Optimizely client engine to {}", clientEngine.getClientEngineValue()); ClientEngineInfo.clientEngine = clientEngine; + ClientEngineInfo.clientEngineName = clientEngine.getClientEngineValue(); } + /** + * @deprecated in favor of {@link #getClientEngineName()}. + */ + @Deprecated public static EventBatch.ClientEngine getClientEngine() { return clientEngine; } - private ClientEngineInfo() { - } } diff --git a/core-api/src/main/java/com/optimizely/ab/event/internal/EventFactory.java b/core-api/src/main/java/com/optimizely/ab/event/internal/EventFactory.java index f651be851..47839810d 100644 --- a/core-api/src/main/java/com/optimizely/ab/event/internal/EventFactory.java +++ b/core-api/src/main/java/com/optimizely/ab/event/internal/EventFactory.java @@ -72,7 +72,7 @@ public static LogEvent createLogEvent(List userEvents) { ProjectConfig projectConfig = userContext.getProjectConfig(); builder - .setClientName(ClientEngineInfo.getClientEngine().getClientEngineValue()) + .setClientName(ClientEngineInfo.getClientEngineName()) .setClientVersion(BuildVersionInfo.getClientVersion()) .setAccountId(projectConfig.getAccountId()) .setAnonymizeIp(projectConfig.getAnonymizeIP()) diff --git a/core-api/src/main/java/com/optimizely/ab/event/internal/payload/EventBatch.java b/core-api/src/main/java/com/optimizely/ab/event/internal/payload/EventBatch.java index c50ee6288..43965dafa 100644 --- a/core-api/src/main/java/com/optimizely/ab/event/internal/payload/EventBatch.java +++ b/core-api/src/main/java/com/optimizely/ab/event/internal/payload/EventBatch.java @@ -24,6 +24,8 @@ import java.util.List; public class EventBatch { + + @Deprecated public enum ClientEngine { JAVA_SDK("java-sdk"), ANDROID_SDK("android-sdk"), diff --git a/core-api/src/main/java/com/optimizely/ab/odp/ODPEventManager.java b/core-api/src/main/java/com/optimizely/ab/odp/ODPEventManager.java index ba668a138..efcdd6cda 100644 --- a/core-api/src/main/java/com/optimizely/ab/odp/ODPEventManager.java +++ b/core-api/src/main/java/com/optimizely/ab/odp/ODPEventManager.java @@ -148,7 +148,7 @@ protected Map augmentCommonData(Map sourceData) Map data = new HashMap<>(); data.put("idempotence_id", UUID.randomUUID().toString()); data.put("data_source_type", "sdk"); - data.put("data_source", ClientEngineInfo.getClientEngine().getClientEngineValue()); + data.put("data_source", ClientEngineInfo.getClientEngineName()); data.put("data_source_version", BuildVersionInfo.getClientVersion()); data.putAll(userCommonData); diff --git a/core-api/src/test/java/com/optimizely/ab/OptimizelyBuilderTest.java b/core-api/src/test/java/com/optimizely/ab/OptimizelyBuilderTest.java index 566eec635..6f091fdf8 100644 --- a/core-api/src/test/java/com/optimizely/ab/OptimizelyBuilderTest.java +++ b/core-api/src/test/java/com/optimizely/ab/OptimizelyBuilderTest.java @@ -224,7 +224,6 @@ public void withClientInfo() throws Exception { reset(eventHandler); optimizely = Optimizely.builder(validConfigJsonV4(), eventHandler) - .withClientInfo(null, null) .build(); optimizely.track("basic_event", "tester"); @@ -245,8 +244,8 @@ public void withClientInfo() throws Exception { assertEquals(argument.getValue().getEventBatch().getClientVersion(), "1.2.3"); // restore the default values for other tests - ClientEngineInfo.setClientEngine(ClientEngineInfo.DEFAULT); - BuildVersionInfo.setClientVersion(BuildVersionInfo.VERSION); + ClientEngineInfo.setClientEngineName(ClientEngineInfo.DEFAULT_NAME); + BuildVersionInfo.setClientVersion(BuildVersionInfo.DEFAULT_VERSION); } @Test diff --git a/core-api/src/test/java/com/optimizely/ab/event/internal/ClientEngineInfoTest.java b/core-api/src/test/java/com/optimizely/ab/event/internal/ClientEngineInfoTest.java index 33be48517..55b04296a 100644 --- a/core-api/src/test/java/com/optimizely/ab/event/internal/ClientEngineInfoTest.java +++ b/core-api/src/test/java/com/optimizely/ab/event/internal/ClientEngineInfoTest.java @@ -26,19 +26,21 @@ public class ClientEngineInfoTest { @After public void tearDown() throws Exception { - ClientEngineInfo.setClientEngine(ClientEngineInfo.DEFAULT); + ClientEngineInfo.setClientEngineName(ClientEngineInfo.DEFAULT_NAME); } @Test public void testSetAndGetClientEngine() { - for (EventBatch.ClientEngine expected: EventBatch.ClientEngine.values()) { - ClientEngineInfo.setClientEngine(expected); - assertEquals(expected, ClientEngineInfo.getClientEngine()); - } - } + // default "java-sdk" name + assertEquals("java-sdk", ClientEngineInfo.getClientEngineName()); - @Test - public void testDefaultValue() { - assertEquals(ClientEngineInfo.DEFAULT, ClientEngineInfo.getClientEngine()); + ClientEngineInfo.setClientEngineName(null); + assertEquals("java-sdk", ClientEngineInfo.getClientEngineName()); + + ClientEngineInfo.setClientEngineName(""); + assertEquals("java-sdk", ClientEngineInfo.getClientEngineName()); + + ClientEngineInfo.setClientEngineName("test-name"); + assertEquals("test-name", ClientEngineInfo.getClientEngineName()); } } diff --git a/core-api/src/test/java/com/optimizely/ab/event/internal/EventFactoryTest.java b/core-api/src/test/java/com/optimizely/ab/event/internal/EventFactoryTest.java index 657bc4fbf..e347074a8 100644 --- a/core-api/src/test/java/com/optimizely/ab/event/internal/EventFactoryTest.java +++ b/core-api/src/test/java/com/optimizely/ab/event/internal/EventFactoryTest.java @@ -87,7 +87,7 @@ public EventFactoryTest(int datafileVersion, @After public void tearDown() { - ClientEngineInfo.setClientEngine(EventBatch.ClientEngine.JAVA_SDK); + ClientEngineInfo.setClientEngineName(ClientEngineInfo.DEFAULT_NAME); } /** @@ -554,7 +554,7 @@ public void createImpressionEventIgnoresNullAttributes() { */ @Test public void createImpressionEventAndroidClientEngineClientVersion() throws Exception { - ClientEngineInfo.setClientEngine(EventBatch.ClientEngine.ANDROID_SDK); + ClientEngineInfo.setClientEngineName("android-sdk"); ProjectConfig projectConfig = validProjectConfigV2(); Experiment activatedExperiment = projectConfig.getExperiments().get(0); Variation bucketedVariation = activatedExperiment.getVariations().get(0); @@ -566,7 +566,7 @@ public void createImpressionEventAndroidClientEngineClientVersion() throws Excep userId, attributeMap); EventBatch impression = gson.fromJson(impressionEvent.getBody(), EventBatch.class); - assertThat(impression.getClientName(), is(EventBatch.ClientEngine.ANDROID_SDK.getClientEngineValue())); + assertThat(impression.getClientName(), is("android-sdk")); // assertThat(impression.getClientVersion(), is("0.0.0")); } @@ -577,7 +577,7 @@ public void createImpressionEventAndroidClientEngineClientVersion() throws Excep @Test public void createImpressionEventAndroidTVClientEngineClientVersion() throws Exception { String clientVersion = "0.0.0"; - ClientEngineInfo.setClientEngine(EventBatch.ClientEngine.ANDROID_TV_SDK); + ClientEngineInfo.setClientEngineName("android-tv-sdk"); ProjectConfig projectConfig = validProjectConfigV2(); Experiment activatedExperiment = projectConfig.getExperiments().get(0); Variation bucketedVariation = activatedExperiment.getVariations().get(0); @@ -589,7 +589,7 @@ public void createImpressionEventAndroidTVClientEngineClientVersion() throws Exc userId, attributeMap); EventBatch impression = gson.fromJson(impressionEvent.getBody(), EventBatch.class); - assertThat(impression.getClientName(), is(EventBatch.ClientEngine.ANDROID_TV_SDK.getClientEngineValue())); + assertThat(impression.getClientName(), is("android-tv-sdk")); // assertThat(impression.getClientVersion(), is(clientVersion)); } @@ -816,7 +816,7 @@ public void createConversionEventExperimentStatusPrecedesForcedVariation() { */ @Test public void createConversionEventAndroidClientEngineClientVersion() throws Exception { - ClientEngineInfo.setClientEngine(EventBatch.ClientEngine.ANDROID_SDK); + ClientEngineInfo.setClientEngineName("android-sdk"); Attribute attribute = validProjectConfig.getAttributes().get(0); EventType eventType = validProjectConfig.getEventTypes().get(0); @@ -838,7 +838,7 @@ public void createConversionEventAndroidClientEngineClientVersion() throws Excep EventBatch conversion = gson.fromJson(conversionEvent.getBody(), EventBatch.class); - assertThat(conversion.getClientName(), is(EventBatch.ClientEngine.ANDROID_SDK.getClientEngineValue())); + assertThat(conversion.getClientName(), is("android-sdk")); // assertThat(conversion.getClientVersion(), is("0.0.0")); } @@ -849,7 +849,7 @@ public void createConversionEventAndroidClientEngineClientVersion() throws Excep @Test public void createConversionEventAndroidTVClientEngineClientVersion() throws Exception { String clientVersion = "0.0.0"; - ClientEngineInfo.setClientEngine(EventBatch.ClientEngine.ANDROID_TV_SDK); + ClientEngineInfo.setClientEngineName("android-tv-sdk"); ProjectConfig projectConfig = validProjectConfigV2(); Attribute attribute = projectConfig.getAttributes().get(0); EventType eventType = projectConfig.getEventTypes().get(0); @@ -873,7 +873,7 @@ public void createConversionEventAndroidTVClientEngineClientVersion() throws Exc EventBatch conversion = gson.fromJson(conversionEvent.getBody(), EventBatch.class); - assertThat(conversion.getClientName(), is(EventBatch.ClientEngine.ANDROID_TV_SDK.getClientEngineValue())); + assertThat(conversion.getClientName(), is("android-tv-sdk")); // assertThat(conversion.getClientVersion(), is(clientVersion)); } diff --git a/gradle.properties b/gradle.properties index 71d3f3310..f8816af24 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,8 @@ org.gradle.parallel = true gsonVersion = 2.10.1 guavaVersion = 22.0 hamcrestVersion = 1.3 -jacksonVersion = 2.15.2 +# NOTE: jackson 2.14+ uses Java8 stream apis not supported in android +jacksonVersion = 2.13.5 jsonVersion = 20190722 jsonSimpleVersion = 1.1.1 logbackVersion = 1.2.3