From 660dd3d7738e0cd5d093209647ac7625e5b95d0b Mon Sep 17 00:00:00 2001 From: saquib-adobe Date: Thu, 28 Nov 2024 12:56:50 +0530 Subject: [PATCH 1/5] Marking the updateProposition API without callback deprecated --- .../java/com/adobe/marketing/mobile/optimize/Optimize.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java index a0c58bc..8dc4f1d 100644 --- a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java +++ b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java @@ -58,12 +58,13 @@ private Optimize() {} * @param data {@code Map} containing additional free-form data to be sent in * the personalization query request. */ + @Deprecated public static void updatePropositions( @NonNull final List decisionScopes, @Nullable final Map xdm, @Nullable final Map data) { - final long defaultTimeout = OptimizeConstants.EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT; - updatePropositions(decisionScopes, xdm, data, defaultTimeout, null); + + updatePropositions(decisionScopes, xdm, data, null); } /** From 2fb16232be4a529002e4e52da5e28378d820a3b4 Mon Sep 17 00:00:00 2001 From: saquib-adobe Date: Thu, 28 Nov 2024 14:57:54 +0530 Subject: [PATCH 2/5] Changing the timeout scale of update proposition from milliseconds to seconds --- .../marketing/mobile/optimize/Optimize.java | 16 +++++++++------- .../mobile/optimize/OptimizeConstants.java | 2 +- .../adobe/marketing/optimizeapp/OffersScreen.kt | 2 +- .../optimizeapp/viewmodels/MainViewModel.kt | 8 ++++---- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java index 8dc4f1d..40f2204 100644 --- a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java +++ b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java @@ -89,8 +89,8 @@ public static void updatePropositions( @Nullable final Map xdm, @Nullable final Map data, @Nullable final AdobeCallback> callback) { - final long defaultTimeout = OptimizeConstants.EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT; - updatePropositionsInternal(decisionScopes, xdm, data, defaultTimeout, callback); + final double defaultTimeoutSeconds = OptimizeConstants.EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT; + updatePropositionsInternal(decisionScopes, xdm, data, defaultTimeoutSeconds, callback); } /** @@ -107,8 +107,8 @@ public static void updatePropositions( * the personalization query request. * @param data {@code Map} containing additional free-form data to be sent in * the personalization query request. - * @param timeoutMillis {@code Long} containing additional configurable timeout to be sent in - * the personalization query request. + * @param timeoutSeconds {@code Double} containing additional configurable timeout(seconds) to + * be sent in the personalization query request. * @param callback {@code AdobeCallback>} which will be * invoked when decision propositions are received from the Edge network. */ @@ -116,16 +116,16 @@ public static void updatePropositions( @NonNull final List decisionScopes, @Nullable final Map xdm, @Nullable final Map data, - final long timeoutMillis, + final double timeoutSeconds, @Nullable final AdobeCallback> callback) { - updatePropositionsInternal(decisionScopes, xdm, data, timeoutMillis, callback); + updatePropositionsInternal(decisionScopes, xdm, data, timeoutSeconds, callback); } private static void updatePropositionsInternal( @NonNull final List decisionScopes, @Nullable final Map xdm, @Nullable final Map data, - final long timeoutMillis, + final double timeoutSeconds, @Nullable final AdobeCallback> callback) { if (OptimizeUtils.isNullOrEmpty(decisionScopes)) { @@ -176,6 +176,8 @@ private static void updatePropositionsInternal( if (!OptimizeUtils.isNullOrEmpty(data)) { eventData.put(OptimizeConstants.EventDataKeys.DATA, data); } + + long timeoutMillis = (long) (timeoutSeconds * 1000); eventData.put(OptimizeConstants.EventDataKeys.TIMEOUT, timeoutMillis); final Event event = diff --git a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeConstants.java b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeConstants.java index b410331..6d7aaee 100644 --- a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeConstants.java +++ b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeConstants.java @@ -18,7 +18,7 @@ class OptimizeConstants { static final String FRIENDLY_NAME = "Optimize"; static final long DEFAULT_RESPONSE_CALLBACK_TIMEOUT = 500L; static final long GET_RESPONSE_CALLBACK_TIMEOUT = 10000L; - static final long EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT = 10000L; + static final double EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT = 10; static final String ACTIVITY_ID = "activityId"; static final String XDM_ACTIVITY_ID = "xdm:activityId"; diff --git a/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/OffersScreen.kt b/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/OffersScreen.kt index 173bf29..2fb686a 100644 --- a/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/OffersScreen.kt +++ b/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/OffersScreen.kt @@ -182,7 +182,7 @@ fun OffersView(viewModel: MainViewModel) { decisionScopes = decisionScopeList, xdm = mapOf(Pair("xdmKey", "1234")), data = data, - timeout = 200 + timeoutSeconds = 0.2 ) }) { Text( diff --git a/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/viewmodels/MainViewModel.kt b/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/viewmodels/MainViewModel.kt index 3768678..cb90705 100644 --- a/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/viewmodels/MainViewModel.kt +++ b/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/viewmodels/MainViewModel.kt @@ -97,13 +97,13 @@ class MainViewModel: ViewModel() { * @param decisionScopes a [List] of [DecisionScope] * @param xdm a [Map] of xdm params * @param data a [Map] of data - * @param timeout a [Long] in milliseconds + * @param timeoutSeconds a [Double] in seconds */ fun updatePropositions( decisionScopes: List, xdm: Map, data: Map, - timeout: Long? = null + timeoutSeconds: Double? = null ) { val callback = object : AdobeCallbackWithOptimizeError> { override fun call(propositions: Map?) { @@ -119,12 +119,12 @@ class MainViewModel: ViewModel() { } optimizePropositionStateMap.clear() - timeout?.let { milliseconds -> + timeoutSeconds?.let { seconds -> Optimize.updatePropositions( decisionScopes, xdm, data, - milliseconds, + seconds, callback ) } ?: Optimize.updatePropositions(decisionScopes, xdm, data, callback) From eb6b34de0c9a5d3155b62fe6798c6307410430e2 Mon Sep 17 00:00:00 2001 From: saquib-adobe Date: Thu, 28 Nov 2024 15:26:00 +0530 Subject: [PATCH 3/5] Changing the timeout scale of get proposition from milliseconds to seconds --- .../marketing/mobile/optimize/Optimize.java | 18 +++++++++--------- .../mobile/optimize/OptimizeConstants.java | 3 +-- .../marketing/optimizeapp/OffersScreen.kt | 2 +- .../optimizeapp/viewmodels/MainViewModel.kt | 8 ++++---- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java index 40f2204..f9e28db 100644 --- a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java +++ b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java @@ -49,7 +49,7 @@ private Optimize() {} * Experience Edge network. * *

The returned decision propositions are cached in-memory in the Optimize SDK extension and - * can be retrieved using {@link #getPropositions(List, long, AdobeCallback)} API. + * can be retrieved using {@link #getPropositions(List, AdobeCallback)} API. * * @param decisionScopes {@code List} containing scopes for which offers need to * be updated. @@ -99,7 +99,7 @@ public static void updatePropositions( * Experience Edge network. * *

The returned decision propositions are cached in-memory in the Optimize SDK extension and - * can be retrieved using {@link #getPropositions(List, long, AdobeCallback)} API. + * can be retrieved using {@link #getPropositions(List, double, AdobeCallback)} API. * * @param decisionScopes {@code List} containing scopes for which offers need to * be updated. @@ -278,8 +278,8 @@ public void call(final Event event) { public static void getPropositions( @NonNull final List decisionScopes, @NonNull final AdobeCallback> callback) { - long defaultTimeout = OptimizeConstants.GET_RESPONSE_CALLBACK_TIMEOUT; - getPropositionsInternal(decisionScopes, defaultTimeout, callback); + final double defaultTimeoutSeconds = OptimizeConstants.GET_RESPONSE_CALLBACK_TIMEOUT; + getPropositionsInternal(decisionScopes, defaultTimeoutSeconds, callback); } /** @@ -293,14 +293,14 @@ public static void getPropositions( */ public static void getPropositions( @NonNull final List decisionScopes, - final long timeoutMillis, + final double timeoutSeconds, @NonNull final AdobeCallback> callback) { - getPropositionsInternal(decisionScopes, timeoutMillis, callback); + getPropositionsInternal(decisionScopes, timeoutSeconds, callback); } private static void getPropositionsInternal( @NonNull final List decisionScopes, - final long timeoutMillis, + final double timeoutSeconds, @NonNull final AdobeCallback> callback) { if (OptimizeUtils.isNullOrEmpty(decisionScopes)) { Log.warning( @@ -348,8 +348,8 @@ private static void getPropositionsInternal( .setEventData(eventData) .build(); - // Increased default response callback timeout to 10s to ensure prior update propositions - // requests have enough time to complete. + long timeoutMillis = (long) (timeoutSeconds * 1000); + MobileCore.dispatchEventWithResponseCallback( event, timeoutMillis, diff --git a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeConstants.java b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeConstants.java index 6d7aaee..c9933f6 100644 --- a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeConstants.java +++ b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeConstants.java @@ -16,8 +16,7 @@ class OptimizeConstants { static final String EXTENSION_VERSION = "3.2.0"; static final String EXTENSION_NAME = "com.adobe.optimize"; static final String FRIENDLY_NAME = "Optimize"; - static final long DEFAULT_RESPONSE_CALLBACK_TIMEOUT = 500L; - static final long GET_RESPONSE_CALLBACK_TIMEOUT = 10000L; + static final double GET_RESPONSE_CALLBACK_TIMEOUT = 10; static final double EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT = 10; static final String ACTIVITY_ID = "activityId"; diff --git a/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/OffersScreen.kt b/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/OffersScreen.kt index 2fb686a..19a9ddc 100644 --- a/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/OffersScreen.kt +++ b/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/OffersScreen.kt @@ -203,7 +203,7 @@ fun OffersView(viewModel: MainViewModel) { viewModel.getPropositions( decisionScopes = decisionScopeList, - timeout = 200 + timeoutSeconds = 0.2 ) }) { Text( diff --git a/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/viewmodels/MainViewModel.kt b/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/viewmodels/MainViewModel.kt index cb90705..2240944 100644 --- a/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/viewmodels/MainViewModel.kt +++ b/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/viewmodels/MainViewModel.kt @@ -71,9 +71,9 @@ class MainViewModel: ViewModel() { * Calls the Optimize SDK API to get the Propositions see [Optimize.getPropositions] * * @param [decisionScopes] a [List] of [DecisionScope] - * @param [timeout] a [Long] in milliseconds + * @param [timeoutSeconds] a [Double] in seconds */ - fun getPropositions(decisionScopes: List, timeout: Long? = null) { + fun getPropositions(decisionScopes: List, timeoutSeconds: Double? = null) { optimizePropositionStateMap.clear() val callback = object : AdobeCallbackWithError> { override fun call(propositions: Map?) { @@ -86,8 +86,8 @@ class MainViewModel: ViewModel() { print("Error in getting Propositions.") } } - timeout?.let { milliseconds -> - Optimize.getPropositions(decisionScopes, milliseconds, callback) + timeoutSeconds?.let { seconds -> + Optimize.getPropositions(decisionScopes, seconds, callback) } ?: Optimize.getPropositions(decisionScopes, callback) } From ab24d23458ef9074279d3ef7ce237a13103c521d Mon Sep 17 00:00:00 2001 From: saquib-adobe Date: Thu, 28 Nov 2024 15:30:02 +0530 Subject: [PATCH 4/5] Updating the unit tests for the get and update timeout case accordingly --- .../mobile/optimize/OptimizeTests.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/code/optimize/src/test/java/com/adobe/marketing/mobile/optimize/OptimizeTests.java b/code/optimize/src/test/java/com/adobe/marketing/mobile/optimize/OptimizeTests.java index 9254413..90fc347 100644 --- a/code/optimize/src/test/java/com/adobe/marketing/mobile/optimize/OptimizeTests.java +++ b/code/optimize/src/test/java/com/adobe/marketing/mobile/optimize/OptimizeTests.java @@ -10,10 +10,6 @@ */ package com.adobe.marketing.mobile.optimize; - -import static com.adobe.marketing.mobile.optimize.Optimize.failWithOptimizeError; -import static com.adobe.marketing.mobile.optimize.Optimize.getPropositions; -import static com.adobe.marketing.mobile.optimize.Optimize.updatePropositions; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -460,7 +456,7 @@ public void testGetPropositions_validDecisionScope() throws Exception { new DecisionScope( "eyJhY3Rpdml0eUlkIjoieGNvcmU6b2ZmZXItYWN0aXZpdHk6MTExMTExMTExMTExMTExMSIsInBsYWNlbWVudElkIjoieGNvcmU6b2ZmZXItcGxhY2VtZW50OjExMTExMTExMTExMTExMTEifQ==")); - getPropositions( + Optimize.getPropositions( scopes, new AdobeCallbackWithError>() { @Override @@ -567,7 +563,7 @@ public void testGetPropositions_multipleValidDecisionScopes() { "eyJhY3Rpdml0eUlkIjoieGNvcmU6b2ZmZXItYWN0aXZpdHk6MTExMTExMTExMTExMTExMSIsInBsYWNlbWVudElkIjoieGNvcmU6b2ZmZXItcGxhY2VtZW50OjExMTExMTExMTExMTExMTEifQ==")); scopes.add(new DecisionScope("myMbox")); - getPropositions( + Optimize.getPropositions( scopes, new AdobeCallbackWithError>() { @Override @@ -637,7 +633,7 @@ public void testGetPropositions_invalidDecisionScopeInList() { new DecisionScope( "eyJhY3Rpdml0eUlkIjoiIiwicGxhY2VtZW50SWQiOiJ4Y29yZTpvZmZlci1wbGFjZW1lbnQ6MTExMTExMTExMTExMTExMSJ9")); - getPropositions( + Optimize.getPropositions( scopes, new AdobeCallbackWithError>() { @Override @@ -666,7 +662,7 @@ public void call(Map propositionsMap) { public void testGetPropositions_emptyDecisionScopesList() { try (MockedStatic logMockedStatic = Mockito.mockStatic(Log.class)) { // test - getPropositions( + Optimize.getPropositions( new ArrayList(), new AdobeCallbackWithError>() { @Override @@ -695,7 +691,7 @@ public void call(Map propositionsMap) { public void testGetPropositions_nullDecisionScopesList() { try (MockedStatic logMockedStatic = Mockito.mockStatic(Log.class)) { // test - getPropositions( + Optimize.getPropositions( null, new AdobeCallbackWithError>() { @Override @@ -906,7 +902,7 @@ public void test_clearCachedPropositions() { @Test public void testUpdatePropositions_timeoutError() { - long timeoutMillis = 100; + double timeoutSeconds = 0.1; Map xdm = new HashMap<>(); Map data = new HashMap<>(); final List scopes = new ArrayList<>(); @@ -947,13 +943,13 @@ public void testUpdatePropositions_timeoutError() { .thenAnswer( (Answer) invocation -> { - failWithOptimizeError( + Optimize.failWithOptimizeError( callbackMockEvent, AEPOptimizeError.Companion.getTimeoutError()); return null; }); - updatePropositions(scopes, xdm, data, timeoutMillis, callbackMock); + Optimize.updatePropositions(scopes, xdm, data, timeoutSeconds, callbackMock); ArgumentCaptor errorCaptor = ArgumentCaptor.forClass(AEPOptimizeError.class); verify(callbackMockEvent, times(1)).fail(errorCaptor.capture()); @@ -965,7 +961,7 @@ public void testUpdatePropositions_timeoutError() { @Test public void testGetPropositions_timeoutError() { - long timeoutMillis = 100; + double timeoutSeconds = 0.1; final List scopes = new ArrayList<>(); scopes.add( new DecisionScope( @@ -1004,13 +1000,13 @@ public void testGetPropositions_timeoutError() { .thenAnswer( (Answer) invocation -> { - failWithOptimizeError( + Optimize.failWithOptimizeError( callbackMockEvent, AEPOptimizeError.Companion.getTimeoutError()); return null; }); - getPropositions(scopes, timeoutMillis, callbackMock); + Optimize.getPropositions(scopes, timeoutSeconds, callbackMock); ArgumentCaptor errorCaptor = ArgumentCaptor.forClass(AEPOptimizeError.class); verify(callbackMockEvent, times(1)).fail(errorCaptor.capture()); From 208ec6c1b8a003bb3ab701eb7e6248095d9b94a3 Mon Sep 17 00:00:00 2001 From: saquib-adobe Date: Thu, 28 Nov 2024 15:31:11 +0530 Subject: [PATCH 5/5] spotless and checkStyle check failure fixes --- .../com/adobe/marketing/mobile/optimize/Optimize.java | 8 +++++--- .../marketing/mobile/optimize/OptimizeConstants.java | 1 + .../adobe/marketing/mobile/optimize/OptimizeTests.java | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java index f9e28db..ae536b6 100644 --- a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java +++ b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java @@ -89,7 +89,8 @@ public static void updatePropositions( @Nullable final Map xdm, @Nullable final Map data, @Nullable final AdobeCallback> callback) { - final double defaultTimeoutSeconds = OptimizeConstants.EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT; + final double defaultTimeoutSeconds = + OptimizeConstants.EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT; updatePropositionsInternal(decisionScopes, xdm, data, defaultTimeoutSeconds, callback); } @@ -177,7 +178,8 @@ private static void updatePropositionsInternal( eventData.put(OptimizeConstants.EventDataKeys.DATA, data); } - long timeoutMillis = (long) (timeoutSeconds * 1000); + long timeoutMillis = (long) (timeoutSeconds * OptimizeConstants.TIMEOUT_CONVERSION_FACTOR); + eventData.put(OptimizeConstants.EventDataKeys.TIMEOUT, timeoutMillis); final Event event = @@ -348,7 +350,7 @@ private static void getPropositionsInternal( .setEventData(eventData) .build(); - long timeoutMillis = (long) (timeoutSeconds * 1000); + long timeoutMillis = (long) (timeoutSeconds * OptimizeConstants.TIMEOUT_CONVERSION_FACTOR); MobileCore.dispatchEventWithResponseCallback( event, diff --git a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeConstants.java b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeConstants.java index c9933f6..d58f4f3 100644 --- a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeConstants.java +++ b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeConstants.java @@ -18,6 +18,7 @@ class OptimizeConstants { static final String FRIENDLY_NAME = "Optimize"; static final double GET_RESPONSE_CALLBACK_TIMEOUT = 10; static final double EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT = 10; + static final long TIMEOUT_CONVERSION_FACTOR = 1000; static final String ACTIVITY_ID = "activityId"; static final String XDM_ACTIVITY_ID = "xdm:activityId"; diff --git a/code/optimize/src/test/java/com/adobe/marketing/mobile/optimize/OptimizeTests.java b/code/optimize/src/test/java/com/adobe/marketing/mobile/optimize/OptimizeTests.java index 90fc347..c26255c 100644 --- a/code/optimize/src/test/java/com/adobe/marketing/mobile/optimize/OptimizeTests.java +++ b/code/optimize/src/test/java/com/adobe/marketing/mobile/optimize/OptimizeTests.java @@ -10,6 +10,7 @@ */ package com.adobe.marketing.mobile.optimize; + import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify;