From 6635365ce5ec5c3274672b3f6c09d0841b496b6f Mon Sep 17 00:00:00 2001 From: MatthiasSort Date: Thu, 21 Dec 2023 09:03:43 +0100 Subject: [PATCH] Merged PR 11243 insto this: Added new add-in on the destination so you can choose "Continue on error", plus added logic in the Writer. bump version to 10.0.16 --- ...ataIntegration.Providers.ODataProvider.csproj | 2 +- src/ODataProvider.cs | 16 +++++++++++++++- src/ODataWriter.cs | 14 +++++++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj b/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj index 791c80c..9678638 100644 --- a/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj +++ b/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj @@ -1,6 +1,6 @@  - 10.0.15 + 10.0.16 1.0.0.0 OData Provider The Odata Provider lets you fetch and map data from or to any OData endpoint. diff --git a/src/ODataProvider.cs b/src/ODataProvider.cs index 1ed2f93..27ea9a7 100644 --- a/src/ODataProvider.cs +++ b/src/ODataProvider.cs @@ -115,6 +115,11 @@ public string DestinationEndpointId set => _endpoint = _endpointService.GetEndpointById(Convert.ToInt32(value)); } + [AddInParameter("Continue on error")] + [AddInParameterEditor(typeof(YesNoParameterEditor), "Tooltip=Use this when the job should continue when endpoint returns an error.")] + [AddInParameterGroup("Destination")] + public bool ContinueOnError { get; set; } + #endregion private string GetMetadataURL() @@ -499,6 +504,7 @@ public override void UpdateDestinationSettings(IDestination destination) { ODataProvider newProvider = (ODataProvider)destination; DestinationEndpointId = newProvider.DestinationEndpointId; + ContinueOnError = newProvider.ContinueOnError; } /// @@ -580,6 +586,12 @@ public ODataProvider(XmlNode xmlNode) : this() DestinationEndpointId = node.FirstChild.Value; } break; + case "Continueonerror": + if (node.HasChildNodes) + { + ContinueOnError = node.FirstChild.Value == "True"; + } + break; } } } @@ -598,6 +610,7 @@ public override string Serialize() root.Add(CreateParameterNode(GetType(), "Do not store last response in log file", DoNotStoreLastResponseInLogFile.ToString())); root.Add(CreateParameterNode(GetType(), "Predefined endpoint", EndpointId)); root.Add(CreateParameterNode(GetType(), "Destination endpoint", DestinationEndpointId)); + root.Add(CreateParameterNode(GetType(), "Continue on error", ContinueOnError.ToString())); return document.ToString(); } @@ -613,6 +626,7 @@ public override void SaveAsXml(XmlTextWriter textWriter) textWriter.WriteElementString("Donotstorelastresponseinlogfile", DoNotStoreLastResponseInLogFile.ToString()); textWriter.WriteElementString("Predefinedendpoint", EndpointId); textWriter.WriteElementString("Destinationendpoint", DestinationEndpointId); + textWriter.WriteElementString("Continueonerror", ContinueOnError.ToString()); GetSchema().SaveAsXml(textWriter); } @@ -660,7 +674,7 @@ public override bool RunJob(Job job) Logger?.Log($"Begin synchronizing '{mapping.SourceTable.Name}' to '{mapping.DestinationTable.Name}'."); - using (var writer = new ODataWriter(Logger, mapping, _endpoint, _credentials)) + using (var writer = new ODataWriter(Logger, mapping, _endpoint, _credentials, ContinueOnError)) { using (ISourceReader sourceReader = mapping.Source.GetReader(mapping)) { diff --git a/src/ODataWriter.cs b/src/ODataWriter.cs index 2aec95c..dfbe994 100644 --- a/src/ODataWriter.cs +++ b/src/ODataWriter.cs @@ -23,10 +23,11 @@ internal class ODataWriter : IDisposable, IDestinationWriter public readonly EndpointAuthenticationService EndpointAuthenticationService; private Dictionary _destinationPrimaryKeyColumns; private readonly ColumnMappingCollection _responseMappings; + private bool _continueOnError; public Mapping Mapping { get; } internal JsonObject PostBackObject { get; set; } - internal ODataWriter(ILogger logger, Mapping mapping, Endpoint endpoint, ICredentials credentials) + internal ODataWriter(ILogger logger, Mapping mapping, Endpoint endpoint, ICredentials credentials, bool continueOnError) { Logger = logger; Endpoint = endpoint; @@ -37,6 +38,7 @@ internal ODataWriter(ILogger logger, Mapping mapping, Endpoint endpoint, ICreden var originalDestinationMappingTable = originalDestinationTables.FirstOrDefault(obj => obj.Name == Mapping.DestinationTable.Name); _destinationPrimaryKeyColumns = originalDestinationMappingTable?.Columns.Where(obj => obj.IsPrimaryKey)?.ToDictionary(obj => obj.Name, obj => obj.Type) ?? new Dictionary(); _responseMappings = Mapping.GetResponseColumnMappings(); + _continueOnError = continueOnError; } public void Write(Dictionary Row) @@ -68,7 +70,10 @@ public void Write(Dictionary Row) if (!string.IsNullOrEmpty(responseFromEndpoint?.Result?.Error)) { Logger?.Error($"Error Url: {url}. Response Error: {responseFromEndpoint.Result.Error}. Status response code: {responseFromEndpoint.Result.Status}"); - throw new Exception(responseFromEndpoint.Result.Error); + if (!_continueOnError) + { + throw new Exception(responseFromEndpoint.Result.Error); + } } var response = responseFromEndpoint?.Result?.Content?.Value; @@ -136,7 +141,10 @@ public void Write(Dictionary Row) if (!string.IsNullOrEmpty(awaitResponseFromEndpoint?.Result?.Error)) { Logger?.Error($"Error Url: {url}. Response Error: {awaitResponseFromEndpoint.Result.Error}. Status response code: {awaitResponseFromEndpoint.Result.Status}"); - throw new Exception(awaitResponseFromEndpoint.Result.Error); + if (!_continueOnError) + { + throw new Exception(awaitResponseFromEndpoint.Result.Error); + } } PostBackObject = awaitResponseFromEndpoint?.Result?.Content;