-
Notifications
You must be signed in to change notification settings - Fork 32
feat(ats): add support for android ODP events #502
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
Changes from all commits
6f7c846
ef5dfca
30c4404
4d553ac
73fa366
e7d4f27
b6d7e75
b3f9466
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| */ | ||
| package com.optimizely.ab.odp; | ||
|
|
||
| import com.optimizely.ab.annotations.VisibleForTesting; | ||
| import com.optimizely.ab.event.internal.BuildVersionInfo; | ||
| import com.optimizely.ab.event.internal.ClientEngineInfo; | ||
| import com.optimizely.ab.odp.serializer.ODPJsonSerializerFactory; | ||
|
|
@@ -38,6 +39,8 @@ public class ODPEventManager { | |
| private final int queueSize; | ||
| private final int batchSize; | ||
| private final int flushInterval; | ||
| @Nonnull private Map<String, Object> userCommonData = Collections.emptyMap(); | ||
| @Nonnull private Map<String, String> userCommonIdentifiers = Collections.emptyMap(); | ||
|
|
||
| private Boolean isRunning = false; | ||
|
|
||
|
|
@@ -63,6 +66,16 @@ public ODPEventManager(@Nonnull ODPApiManager apiManager, @Nullable Integer queu | |
| this.batchSize = (flushInterval != null && flushInterval == 0) ? 1 : DEFAULT_BATCH_SIZE; | ||
| } | ||
|
|
||
| // these user-provided common data are included in all ODP events in addition to the SDK-generated common data. | ||
| public void setUserCommonData(@Nullable Map<String, Object> commonData) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks confusing, at line 42 and 43 there is a NonNull tag and here it is nullable. I think it should be NonNull to keep it consistent. Same goes for line 75. |
||
| if (commonData != null) this.userCommonData = commonData; | ||
| } | ||
|
|
||
| // these user-provided common identifiers are included in all ODP events in addition to the SDK-generated identifiers. | ||
| public void setUserCommonIdentifiers(@Nullable Map<String, String> commonIdentifiers) { | ||
| if (commonIdentifiers != null) this.userCommonIdentifiers = commonIdentifiers; | ||
| } | ||
|
|
||
| public void start() { | ||
| if (eventDispatcherThread == null) { | ||
| eventDispatcherThread = new EventDispatcherThread(); | ||
|
|
@@ -107,19 +120,35 @@ public void sendEvent(ODPEvent event) { | |
| return; | ||
| } | ||
| event.setData(augmentCommonData(event.getData())); | ||
| event.setIdentifiers(augmentCommonIdentifiers(event.getIdentifiers())); | ||
| processEvent(event); | ||
| } | ||
|
|
||
| private Map<String, Object> augmentCommonData(Map<String, Object> sourceData) { | ||
| @VisibleForTesting | ||
| Map<String, Object> augmentCommonData(Map<String, Object> sourceData) { | ||
| // priority: sourceData > userCommonData > sdkCommonData | ||
|
|
||
| Map<String, Object> 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_version", BuildVersionInfo.getClientVersion()); | ||
|
|
||
| data.putAll(userCommonData); | ||
| data.putAll(sourceData); | ||
| return data; | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| Map<String, String> augmentCommonIdentifiers(Map<String, String> sourceIdentifiers) { | ||
| // priority: sourceIdentifiers > userCommonIdentifiers | ||
|
|
||
| Map<String, String> identifiers = new HashMap<>(); | ||
| identifiers.putAll(userCommonIdentifiers); | ||
| identifiers.putAll(sourceIdentifiers); | ||
| return identifiers; | ||
| } | ||
|
|
||
| private void processEvent(ODPEvent event) { | ||
| if (!isRunning) { | ||
| logger.warn("Failed to Process ODP Event. ODPEventManager is not running"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /**************************************************************************** | ||
| * Copyright 2020-2021, Optimizely, Inc. and contributors * | ||
| * Copyright 2020-2021, 2023, Optimizely, Inc. and contributors * | ||
| * * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); * | ||
| * you may not use this file except in compliance with the License. * | ||
|
|
@@ -63,6 +63,8 @@ public String getKey() { | |
|
|
||
| /** | ||
| * @deprecated use {@link #getExperimentRules()} and {@link #getDeliveryRules()} instead | ||
| * | ||
| * @return a map of ExperimentKey to OptimizelyExperiment | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update header. |
||
| */ | ||
| @Deprecated | ||
| public Map<String, OptimizelyExperiment> getExperimentsMap() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update the header as this is nit fix?