First pass of new mandator selection
This commit is contained in:
@@ -14,6 +14,35 @@
|
||||
Public Const DB_TYPE_DECIMAL = "DECIMAL"
|
||||
Public Const DB_TYPE_BOOLEAN = "BOOLEAN"
|
||||
|
||||
Public Const ALL_MESOCOMP = "mesocomp"
|
||||
|
||||
Public Const V21_ARTICLENUMBER = "c002"
|
||||
Public Const V21_ARTICLEDESCRIPTION = "c003"
|
||||
Public Const V21_MAINARTICLENUMBER = "c011"
|
||||
Public Const V21_REPLACEMENTARTICLENUMBER = "c123"
|
||||
Public Const V21_EAN = "c075"
|
||||
|
||||
Public Const V50_ACCOUNTNUMBER = "c002"
|
||||
Public Const V50_ACCOUNTNAME = "c003"
|
||||
Public Const V50_STREETNAME = "c050"
|
||||
Public Const V50_ZIPCODE = "c051"
|
||||
Public Const V50_CITYNAME = "c052"
|
||||
Public Const V50_GLN = "c260"
|
||||
|
||||
Public Const T45_KEY = "c000"
|
||||
Public Const T45_NAME = "c001"
|
||||
Public Const T45_CONTACTNUMBER = "c063"
|
||||
|
||||
Public Const V05_ACCOUNTID = "c002"
|
||||
Public Const V05_ACCOUNTNAME = "c003"
|
||||
|
||||
Public Const T357_KINDID = "c030"
|
||||
Public Const T357_KINDNAME = "c001"
|
||||
|
||||
Public Const T01_DATABASEINFO = "c004"
|
||||
Public Const T01_MANDATORID = "c000"
|
||||
Public Const T01_MANDATORNAME = "c003"
|
||||
|
||||
Public Enum ColumnType As Integer
|
||||
[String]
|
||||
[Integer]
|
||||
|
||||
@@ -23,7 +23,7 @@ Namespace Documents
|
||||
|
||||
Public ReadOnly Property HasErrors As Boolean
|
||||
Get
|
||||
Return Rows.Any(Function(r As DocumentRow) r.HasErrors)
|
||||
Return Mandator Is Nothing Or Rows.Any(Function(r As DocumentRow) r.HasErrors)
|
||||
End Get
|
||||
End Property
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ Namespace Documents
|
||||
oInfo.FilesTotal = oFiles.Count
|
||||
|
||||
RaiseEvent FileLoadComplete(Me, oInfo)
|
||||
|
||||
Catch ex As MissingAttributeException
|
||||
Logger.Error(ex)
|
||||
Throw New DocumentLoaderException($"Missing Attribute '{ex.Message}' in File '{oFile.Name}'")
|
||||
@@ -270,12 +271,11 @@ Namespace Documents
|
||||
|
||||
If oMandator Is Nothing Then
|
||||
Logger.Warn("Mandator not found for File [{0}]", pDocument.File.Name)
|
||||
Throw New Exceptions.NoMandatorException($"Mandator not found for file [{pDocument.File.Name}]")
|
||||
Else
|
||||
pDocument = MatchDocumentData(pDocument, oMandator, pTemplate)
|
||||
End If
|
||||
|
||||
pDocument = MatchDocumentData(pDocument, oMandator, pTemplate)
|
||||
pDocument.Mandator = oMandator
|
||||
|
||||
Return pDocument
|
||||
End Function
|
||||
|
||||
|
||||
2
MultiTool.Shared/Helpers.vb
Normal file
2
MultiTool.Shared/Helpers.vb
Normal file
@@ -0,0 +1,2 @@
|
||||
Friend Class Helpers
|
||||
End Class
|
||||
@@ -104,6 +104,7 @@
|
||||
<Compile Include="Documents\DocumentType.vb" />
|
||||
<Compile Include="Documents\DocumentLoader.vb" />
|
||||
<Compile Include="Exceptions.vb" />
|
||||
<Compile Include="Helpers.vb" />
|
||||
<Compile Include="IDictionaryEx.vb" />
|
||||
<Compile Include="IEnumerableEx.vb" />
|
||||
<Compile Include="Mapper.vb" />
|
||||
@@ -123,7 +124,10 @@
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="Templates\MandatorConfig.vb" />
|
||||
<Compile Include="Templates\MandatorConfigItem.vb" />
|
||||
<Compile Include="Templates\MappingConfig.vb" />
|
||||
<Compile Include="Templates\MappingConfigItem.vb" />
|
||||
<Compile Include="Report\ReportHead.vb" />
|
||||
<Compile Include="Report\ReportPosition.vb" />
|
||||
<Compile Include="Report\ReportSource.vb" />
|
||||
@@ -138,7 +142,7 @@
|
||||
<Compile Include="Winline\Entities\Contact.vb" />
|
||||
<Compile Include="Winline\Entities\DocumentKind.vb" />
|
||||
<Compile Include="Winline\Entities\Mandator.vb" />
|
||||
<Compile Include="Templates\ColumnConfig.vb" />
|
||||
<Compile Include="Templates\TemplateConfigItem.vb" />
|
||||
<Compile Include="Winline\WebServiceData.vb" />
|
||||
<Compile Include="XmlData.vb" />
|
||||
</ItemGroup>
|
||||
|
||||
5
MultiTool.Shared/Templates/MandatorConfig.vb
Normal file
5
MultiTool.Shared/Templates/MandatorConfig.vb
Normal file
@@ -0,0 +1,5 @@
|
||||
Namespace Templates
|
||||
Public Class MandatorConfig
|
||||
Public Property Items As New List(Of MandatorConfigItem)
|
||||
End Class
|
||||
End Namespace
|
||||
7
MultiTool.Shared/Templates/MandatorConfigItem.vb
Normal file
7
MultiTool.Shared/Templates/MandatorConfigItem.vb
Normal file
@@ -0,0 +1,7 @@
|
||||
Namespace Templates
|
||||
Public Class MandatorConfigItem
|
||||
Public Property Name As String
|
||||
Public Property OrderKey As Integer
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@@ -1,12 +1,6 @@
|
||||
Namespace Templates
|
||||
Public Class MappingConfig
|
||||
Public Property OrderKey As Integer
|
||||
Public Property SourceName As String
|
||||
Public Property SourceItem As String
|
||||
Public Property SourceRegex As String
|
||||
Public Property DestinationName As String
|
||||
Public Property DestinationItem As String
|
||||
Public Property DestinationValue As String
|
||||
Public Property Items As New List(Of MappingConfigItem)
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
12
MultiTool.Shared/Templates/MappingConfigItem.vb
Normal file
12
MultiTool.Shared/Templates/MappingConfigItem.vb
Normal file
@@ -0,0 +1,12 @@
|
||||
Namespace Templates
|
||||
Public Class MappingConfigItem
|
||||
Public Property OrderKey As Integer
|
||||
Public Property SourceName As String
|
||||
Public Property SourceItem As String
|
||||
Public Property SourceRegex As String
|
||||
Public Property DestinationName As String
|
||||
Public Property DestinationItem As String
|
||||
Public Property DestinationValue As String
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@@ -19,7 +19,7 @@
|
||||
''' Required value from Schema. This value will be written in the ColumnConfig and is not relevant from that point on.
|
||||
''' </summary>
|
||||
Public Property IsRequired As Boolean
|
||||
Public Property Config As ColumnConfig
|
||||
Public Property Config As TemplateConfigItem
|
||||
End Class
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
@@ -6,10 +6,10 @@ Namespace Templates
|
||||
''' Class for loading column/field config from database
|
||||
''' </summary>
|
||||
Public Class TemplateConfig
|
||||
Public Columns As List(Of ColumnConfig)
|
||||
Public Property Items As List(Of TemplateConfigItem)
|
||||
|
||||
Public Function GetColumn(pName As String) As ColumnConfig
|
||||
Return Columns.
|
||||
Public Function GetColumn(pName As String) As TemplateConfigItem
|
||||
Return Items.
|
||||
Where(Function(c) c.Name = pName).
|
||||
FirstOrDefault()
|
||||
End Function
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Imports MultiTool.Shared.Constants
|
||||
|
||||
Namespace Templates
|
||||
Public Class ColumnConfig
|
||||
Public Class TemplateConfigItem
|
||||
Public Property Name As String
|
||||
Public Property Table As String
|
||||
Public Property Type As ColumnType
|
||||
@@ -1,8 +1,6 @@
|
||||
Imports System.IO
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports MultiTool.Shared.Winline
|
||||
Imports MultiTool.Shared.Helpers
|
||||
|
||||
Namespace Templates
|
||||
Public Class TemplateLoader
|
||||
@@ -12,12 +10,15 @@ Namespace Templates
|
||||
|
||||
Public Property TemplateList As List(Of Template)
|
||||
Public Property TemplateConfiguration As New TemplateConfig
|
||||
Public Property MappingConfiguration As New List(Of MappingConfig)
|
||||
Public Property MappingConfiguration As New MappingConfig
|
||||
Public Property MandatorConfiguration As New MandatorConfig
|
||||
|
||||
Private ReadOnly Database As MSSQLServer
|
||||
|
||||
Private Const VWEDI_XML_ITEMS = "VWEDI_XML_ITEMS"
|
||||
Private Const VWEDI_XML_MAPPING = "VWEDI_XML_MAPPING"
|
||||
Private Const TBEDI_XML_MANDATORS = "TBEDI_XML_MANDATORS"
|
||||
Private Const TBEDI_XML_TEMPLATES = "TBEDI_XML_TEMPLATES"
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pMSSQL As MSSQLServer)
|
||||
MyBase.New(pLogConfig, pLogConfig.GetLogger)
|
||||
@@ -26,7 +27,7 @@ Namespace Templates
|
||||
|
||||
Public Async Function LoadTemplates() As Task(Of Boolean)
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [DD_ECM].[dbo].[TBEDI_XML_TEMPLATES]"
|
||||
Dim oSql = $"SELECT * FROM [DD_ECM].[dbo].[{TBEDI_XML_TEMPLATES}]"
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(oSql)
|
||||
Dim oTemplates As New List(Of Template)
|
||||
|
||||
@@ -55,10 +56,10 @@ Namespace Templates
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [DD_ECM].[dbo].[{VWEDI_XML_MAPPING}]"
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(oSql)
|
||||
Dim oMappingConfigList As New List(Of MappingConfig)
|
||||
Dim oMappingConfig As New MappingConfig
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oTemplate As New MappingConfig With {
|
||||
Dim oTemplate As New MappingConfigItem With {
|
||||
.OrderKey = oRow.ItemEx("ORDER_KEY", String.Empty),
|
||||
.SourceName = oRow.ItemEx("SOURCE_NAME", String.Empty),
|
||||
.SourceItem = oRow.ItemEx("SOURCE_ITEM", String.Empty),
|
||||
@@ -68,10 +69,35 @@ Namespace Templates
|
||||
.DestinationValue = oRow.ItemEx("DESTINATION_VALUE", String.Empty)
|
||||
}
|
||||
|
||||
oMappingConfigList.Add(oTemplate)
|
||||
oMappingConfig.Items.Add(oTemplate)
|
||||
Next
|
||||
|
||||
MappingConfiguration = oMappingConfigList
|
||||
MappingConfiguration = oMappingConfig
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Async Function LoadMandatorConfiguration() As Task(Of Boolean)
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [DD_ECM].[dbo].[{TBEDI_XML_MANDATORS}] ORDER BY ORDER_KEY"
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(oSql)
|
||||
Dim oMandatorConfig As New MandatorConfig
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oMandator As New MandatorConfigItem With {
|
||||
.OrderKey = oRow.ItemEx("ORDER_KEY", String.Empty),
|
||||
.Name = oRow.ItemEx("NAME", String.Empty)
|
||||
}
|
||||
|
||||
oMandatorConfig.Items.Add(oMandator)
|
||||
Next
|
||||
|
||||
MandatorConfiguration = oMandatorConfig
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
@@ -85,20 +111,20 @@ Namespace Templates
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [DD_ECM].[dbo].[{VWEDI_XML_ITEMS}]"
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(oSql)
|
||||
Dim oItems As New List(Of ColumnConfig)
|
||||
Dim oItems As New List(Of TemplateConfigItem)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oColumn As New ColumnConfig() With {
|
||||
Dim oColumn As New TemplateConfigItem() With {
|
||||
.Template = oRow.ItemEx("TEMPLATE_NAME", String.Empty),
|
||||
.Table = oRow.ItemEx("XML_TABLE", String.Empty),
|
||||
.Name = oRow.ItemEx("XML_ITEM", String.Empty),
|
||||
.Type = ColumnConfig.ConvertType(ItemEx(oRow, "DATA_TYPE", String.Empty)),
|
||||
.Type = TemplateConfigItem.ConvertType(ItemEx(oRow, "DATA_TYPE", String.Empty)),
|
||||
.OrderKey = oRow.ItemEx("ORDER_KEY", 0),
|
||||
.IsReadOnly = oRow.ItemEx("IS_READ_ONLY", False),
|
||||
.IsVisible = oRow.ItemEx("IS_VISIBLE", True),
|
||||
.IsRequired = oRow.ItemEx("IS_REQUIRED", False),
|
||||
.IsHead = oRow.ItemEx("IS_HEAD", True),
|
||||
.[Function] = New ColumnConfig.ColumnFunction With {
|
||||
.[Function] = New TemplateConfigItem.ColumnFunction With {
|
||||
.Id = oRow.ItemEx("FUNCTION_ID", 0),
|
||||
.Name = oRow.ItemEx("FUNCTION_NAME", String.Empty),
|
||||
.Params = oRow.ItemEx("FUNCTION_PARAMETERS", String.Empty)
|
||||
@@ -109,7 +135,7 @@ Namespace Templates
|
||||
Next
|
||||
|
||||
TemplateConfiguration = New TemplateConfig With {
|
||||
.Columns = oItems
|
||||
.Items = oItems
|
||||
}
|
||||
|
||||
Return True
|
||||
@@ -173,7 +199,7 @@ Namespace Templates
|
||||
Dim oConfig = pTemplateConfig.GetColumn(oColumn.Name)
|
||||
|
||||
If oConfig Is Nothing Then
|
||||
oConfig = New ColumnConfig With {
|
||||
oConfig = New TemplateConfigItem With {
|
||||
.IsRequired = oColumn.IsRequired,
|
||||
.Name = oColumn.Name
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports MultiTool.Shared.Helpers
|
||||
Imports MultiTool.Shared.Winline.Entities
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports MultiTool.Shared.Templates
|
||||
Imports MultiTool.Shared.Constants
|
||||
|
||||
Namespace Winline
|
||||
Public Class WinlineData
|
||||
@@ -10,6 +11,8 @@ Namespace Winline
|
||||
|
||||
Private ReadOnly Database As MSSQLServer
|
||||
Private ReadOnly Config As Config
|
||||
Private ReadOnly MandatorConfig As MandatorConfig
|
||||
Private ReadOnly MappingConfig As MappingConfig
|
||||
|
||||
Public Articles As New List(Of Article)
|
||||
Public Accounts As New List(Of Account)
|
||||
@@ -18,39 +21,12 @@ Namespace Winline
|
||||
|
||||
Public Years As List(Of Integer)
|
||||
|
||||
Public Const ALL_MESOCOMP = "mesocomp"
|
||||
|
||||
Public Const V21_ARTICLENUMBER = "c002"
|
||||
Public Const V21_ARTICLEDESCRIPTION = "c003"
|
||||
Public Const V21_MAINARTICLENUMBER = "c011"
|
||||
Public Const V21_REPLACEMENTARTICLENUMBER = "c123"
|
||||
Public Const V21_EAN = "c075"
|
||||
|
||||
Public Const V50_ACCOUNTNUMBER = "c002"
|
||||
Public Const V50_ACCOUNTNAME = "c003"
|
||||
Public Const V50_STREETNAME = "c050"
|
||||
Public Const V50_ZIPCODE = "c051"
|
||||
Public Const V50_CITYNAME = "c052"
|
||||
Public Const V50_GLN = "c260"
|
||||
|
||||
Public Const T45_KEY = "c000"
|
||||
Public Const T45_NAME = "c001"
|
||||
Public Const T45_CONTACTNUMBER = "c063"
|
||||
|
||||
Public Const V05_ACCOUNTID = "c002"
|
||||
Public Const V05_ACCOUNTNAME = "c003"
|
||||
|
||||
Public Const T357_KINDID = "c030"
|
||||
Public Const T357_KINDNAME = "c001"
|
||||
|
||||
Public Const T01_DATABASEINFO = "c004"
|
||||
Public Const T01_MANDATORID = "c000"
|
||||
Public Const T01_MANDATORNAME = "c003"
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As Config)
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As Config, pMappingConfig As MappingConfig, pMandatorConfig As MandatorConfig)
|
||||
MyBase.New(pLogConfig, pLogConfig.GetLogger())
|
||||
Database = pDatabase
|
||||
Config = pConfig
|
||||
MandatorConfig = pMandatorConfig
|
||||
MappingConfig = pMappingConfig
|
||||
End Sub
|
||||
|
||||
<DebuggerStepThrough>
|
||||
@@ -165,17 +141,14 @@ Namespace Winline
|
||||
.Server = oDbInfo.Item2
|
||||
}
|
||||
|
||||
'Dim oMandatorConfig As Config.MandatorConfig = Config.Mandators.
|
||||
' Where(Function(m) oMandator.Id = m.Name).
|
||||
' SingleOrDefault()
|
||||
Dim oMandatorConfig As MandatorConfigItem = MandatorConfig.Items.
|
||||
Where(Function(item) item.Name = oMandator.Id).
|
||||
SingleOrDefault()
|
||||
|
||||
'Dim oMandatorConfig2 = MappingConfiguration.Where(Function(c) c.)
|
||||
|
||||
'If oMandatorConfig IsNot Nothing Then
|
||||
' oMandator.IsWhitelisted = True
|
||||
' oMandator.Regex = oMandatorConfig.ArticleRegex
|
||||
' oMandator.Order = oMandatorConfig.Order
|
||||
'End If
|
||||
If oMandatorConfig IsNot Nothing Then
|
||||
oMandator.IsWhitelisted = True
|
||||
oMandator.Order = oMandatorConfig.OrderKey
|
||||
End If
|
||||
|
||||
Mandators.Add(oMandator)
|
||||
Next
|
||||
@@ -411,17 +384,20 @@ Namespace Winline
|
||||
If p.Fields.ContainsKey("Artikelnummer") Then
|
||||
Return p.Fields.Item("Artikelnummer").Original
|
||||
Else
|
||||
' TODO: Throw or ignore?
|
||||
Throw New Exceptions.MissingAttributeException("Artikelnummer")
|
||||
Return Nothing
|
||||
End If
|
||||
End Function).
|
||||
Where(Function(ean) ean IsNot Nothing).
|
||||
Distinct().
|
||||
ToList()
|
||||
|
||||
Dim oYear = GetWinLineYear()
|
||||
Dim oMandatorId As String = String.Empty
|
||||
|
||||
' TODO: Instead load whitelisted mandators from database
|
||||
Dim oWhitelistedMandators = Mandators.
|
||||
Where(Function(m) m.IsWhitelisted = True).
|
||||
OrderBy(Function(m) m.Order).
|
||||
ToList()
|
||||
|
||||
For Each oEANNumber In oEANNumbers
|
||||
@@ -453,15 +429,19 @@ Namespace Winline
|
||||
Dim oArticleNumber As String = ItemEx(oRow, V21_MAINARTICLENUMBER, String.Empty)
|
||||
|
||||
' EAN was found, now we need to check it against the Regex of the current Mandantor, if one exists
|
||||
If oMandator.Regex <> String.Empty Then
|
||||
Dim oMappingConfigItem = MappingConfig.Items.
|
||||
Where(Function(item) item.DestinationName = "MANDATOR" And item.DestinationValue = oMandator.Id And item.SourceName = "ARTICLE").
|
||||
SingleOrDefault()
|
||||
|
||||
If oMappingConfigItem IsNot Nothing Then
|
||||
|
||||
Try
|
||||
Dim oRegex As New Regex(oMandator.Regex)
|
||||
Dim oRegex As New Regex(oMappingConfigItem.SourceRegex)
|
||||
Dim oMatch = oRegex.Match(oArticleNumber)
|
||||
|
||||
' If ArticleNumber matches the regex, we assign it and exit
|
||||
If oMatch.Success Then
|
||||
oMandatorId = oMandator.Id
|
||||
Exit For
|
||||
Return oMandator
|
||||
Else
|
||||
' If it does not match, continue to the next mandator
|
||||
End If
|
||||
@@ -469,21 +449,15 @@ Namespace Winline
|
||||
Logger.Error(ex)
|
||||
Logger.Warn("Regex [{0}] could not be parsed. Skipping.", oMandator.Regex)
|
||||
End Try
|
||||
|
||||
Else
|
||||
' If no regex was found, we assume the number matches
|
||||
oMandatorId = oMandator.Id
|
||||
Continue For
|
||||
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
|
||||
If oMandatorId = String.Empty Then
|
||||
Return Nothing
|
||||
Else
|
||||
Return oWhitelistedMandators.
|
||||
Where(Function(m) m.Id = oMandatorId).
|
||||
Take(1).
|
||||
SingleOrDefault()
|
||||
End If
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
|
||||
Reference in New Issue
Block a user