From 9d4ba59db6ed9731273d32cc45dfb2d5fb105fb7 Mon Sep 17 00:00:00 2001 From: Andrei Anischevici Date: Mon, 18 Sep 2023 23:58:15 +0300 Subject: [PATCH] TNT-48503 Expose edge response callback (#39) Geo context cleanup before ODD sendNotifications --- .../Service/OnDeviceDecisioningService.cs | 26 +++++++++++++++++++ .../Service/TargetService.cs | 5 +++- .../Adobe.Target.Client/TargetClientConfig.cs | 25 ++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/Source/Adobe.Target.Client/Service/OnDeviceDecisioningService.cs b/Source/Adobe.Target.Client/Service/OnDeviceDecisioningService.cs index fe91243..6d7c52a 100644 --- a/Source/Adobe.Target.Client/Service/OnDeviceDecisioningService.cs +++ b/Source/Adobe.Target.Client/Service/OnDeviceDecisioningService.cs @@ -144,6 +144,8 @@ public TargetDeliveryResponse ExecuteRequest(TargetDeliveryRequest deliveryReque var elapsedMilliseconds = (int)stopwatch.ElapsedMilliseconds; var telemetry = deliveryRequest.GetTelemetryEntry(this.clientConfig, elapsedMilliseconds); + CleanupGeoContext(deliveryRequest); + this.SendNotifications(deliveryRequest, targetResponse, notifications, telemetry); TargetClient.Logger?.LogDebug(targetResponse.ToString()); @@ -160,6 +162,30 @@ internal OnDeviceDecisioningEvaluation EvaluateLocalExecution(TargetDeliveryRequ return this.decisioningEvaluator.EvaluateLocalExecution(request); } + private static void CleanupGeoContext(TargetDeliveryRequest deliveryRequest) + { + var geo = deliveryRequest.DeliveryRequest.Context.Geo; + if (geo == null) + { + return; + } + + if (string.IsNullOrWhiteSpace(geo.City)) + { + geo.City = null; + } + + if (string.IsNullOrWhiteSpace(geo.StateCode)) + { + geo.StateCode = null; + } + + if (string.IsNullOrWhiteSpace(geo.CountryCode)) + { + geo.CountryCode = null; + } + } + private static string RemoveLocationHint(string tntId) { if (string.IsNullOrEmpty(tntId)) diff --git a/Source/Adobe.Target.Client/Service/TargetService.cs b/Source/Adobe.Target.Client/Service/TargetService.cs index fbc578c..1511acc 100644 --- a/Source/Adobe.Target.Client/Service/TargetService.cs +++ b/Source/Adobe.Target.Client/Service/TargetService.cs @@ -46,7 +46,10 @@ internal TargetService(TargetClientConfig clientConfig) this.clientConfig = clientConfig; this.logger = TargetClient.Logger; this.stickyBaseUrl = this.clientConfig.DefaultUrl; - this.deliveryApi = new DeliveryApi(this.GetDeliveryApiConfig(this.stickyBaseUrl)); + this.deliveryApi = new DeliveryApi(this.GetDeliveryApiConfig(this.stickyBaseUrl)) + { + ExceptionFactory = clientConfig.ExceptionFactory, + }; RetryConfiguration.RetryPolicy = clientConfig.RetryPolicy; RetryConfiguration.AsyncRetryPolicy = clientConfig.AsyncRetryPolicy; } diff --git a/Source/Adobe.Target.Client/TargetClientConfig.cs b/Source/Adobe.Target.Client/TargetClientConfig.cs index b952be8..6f39465 100644 --- a/Source/Adobe.Target.Client/TargetClientConfig.cs +++ b/Source/Adobe.Target.Client/TargetClientConfig.cs @@ -13,6 +13,7 @@ namespace Adobe.Target.Client using System; using System.Net; using System.Threading.Tasks; + using Adobe.Target.Delivery.Client; using Adobe.Target.Delivery.Model; using Microsoft.Extensions.Logging; using Polly; @@ -53,6 +54,7 @@ private TargetClientConfig(Builder builder) this.OnDeviceDecisioningReady = builder.OnDeviceDecisioningReady; this.ArtifactDownloadSucceeded = builder.ArtifactDownloadSucceeded; this.ArtifactDownloadFailed = builder.ArtifactDownloadFailed; + this.ExceptionFactory = builder.ExceptionFactory; this.OnDeviceEnvironment = builder.OnDeviceEnvironment; this.OnDeviceConfigHostname = builder.OnDeviceConfigHostname; this.OnDeviceDecisioningPollingIntSecs = builder.OnDeviceDecisioningPollingIntSecs; @@ -140,6 +142,11 @@ private TargetClientConfig(Builder builder) /// public Action ArtifactDownloadFailed { get; } + /// + /// Exception Factory delegate + /// + public ExceptionFactory ExceptionFactory { get; } + /// /// OnDevice Environment /// @@ -280,6 +287,11 @@ public Builder(string client, string organizationId) /// internal Action ArtifactDownloadFailed { get; private set; } + /// + /// Exception Factory delegate + /// + internal ExceptionFactory ExceptionFactory { get; private set; } + /// /// OnDevice Environment /// @@ -452,6 +464,19 @@ public Builder SetArtifactDownloadFailed(Action @delegate) return this; } + /// + /// Sets Exception Factory delegate
+ /// Note: this will receive all raw Delivery API responses, + /// Make sure to return null after handling any exceptions if you don't want these to be re-thrown + ///
+ /// delegate + /// instance + public Builder SetExceptionFactory(ExceptionFactory factory) + { + this.ExceptionFactory = factory; + return this; + } + /// /// Sets OnDevice Environment
/// Default: "production"