Skip to content

Commit

Permalink
Merge pull request #52 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 117b91f + 2899179 commit 45aa058
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Dynamicweb.DataIntegration.Providers.EcomProvider.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.6.2</Version>
<Version>10.7.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Ecom Provider</Title>
<Description>Ecom Provider</Description>
Expand All @@ -24,8 +24,8 @@
<Nullable>enable</Nullable>
</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>
22 changes: 20 additions & 2 deletions src/EcomProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,24 @@ internal static IEnumerable<Mapping> GetMappingsByName(MappingCollection collect
}
}

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)
{
ReplaceMappingConditionalsWithValuesFromRequest(job);
Expand Down Expand Up @@ -945,9 +963,9 @@ public override bool RunJob(Job job)

foreach (Mapping mapping in job.Mappings)
{
var columnMappings = mapping.GetColumnMappings();
var columnMappings = ReplaceKeyColumnsWithAutoIdIfExists(mapping);

if (mapping.Active && columnMappings.Count > 0)
if (mapping.Active && columnMappings.Any())
{
if (!string.IsNullOrEmpty(Shop))
{
Expand Down

0 comments on commit 45aa058

Please sign in to comment.