Skip to content

Commit

Permalink
Merged PR 11243 insto this: Added new add-in on the destination so yo…
Browse files Browse the repository at this point in the history
…u can choose "Continue on error", plus added logic in the Writer. bump version to 10.0.16
  • Loading branch information
MatthiasSort committed Dec 21, 2023
1 parent 74a50c2 commit 6635365
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.0.15</Version>
<Version>10.0.16</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>OData Provider</Title>
<Description>The Odata Provider lets you fetch and map data from or to any OData endpoint.</Description>
Expand Down
16 changes: 15 additions & 1 deletion src/ODataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -499,6 +504,7 @@ public override void UpdateDestinationSettings(IDestination destination)
{
ODataProvider newProvider = (ODataProvider)destination;
DestinationEndpointId = newProvider.DestinationEndpointId;
ContinueOnError = newProvider.ContinueOnError;
}

/// <inheritdoc />
Expand Down Expand Up @@ -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;
}
}
}
Expand All @@ -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();
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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))
{
Expand Down
14 changes: 11 additions & 3 deletions src/ODataWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ internal class ODataWriter : IDisposable, IDestinationWriter
public readonly EndpointAuthenticationService EndpointAuthenticationService;
private Dictionary<string, Type> _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;
Expand All @@ -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<string, Type>();
_responseMappings = Mapping.GetResponseColumnMappings();
_continueOnError = continueOnError;
}

public void Write(Dictionary<string, object> Row)
Expand Down Expand Up @@ -68,7 +70,10 @@ public void Write(Dictionary<string, object> 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;
Expand Down Expand Up @@ -136,7 +141,10 @@ public void Write(Dictionary<string, object> 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;
Expand Down

0 comments on commit 6635365

Please sign in to comment.