diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/EmarsysTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/EmarsysTest.kt index 5a70e7b8..32cd213f 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/EmarsysTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/EmarsysTest.kt @@ -819,7 +819,7 @@ class EmarsysTest : AnnotationSpec() { runBlockingOnCoreSdkThread { verify(mockMobileEngageApi).clearContact(completionListener) - verify(mockPredictRestricted).clearContact() + verify(mockPredictRestricted).clearVisitorId() } } @@ -832,7 +832,7 @@ class EmarsysTest : AnnotationSpec() { verifyNoInteractions(mockPredictRestricted) } verify(mockLoggingMobileEngageApi).clearContact(completionListener) - verify(mockLoggingPredictRestricted).clearContact() + verify(mockLoggingPredictRestricted).clearVisitorId() } @Test diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/config/ConfigTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/config/ConfigTest.kt index 6ed8cca4..f9e0113d 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/config/ConfigTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/config/ConfigTest.kt @@ -97,7 +97,7 @@ class ConfigTest : AnnotationSpec() { fun testChangeMerchantId_delegatesTo_internal() { config.changeMerchantId("testMerchantId") - verify(mockConfigInternal).changeMerchantId("testMerchantId") + verify(mockConfigInternal).changeMerchantId("testMerchantId", null) } @Test diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/predict/PredictRestrictedTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/predict/PredictRestrictedTest.kt index 4e17e7dd..e69ee0bb 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/predict/PredictRestrictedTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/predict/PredictRestrictedTest.kt @@ -50,8 +50,8 @@ class PredictRestrictedTest : AnnotationSpec() { @Test fun testPredict_clearContact_delegatesTo_Predict_Internal() { - predictRestricted.clearContact() - Mockito.verify(mockPredictInternal).clearContact() + predictRestricted.clearVisitorId() + Mockito.verify(mockPredictInternal).clearVisitorId() } @Test diff --git a/emarsys-sdk/src/main/java/com/emarsys/Emarsys.kt b/emarsys-sdk/src/main/java/com/emarsys/Emarsys.kt index 28afd6e2..a2d67215 100644 --- a/emarsys-sdk/src/main/java/com/emarsys/Emarsys.kt +++ b/emarsys-sdk/src/main/java/com/emarsys/Emarsys.kt @@ -185,7 +185,7 @@ object Emarsys { .clearContact(completionListener) EmarsysDependencyInjection.predictRestrictedApi() .proxyApi(mobileEngage().concurrentHandlerHolder) - .clearContact() + .clearVisitorId() } private fun clearPredictOnlyContact(completionListener: CompletionListener?) { diff --git a/emarsys-sdk/src/main/java/com/emarsys/config/Config.kt b/emarsys-sdk/src/main/java/com/emarsys/config/Config.kt index 00cd12d3..852cb3f5 100644 --- a/emarsys-sdk/src/main/java/com/emarsys/config/Config.kt +++ b/emarsys-sdk/src/main/java/com/emarsys/config/Config.kt @@ -40,6 +40,6 @@ class Config : ConfigApi { } override fun changeMerchantId(merchantId: String?) { - emarsys().configInternal.changeMerchantId(merchantId) + emarsys().configInternal.changeMerchantId(merchantId, null) } } diff --git a/emarsys-sdk/src/main/java/com/emarsys/di/DefaultEmarsysComponent.kt b/emarsys-sdk/src/main/java/com/emarsys/di/DefaultEmarsysComponent.kt index 7d9488f5..cd42d92e 100644 --- a/emarsys-sdk/src/main/java/com/emarsys/di/DefaultEmarsysComponent.kt +++ b/emarsys-sdk/src/main/java/com/emarsys/di/DefaultEmarsysComponent.kt @@ -147,7 +147,6 @@ import com.emarsys.mobileengage.push.NotificationInformationListenerProvider import com.emarsys.mobileengage.push.PushInternal import com.emarsys.mobileengage.push.PushTokenProvider import com.emarsys.mobileengage.push.SilentNotificationInformationListenerProvider -import com.emarsys.request.CoreCompletionHandlerRefreshTokenProxyProvider import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory import com.emarsys.mobileengage.request.mapper.ContactTokenHeaderMapper import com.emarsys.mobileengage.request.mapper.DefaultRequestHeaderMapper @@ -180,6 +179,7 @@ import com.emarsys.predict.PredictRestrictedApi import com.emarsys.predict.endpoint.Endpoint.PREDICT_BASE_URL import com.emarsys.predict.provider.PredictRequestModelBuilderProvider import com.emarsys.predict.request.PredictHeaderFactory +import com.emarsys.predict.request.PredictMultiIdRequestModelFactory import com.emarsys.predict.request.PredictRequestContext import com.emarsys.predict.response.VisitorIdResponseHandler import com.emarsys.predict.response.XPResponseHandler @@ -187,7 +187,7 @@ import com.emarsys.predict.shard.PredictShardListMerger import com.emarsys.predict.storage.PredictStorageKey import com.emarsys.push.Push import com.emarsys.push.PushApi -import com.emarsys.predict.request.PredictMultiIdRequestModelFactory +import com.emarsys.request.CoreCompletionHandlerRefreshTokenProxyProvider import com.google.android.gms.common.ConnectionResult import com.google.android.gms.common.GoogleApiAvailabilityLight import com.google.android.gms.location.FusedLocationProviderClient @@ -935,7 +935,8 @@ open class DefaultEmarsysComponent(config: EmarsysConfig) : EmarsysComponent { logLevelStorage, crypto, clientServiceInternal, - concurrentHandlerHolder + concurrentHandlerHolder, + predictInternal ) } diff --git a/emarsys-sdk/src/main/java/com/emarsys/predict/PredictRestricted.kt b/emarsys-sdk/src/main/java/com/emarsys/predict/PredictRestricted.kt index cffea80a..86ea785d 100644 --- a/emarsys-sdk/src/main/java/com/emarsys/predict/PredictRestricted.kt +++ b/emarsys-sdk/src/main/java/com/emarsys/predict/PredictRestricted.kt @@ -16,8 +16,8 @@ class PredictRestricted(private val loggingInstance: Boolean = false) : PredictR .clearPredictOnlyContact(completionListener) } - override fun clearContact() { + override fun clearVisitorId() { (if (loggingInstance) predict().loggingPredictInternal else predict().predictInternal) - .clearContact() + .clearVisitorId() } } \ No newline at end of file diff --git a/emarsys-sdk/src/main/java/com/emarsys/predict/PredictRestrictedApi.kt b/emarsys-sdk/src/main/java/com/emarsys/predict/PredictRestrictedApi.kt index e5c74d4f..bb76f598 100644 --- a/emarsys-sdk/src/main/java/com/emarsys/predict/PredictRestrictedApi.kt +++ b/emarsys-sdk/src/main/java/com/emarsys/predict/PredictRestrictedApi.kt @@ -8,5 +8,5 @@ interface PredictRestrictedApi { fun clearPredictOnlyContact(completionListener: CompletionListener?) - fun clearContact() + fun clearVisitorId() } \ No newline at end of file diff --git a/emarsys/src/androidTest/java/com/emarsys/config/DefaultConfigInternalTest.kt b/emarsys/src/androidTest/java/com/emarsys/config/DefaultConfigInternalTest.kt index 10a1ea61..6135b4e8 100644 --- a/emarsys/src/androidTest/java/com/emarsys/config/DefaultConfigInternalTest.kt +++ b/emarsys/src/androidTest/java/com/emarsys/config/DefaultConfigInternalTest.kt @@ -181,7 +181,8 @@ class DefaultConfigInternalTest : AnnotationSpec() { mockLogLevelStorage, mockCrypto, mockClientServiceInternal, - concurrentHandlerHolder + concurrentHandlerHolder, + mockPredictInternal ) ) } @@ -275,7 +276,8 @@ class DefaultConfigInternalTest : AnnotationSpec() { mockLogLevelStorage, mockCrypto, mockClientServiceInternal, - concurrentHandlerHolder + concurrentHandlerHolder, + mockPredictInternal ) val latch = CountDownLatch(1) val completionListener = CompletionListener { @@ -327,7 +329,8 @@ class DefaultConfigInternalTest : AnnotationSpec() { mockLogLevelStorage, mockCrypto, mockClientServiceInternal, - concurrentHandlerHolder + concurrentHandlerHolder, + mockPredictInternal ) configInternal.changeApplicationCode(OTHER_APPLICATION_CODE) { @@ -379,7 +382,8 @@ class DefaultConfigInternalTest : AnnotationSpec() { mockLogLevelStorage, mockCrypto, mockClientServiceInternal, - concurrentHandlerHolder + concurrentHandlerHolder, + mockPredictInternal ) configInternal.changeApplicationCode(OTHER_APPLICATION_CODE) { @@ -577,16 +581,39 @@ class DefaultConfigInternalTest : AnnotationSpec() { @Test fun testChangeMerchantId_shouldEnableFeature() { - configInternal.changeMerchantId(MERCHANT_ID) + configInternal.changeMerchantId(MERCHANT_ID, null) FeatureRegistry.isFeatureEnabled(InnerFeature.PREDICT) shouldBe true } + @Test + fun testChangeMerchantId_whenMobileEngageDisabled_shouldClearContact() { + configInternal.changeMerchantId(MERCHANT_ID, null) + + FeatureRegistry.isFeatureEnabled(InnerFeature.PREDICT) shouldBe true + verify(mockPredictInternal).clearPredictOnlyContact(null) + verifyNoInteractions(mockMobileEngageInternal) + } + + @Test + fun testChangeMerchantId_whenMobileEngageEnabled_shouldClearContact() { + val latch = CountDownLatch(1) + + FeatureRegistry.enableFeature(InnerFeature.MOBILE_ENGAGE) + configInternal.changeMerchantId(MERCHANT_ID) { latch.countDown() } + + latch.await() + + FeatureRegistry.isFeatureEnabled(InnerFeature.PREDICT) shouldBe true + verify(mockMobileEngageInternal).clearContact(null) + verify(mockPredictInternal).clearVisitorId() + } + @Test fun testChangeMerchantId_shouldDisableFeature() { FeatureRegistry.enableFeature(InnerFeature.PREDICT) - configInternal.changeMerchantId(null) + configInternal.changeMerchantId(null, null) verify(mockPredictRequestContext).merchantId = null FeatureRegistry.isFeatureEnabled(InnerFeature.PREDICT) shouldBe false @@ -594,7 +621,7 @@ class DefaultConfigInternalTest : AnnotationSpec() { @Test fun testChangeMerchantId_shouldSaveMerchantId() { - configInternal.changeMerchantId(MERCHANT_ID) + configInternal.changeMerchantId(MERCHANT_ID, null) verify(mockPredictRequestContext).merchantId = MERCHANT_ID } @@ -700,7 +727,8 @@ class DefaultConfigInternalTest : AnnotationSpec() { mockLogLevelStorage, mockCrypto, mockClientServiceInternal, - concurrentHandlerHolder + concurrentHandlerHolder, + mockPredictInternal ) configInternal.fetchRemoteConfig(resultListener) @@ -735,7 +763,8 @@ class DefaultConfigInternalTest : AnnotationSpec() { mockLogLevelStorage, mockCrypto, mockClientServiceInternal, - concurrentHandlerHolder + concurrentHandlerHolder, + mockPredictInternal ) val resultListener = @@ -768,7 +797,8 @@ class DefaultConfigInternalTest : AnnotationSpec() { mockLogLevelStorage, mockCrypto, mockClientServiceInternal, - concurrentHandlerHolder + concurrentHandlerHolder, + mockPredictInternal ) val resultListener = @@ -809,7 +839,8 @@ class DefaultConfigInternalTest : AnnotationSpec() { mockLogLevelStorage, mockCrypto, mockClientServiceInternal, - concurrentHandlerHolder + concurrentHandlerHolder, + mockPredictInternal ) configInternal.fetchRemoteConfigSignature(resultListener) @@ -844,7 +875,8 @@ class DefaultConfigInternalTest : AnnotationSpec() { mockLogLevelStorage, mockCrypto, mockClientServiceInternal, - concurrentHandlerHolder + concurrentHandlerHolder, + mockPredictInternal ) val resultListener = FakeResultListener(latch, FakeResultListener.Mode.MAIN_THREAD) @@ -876,7 +908,8 @@ class DefaultConfigInternalTest : AnnotationSpec() { mockLogLevelStorage, mockCrypto, mockClientServiceInternal, - concurrentHandlerHolder + concurrentHandlerHolder, + mockPredictInternal ) val resultListener = FakeResultListener(latch, FakeResultListener.Mode.MAIN_THREAD) diff --git a/emarsys/src/main/java/com/emarsys/config/ConfigInternal.kt b/emarsys/src/main/java/com/emarsys/config/ConfigInternal.kt index 4f25aefb..3d90d3b9 100644 --- a/emarsys/src/main/java/com/emarsys/config/ConfigInternal.kt +++ b/emarsys/src/main/java/com/emarsys/config/ConfigInternal.kt @@ -23,7 +23,7 @@ interface ConfigInternal { fun changeApplicationCode(applicationCode: String?, completionListener: CompletionListener?) - fun changeMerchantId(merchantId: String?) + fun changeMerchantId(merchantId: String?, completionListener: CompletionListener?) fun refreshRemoteConfig(completionListener: CompletionListener?) diff --git a/emarsys/src/main/java/com/emarsys/config/DefaultConfigInternal.kt b/emarsys/src/main/java/com/emarsys/config/DefaultConfigInternal.kt index 6138fd2a..a2a4ed49 100644 --- a/emarsys/src/main/java/com/emarsys/config/DefaultConfigInternal.kt +++ b/emarsys/src/main/java/com/emarsys/config/DefaultConfigInternal.kt @@ -21,6 +21,7 @@ import com.emarsys.mobileengage.MobileEngageInternal import com.emarsys.mobileengage.MobileEngageRequestContext import com.emarsys.mobileengage.client.ClientServiceInternal import com.emarsys.mobileengage.push.PushInternal +import com.emarsys.predict.PredictInternal import com.emarsys.predict.request.PredictRequestContext import java.util.concurrent.CountDownLatch @@ -42,7 +43,8 @@ class DefaultConfigInternal( private val logLevelStorage: Storage, private val crypto: Crypto, private val clientServiceInternal: ClientServiceInternal, - private val concurrentHandlerHolder: ConcurrentHandlerHolder + private val concurrentHandlerHolder: ConcurrentHandlerHolder, + private val predictInternal: PredictInternal ) : ConfigInternal { override val applicationCode: String? @@ -154,13 +156,23 @@ class DefaultConfigInternal( } } - override fun changeMerchantId(merchantId: String?) { + override fun changeMerchantId(merchantId: String?, completionListener: CompletionListener?) { predictRequestContext.merchantId = merchantId + if (FeatureRegistry.isFeatureEnabled(InnerFeature.MOBILE_ENGAGE)) { + mobileEngageInternal.clearContact(null) + predictInternal.clearVisitorId() + } else { + predictInternal.clearPredictOnlyContact(null) + } if (merchantId == null) { FeatureRegistry.disableFeature(InnerFeature.PREDICT) } else { FeatureRegistry.enableFeature(InnerFeature.PREDICT) } + + concurrentHandlerHolder.postOnMain { + completionListener?.onCompleted(null) + } } override fun refreshRemoteConfig(completionListener: CompletionListener?) { diff --git a/predict/src/androidTest/java/com/emarsys/predict/DefaultPredictInternalTest.kt b/predict/src/androidTest/java/com/emarsys/predict/DefaultPredictInternalTest.kt index 40128a80..513acf8c 100644 --- a/predict/src/androidTest/java/com/emarsys/predict/DefaultPredictInternalTest.kt +++ b/predict/src/androidTest/java/com/emarsys/predict/DefaultPredictInternalTest.kt @@ -206,7 +206,7 @@ class DefaultPredictInternalTest : AnnotationSpec() { @Test fun testClearContact_shouldRemove_visitorIdFromKeyValueStore() { - predictInternal.clearContact() + predictInternal.clearVisitorId() verify(mockKeyValueStore).remove("predict_visitor_id") } diff --git a/predict/src/main/java/com/emarsys/predict/DefaultPredictInternal.kt b/predict/src/main/java/com/emarsys/predict/DefaultPredictInternal.kt index 7ba7fd4f..c003da0d 100644 --- a/predict/src/main/java/com/emarsys/predict/DefaultPredictInternal.kt +++ b/predict/src/main/java/com/emarsys/predict/DefaultPredictInternal.kt @@ -79,7 +79,7 @@ class DefaultPredictInternal( } } - override fun clearContact() { + override fun clearVisitorId() { keyValueStore.remove(VISITOR_ID_KEY) } diff --git a/predict/src/main/java/com/emarsys/predict/LoggingPredictInternal.kt b/predict/src/main/java/com/emarsys/predict/LoggingPredictInternal.kt index fdd11715..fb2f9186 100644 --- a/predict/src/main/java/com/emarsys/predict/LoggingPredictInternal.kt +++ b/predict/src/main/java/com/emarsys/predict/LoggingPredictInternal.kt @@ -34,7 +34,7 @@ class LoggingPredictInternal(private val klass: Class<*>) : PredictInternal { debug(MethodNotAllowed(klass, callerMethodName, parameters)) } - override fun clearContact() { + override fun clearVisitorId() { val callerMethodName = SystemUtils.getCallerMethodName() debug(MethodNotAllowed(klass, callerMethodName, null)) } diff --git a/predict/src/main/java/com/emarsys/predict/PredictInternal.kt b/predict/src/main/java/com/emarsys/predict/PredictInternal.kt index 4bb79cf4..a7f1c97b 100644 --- a/predict/src/main/java/com/emarsys/predict/PredictInternal.kt +++ b/predict/src/main/java/com/emarsys/predict/PredictInternal.kt @@ -11,7 +11,7 @@ import com.emarsys.predict.api.model.RecommendationFilter interface PredictInternal { fun setContact(contactFieldId: Int, contactFieldValue: String, completionListener: CompletionListener?) fun clearPredictOnlyContact(completionListener: CompletionListener?) - fun clearContact() + fun clearVisitorId() fun trackCart(items: List): String fun trackPurchase(orderId: String, items: List): String fun trackItemView(itemId: String): String