Skip to content

Commit

Permalink
added processing for catalog group mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanstapel committed Jul 2, 2023
1 parent 52c2166 commit f40fe95
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 2 deletions.
4 changes: 2 additions & 2 deletions BMECat.net/BMECat.net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Authors>Stephan Stapel, [email protected]</Authors>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/stephanstapel/BMECat.net</PackageProjectUrl>
<Version>4.1.0</Version>
<Version>4.2.0</Version>
<Copyright>Stephan Stapel, s2 industries, 2023</Copyright>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/stephanstapel/BMECat.net</RepositoryUrl>
Expand All @@ -14,7 +14,7 @@
<Description>BMECat.net is a .net open source library that allows you to read and write BMEcat descriptions would be a software component that provides developers with a set of tools and functionalities to manipulate BMEcat files programmatically. This library would enable software applications to easily integrate BMEcat support, allowing for the efficient exchange of product information between different systems and partners. Developers could use this library to parse, create, and modify BMEcat documents, accessing product data in a standardized and structured way. Overall, this library would simplify the development of software applications that rely on BMEcat for product information exchange.</Description>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<FileVersion>4.1.0.0</FileVersion>
<FileVersion>4.2.0.0</FileVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<AssemblyName>s2industries.BMECat.net</AssemblyName>
<AssemblyOriginatorKeyFile>BMECat.net.snk</AssemblyOriginatorKeyFile>
Expand Down
35 changes: 35 additions & 0 deletions BMECat.net/BMECatReader12.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,41 @@ internal async static Task<ProductCatalog> LoadAsync(Stream inputStream, BMECatE
mutex.ReleaseMutex();
});

// -- map catalog group assignments to products
Dictionary<string, List<ProductCatalogGroupMapping>> _mappingsMap = new Dictionary<string, List<ProductCatalogGroupMapping>>();

XmlNodeList articleToCatalogGroupMapNodes = doc.DocumentElement.SelectNodes("/BMECAT/T_NEW_CATALOG/ARTICLE_TO_CATALOGGROUP_MAP", nsmgr);
Parallel.ForEach(articleToCatalogGroupMapNodes.Cast<XmlNode>(), /* new ParallelOptions() { MaxDegreeOfParallelism = 1 }, */
async (XmlNode articleToCatalogGroupMapNode) =>
{
string articleId = XmlUtils.nodeAsString(articleToCatalogGroupMapNode, "./ART_ID", nsmgr);

mutex.WaitOne();
if (!_mappingsMap.ContainsKey(articleId))
{
_mappingsMap.Add(articleId, new List<ProductCatalogGroupMapping>());
}

_mappingsMap[articleId].Add(new ProductCatalogGroupMapping()
{
/**
* @todo read optional SUPPLIER_IDREF sub structure
*/

CatalogGroupId = XmlUtils.nodeAsString(articleToCatalogGroupMapNode, "./CATALOG_GROUP_ID", nsmgr),
Order = XmlUtils.nodeAsInt(articleToCatalogGroupMapNode, "./ARTICLE_TO_CATALOGGROUP_MAP_ORDER", nsmgr)
});
mutex.ReleaseMutex();
});

foreach(Product p in retval.Products)
{
if (_mappingsMap.ContainsKey(p.No))
{
p.ProductCatalogGroupMappings = _mappingsMap[p.No];
}
}

return retval;
} // !LoadAsync()

Expand Down
45 changes: 45 additions & 0 deletions BMECat.net/BMECatReader2005.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,51 @@ internal async static Task<ProductCatalog> LoadAsync(Stream inputStream, BMECatE
mutex.ReleaseMutex();
});

// -- map catalog group assignments to products
Dictionary<string, List<ProductCatalogGroupMapping>> _mappingsMap = new Dictionary<string, List<ProductCatalogGroupMapping>>();

// according to the specifiction, ARTICLE_TO_CATALOGGROUP_MAP is still possible with BMECat 2005
XmlNodeList productToCatalogGroupMapNodes = doc.DocumentElement.SelectNodes("/bmecat:BMECAT/bmecat:T_NEW_CATALOG/bmecat:ARTICLE_TO_CATALOGGROUP_MAP", nsmgr);
string IdSelector = "./bmecat:ART_ID";
string mapOrderSelector = "./bmecat:ARTICLE_TO_CATALOGGROUP_MAP_ORDER";
if ((productToCatalogGroupMapNodes == null) || (productToCatalogGroupMapNodes.Count == 0))
{
productToCatalogGroupMapNodes = doc.DocumentElement.SelectNodes("/bmecat:BMECAT/bmecat:T_NEW_CATALOG/bmecat:PRODUCT_TO_CATALOGGROUP_MAP", nsmgr);
IdSelector = "./bmecat:PROD_ID";
mapOrderSelector = "./bmecat:PRODUCT_TO_CATALOGGROUP_MAP_ORDER";
}

Parallel.ForEach(productToCatalogGroupMapNodes.Cast<XmlNode>(), /* new ParallelOptions() { MaxDegreeOfParallelism = 1 }, */
async (XmlNode productToCatalogGroupMapNode) =>
{
string productId = XmlUtils.nodeAsString(productToCatalogGroupMapNode, IdSelector, nsmgr);

mutex.WaitOne();
if (!_mappingsMap.ContainsKey(productId))
{
_mappingsMap.Add(productId, new List<ProductCatalogGroupMapping>());
}

_mappingsMap[productId].Add(new ProductCatalogGroupMapping()
{
/**
* @todo read optional SUPPLIER_IDREF sub structure
*/

CatalogGroupId = XmlUtils.nodeAsString(productToCatalogGroupMapNode, "./bmecat:CATALOG_GROUP_ID", nsmgr),
Order = XmlUtils.nodeAsInt(productToCatalogGroupMapNode, mapOrderSelector, nsmgr)
});
mutex.ReleaseMutex();
});

foreach (Product p in retval.Products)
{
if (_mappingsMap.ContainsKey(p.No))
{
p.ProductCatalogGroupMappings = _mappingsMap[p.No];
}
}

Task.WaitAll();

return retval;
Expand Down
2 changes: 2 additions & 0 deletions BMECat.net/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public Product()
public List<Reference> References { get; set; } = new List<Reference>();
public EDXF EDXF { get; set; }
public List<Tuple<string, string>> ExtendedInformation { get; set; } = new List<Tuple<string, string>>();
public List<ProductCatalogGroupMapping> ProductCatalogGroupMappings { get; set; } = new List<ProductCatalogGroupMapping>();



public Feature GetFeature(string featureName, bool ignoreCase = true, Feature defaultValue = null)
Expand Down
12 changes: 12 additions & 0 deletions BMECat.net/ProductCatalogGroupMapping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace BMECat.net
{
public class ProductCatalogGroupMapping
{
public string CatalogGroupId { get; set; }
public int? Order { get; set; }
}
}

0 comments on commit f40fe95

Please sign in to comment.