Skip to content

Commit

Permalink
Merge pull request #28 from dynamicweb/mss/20221-AutoID
Browse files Browse the repository at this point in the history
added function to check and replace if the auto-id column exists in t…
  • Loading branch information
frederik5480 authored Aug 29, 2024
2 parents ec8db5f + fe62d28 commit 86917de
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.6.1</Version>
<Version>10.7.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Order Provider</Title>
<Description>Order Provider</Description>
Expand All @@ -23,8 +23,8 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.6.3" />
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.6.3" />
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.7.0" />
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.7.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
</Project>
20 changes: 19 additions & 1 deletion src/OrderProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,24 @@ internal static List<Mapping> GetMappingsByName(MappingCollection collection, st
}
}

private static IEnumerable<ColumnMapping> ReplaceKeyColumnsWithAutoIdIfExists(Mapping mapping)
{
//will move this to MappingExtensions - US https://dev.azure.com/dynamicwebsoftware/Dynamicweb/_workitems/edit/20900
if (mapping == null) return [];

var autoIdDestinationColumnName = MappingExtensions.GetAutoIdColumnName(mapping.DestinationTable?.Name ?? "");
if (string.IsNullOrEmpty(autoIdDestinationColumnName)) return mapping.GetColumnMappings();

var columnMappings = mapping.GetColumnMappings().ToList();
var autoIdColumnMapping = columnMappings.Where(obj => obj.DestinationColumn.Name.Equals(autoIdDestinationColumnName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
if (autoIdColumnMapping != null)
{
columnMappings.ForEach(obj => obj.IsKey = false);
autoIdColumnMapping.IsKey = true;
}
return columnMappings;
}

public override bool RunJob(Job job)
{
OrderTablesInJob(job, false);
Expand All @@ -357,8 +375,8 @@ public override bool RunJob(Job job)
Logger.Log("Starting import to temporary table for " + mapping.DestinationTable.Name + ".");
using (var reader = job.Source.GetReader(mapping))
{
var columnMappings = new ColumnMappingCollection(ReplaceKeyColumnsWithAutoIdIfExists(mapping));
var writer = new OrderDestinationWriter(mapping, Connection, Logger, SkipFailingRows, DiscardDuplicates);
var columnMappings = mapping.GetColumnMappings();
while (!reader.IsDone())
{
sourceRow = reader.GetNext();
Expand Down

0 comments on commit 86917de

Please sign in to comment.