Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing nullpointer when columnmapping is a constant and adding id for… #45

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.6.6</Version>
<Version>10.8.0</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 All @@ -24,8 +24,8 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.6.2" />
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.6.2" />
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.8.0" />
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.8.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
Expand Down
20 changes: 19 additions & 1 deletion src/ODataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,23 @@ public ErpType ErpType
}
}

string ISource.GetId() => $"Source|ODataProvider|{EndpointId}";

string IDestination.GetId() => $"Destination|ODataProvider|{DestinationEndpointId}";

public override string GetDetails(string id)
{
var parts = id.Split('|');
if (parts.Length != 3)
return null;

var endpointId = parts[2];
if (!int.TryParse(endpointId, out int idInt))
return null;

var endpoint = _endpointService.GetEndpointById(idInt);
return $"Endpoint name: {endpoint.Name}";
}

/// <inheritdoc />
public override Schema GetSchema()
Expand Down Expand Up @@ -665,7 +682,8 @@ public override void SaveAsXml(XmlTextWriter textWriter)
textWriter.WriteElementString("Destinationendpoint", DestinationEndpointId);
textWriter.WriteElementString("Continueonerror", ContinueOnError.ToString());
textWriter.WriteElementString("Failjobonendpointisbusy", FailJobOnEndpointIsBusy.ToString());
GetSchema().SaveAsXml(textWriter);
if (!Feature.IsActive<SchemaManagementFeature>())
GetSchema().SaveAsXml(textWriter);
}

/// <inheritdoc />
Expand Down
10 changes: 5 additions & 5 deletions src/ODataWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void Write(Dictionary<string, object> Row)
var jsonObject = response[0];
Logger?.Info($"Received response from Endpoint = {jsonObject.ToJsonString()}");

var patchJson = MapValuesToJSon(Row, true);
var patchJson = MapValuesToJson(Row, true);
if (patchJson.Equals(new JsonObject().ToString()))
{
Logger?.Info($"Skipped PATCH as no active column mappings is added for always apply.");
Expand Down Expand Up @@ -138,12 +138,12 @@ public void Write(Dictionary<string, object> Row)
}
else
{
awaitResponseFromEndpoint = PostToEndpoint<JsonObject>(url, MapValuesToJSon(Row, false), null, false);
awaitResponseFromEndpoint = PostToEndpoint<JsonObject>(url, MapValuesToJson(Row, false), null, false);
}
}
else
{
awaitResponseFromEndpoint = PostToEndpoint<JsonObject>(url, MapValuesToJSon(Row, false), null, false);
awaitResponseFromEndpoint = PostToEndpoint<JsonObject>(url, MapValuesToJson(Row, false), null, false);
}
awaitResponseFromEndpoint.Wait();
if (!string.IsNullOrEmpty(awaitResponseFromEndpoint?.Result?.Error))
Expand Down Expand Up @@ -288,7 +288,7 @@ internal List<string> GetKeyColumnValuesForFilter(Dictionary<string, object> row
return keyColumnValues;
}

internal string MapValuesToJSon(Dictionary<string, object> row, bool isPatchRequest)
internal string MapValuesToJson(Dictionary<string, object> row, bool isPatchRequest)
{
var jsonObject = new JsonObject();

Expand All @@ -299,7 +299,7 @@ internal string MapValuesToJSon(Dictionary<string, object> row, bool isPatchRequ

if (columnMapping.HasScriptWithValue || row.ContainsKey(columnMapping.SourceColumn?.Name))
{
var columnValue = columnMapping.ConvertInputValueToOutputValue(row[columnMapping.SourceColumn?.Name] ?? null);
var columnValue = columnMapping.ConvertInputValueToOutputValue(columnMapping.HasScriptWithValue ? null : row.TryGetValue(columnMapping.SourceColumn?.Name ?? "", out var value) ? value : null);

switch (columnMapping.DestinationColumn.Type.Name.ToLower())
{
Expand Down
Loading