Skip to content

Commit

Permalink
Merge pull request #26 from dynamicweb/dbe/Fix-mappings
Browse files Browse the repository at this point in the history
Fix mappings
  • Loading branch information
DWDBE authored Jan 22, 2024
2 parents f41f5be + e21f89f commit 7525117
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.0.16</Version>
<Version>10.0.17</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Ecom Provider</Title>
<Description>Ecom Provider</Description>
Expand Down
24 changes: 24 additions & 0 deletions src/EcomDestinationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3108,6 +3108,8 @@ private void AddMappingsToJobThatNeedsToBeThereForMoveToMainTables()
new string[] { "ProductID", "ProductVariantID", "ProductLanguageID" });
EnsureMapping(ecomProductsMapping, DestinationColumnMappings["EcomProducts"], tableColumnsDictionary["EcomProducts"],
new string[] { "ProductVariantProdCounter", "ProductVariantGroupCounter", "ProductVariantCounter" });

HandleIsKeyColumns(ecomProductsMapping, new string[] { "ProductVariantID", "ProductLanguageID" });
}
}

Expand Down Expand Up @@ -3207,6 +3209,28 @@ private static void EnsureMapping(Mapping mapping, Dictionary<string, Column> de
}
}

private void HandleIsKeyColumns(Mapping mapping, string[] destinationKeyColumnNames)
{
var columnMappings = mapping.GetColumnMappings();
IEnumerable<ColumnMapping> keyColumnMappings = columnMappings.GetKeyColumnMappings();
if (keyColumnMappings.Any())
{
foreach (var destinationKeyColumnName in destinationKeyColumnNames)
{
// If any Key columns are in the mappings we need to add ProductLanguageID as Key Column mapping as well
if (!keyColumnMappings.Any((ColumnMapping cm) => string.Equals(cm.DestinationColumn?.Name, destinationKeyColumnName, StringComparison.OrdinalIgnoreCase)))
{
var cm = columnMappings.Where(cm => cm != null && cm.Active &&
cm.DestinationColumn != null && string.Equals(cm.DestinationColumn?.Name, destinationKeyColumnName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
if (cm is not null)
{
cm.IsKey = true;
}
}
}
}
}

private void RemoveColumnMappingsFromJobThatShouldBeSkippedInMoveToMainTables()
{
List<Mapping> mappings = null;
Expand Down
28 changes: 2 additions & 26 deletions src/EcomProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -942,19 +942,7 @@ public override bool RunJob(Job job)
var columnMappings = mapping.GetColumnMappings();

if (mapping.Active && columnMappings.Count > 0)
{
if (!string.IsNullOrEmpty(defaultLanguage))
{
string destinationColumnNameForLanguageId = MappingExtensions.GetLanguageIdColumnName(mapping.DestinationTable.Name);
if (!string.IsNullOrEmpty(destinationColumnNameForLanguageId) && !columnMappings.Any(obj => obj.Active && obj.DestinationColumn.Name.Equals(destinationColumnNameForLanguageId, StringComparison.OrdinalIgnoreCase)))
{
Column randomColumn = mapping.SourceTable.Columns.First();
var languageColumnMapping = mapping.AddMapping(randomColumn, mapping.DestinationTable.Columns.Find(c => string.Compare(c.Name, MappingExtensions.GetLanguageIdColumnName(mapping.DestinationTable.Name), true) == 0), true);
languageColumnMapping.ScriptType = ScriptType.Constant;
languageColumnMapping.ScriptValue = defaultLanguage;
}
}

{
if (!string.IsNullOrEmpty(Shop))
{
string destinationColumnNameForShopId = MappingExtensions.GetShopIdColumnName(mapping.DestinationTable.Name);
Expand All @@ -965,19 +953,7 @@ public override bool RunJob(Job job)
shopColumnMapping.ScriptType = ScriptType.Constant;
shopColumnMapping.ScriptValue = Shop;
}
}

var ecomProductTableMapping = job.Mappings.Where(obj => obj != null && obj.Active && obj.DestinationTable != null && obj.DestinationTable.Name.Equals("EcomProducts", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
if (ecomProductTableMapping != null)
{
if (ecomProductTableMapping.DestinationTable != null && !ecomProductTableMapping.GetColumnMappings().Any(obj => obj.DestinationColumn != null && obj.DestinationColumn.Name.Equals("ProductVariantId", StringComparison.OrdinalIgnoreCase)))
{
Column randomColumn = mapping.SourceTable.Columns.First();
var shopColumnMapping = mapping.AddMapping(randomColumn, ecomProductTableMapping.DestinationTable.Columns.Find(c => string.Compare(c.Name, "ProductVariantId", true) == 0), true);
shopColumnMapping.ScriptType = ScriptType.Constant;
shopColumnMapping.ScriptValue = string.Empty;
}
}
}

if (IsFirstJobRun)
{
Expand Down

0 comments on commit 7525117

Please sign in to comment.