Rename Schema to Template , Clean up obsolete files

This commit is contained in:
Jonathan Jenne
2021-11-19 14:16:07 +01:00
parent ee23cdd7e8
commit cc81a77f05
35 changed files with 216 additions and 1083 deletions

View File

@@ -1,12 +1,12 @@
Imports System.IO
Imports MultiTool.Shared.Schemas
Imports MultiTool.Shared.Winline
Imports MultiTool.Shared.Templates
Imports MultiTool.Shared.Winline.Entities
Namespace Documents
Public Class Document
Public File As FileInfo
Public Property Type As DocumentType
Public Schema As Schema
Public Schema As Template
Public Mandator As Mandator
Public TemplateName As String

View File

@@ -1,9 +1,9 @@
Imports System.Globalization
Imports System.IO
Imports System.IO
Imports DigitalData.Modules.Logging
Imports MultiTool.Shared.Exceptions
Imports MultiTool.Shared.Schemas
Imports MultiTool.Shared.Templates
Imports MultiTool.Shared.Winline
Imports MultiTool.Shared.Winline.Entities
Namespace Documents
Public Class DocumentLoader
@@ -25,7 +25,7 @@ Namespace Documents
End Sub
Public Function LoadFiles(pInputDirectory As String, pSchema As Schema, pMandator As Mandator) As Boolean
Public Function LoadFiles(pInputDirectory As String, pTemplate As Template, pMandator As Mandator) As Boolean
If pInputDirectory = String.Empty Then
Throw New ArgumentNullException("InputDirectory")
End If
@@ -41,7 +41,7 @@ Namespace Documents
For Each oFile In oFiles
Try
Dim oDocument = LoadFile(oFile, pSchema, pMandator)
Dim oDocument = LoadFile(oFile, pTemplate, pMandator)
Files.Add(oDocument)
Dim oInfo As FileLoadInfo
@@ -68,16 +68,16 @@ Namespace Documents
End Try
End Function
Public Function LoadFile(pFileInfo As FileInfo, pSchema As Schema, pMandator As Mandator) As Document
Public Function LoadFile(pFileInfo As FileInfo, pTemplate As Template, pMandator As Mandator) As Document
Dim oFileList As New List(Of FileInfo) From {pFileInfo}
Logger.Info("Loading file [{0}]", pFileInfo.Name)
Try
Return oFileList.
Select(AddressOf WrapFileInfo).
Select(Function(d) IncludeSchema(d, pSchema)).
Select(Function(d) LoadDocumentData(d, pSchema)).
Select(Function(d) MatchDataFromWinLine(d, Winline.Mandators, pMandator, pSchema)).
Select(Function(d) IncludeSchema(d, pTemplate)).
Select(Function(d) LoadDocumentData(d, pTemplate)).
Select(Function(d) MatchDataFromWinLine(d, Winline.Mandators, pMandator, pTemplate)).
SingleOrDefault()
Catch ex As Exception
Logger.Error(ex)
@@ -86,8 +86,8 @@ Namespace Documents
End Function
Private Function IncludeSchema(pDocument As Document, pSchema As Schema) As Document
pDocument.Schema = pSchema
Private Function IncludeSchema(pDocument As Document, pTemplate As Template) As Document
pDocument.Schema = pTemplate
Return pDocument
End Function
@@ -105,7 +105,7 @@ Namespace Documents
''' </MESOWebService>
'''
''' </example>
Private Function LoadDocumentData(pDocument As Document, pSchema As Schema) As Document
Private Function LoadDocumentData(pDocument As Document, pTemplate As Template) As Document
Dim oText As String = IO.File.ReadAllText(pDocument.FullName)
Dim oDoc = XDocument.Parse(oText)
@@ -150,7 +150,7 @@ Namespace Documents
Dim oColumnSortKey = 0
Dim oFields As New Dictionary(Of String, DocumentRow.FieldValue)
Dim oSubElements = oTopLevelElement.Descendants().ToList()
Dim oTable = pSchema.Tables.
Dim oTable = pTemplate.Tables.
Where(Function(t) t.Name = oTopLevelElement.Name).
FirstOrDefault()
@@ -165,7 +165,7 @@ Namespace Documents
Dim oValue = oSubElement.Value.Trim()
' TODO: Needed when we have time for date times
'If oSchemaField.DataType = Constants.ColumnType.Date Then
'If oTemplateField.DataType = Constants.ColumnType.Date Then
' Dim oDate = Date.ParseExact(oValue, "yyyy-MM-dd", CultureInfo.InvariantCulture)
' oValue = oDate.ToString("d")
'End If
@@ -193,15 +193,15 @@ Namespace Documents
Next
'For Each oSubElement As XElement In oSubElements
' Dim oSchemaField = oTable.Columns.
' Dim oTemplateField = oTable.Columns.
' Where(Function(c) c.Name = oSubElement.Name).
' SingleOrDefault()
' Dim oRequired = oSchemaField.IsRequired
' Dim oRequired = oTemplateField.IsRequired
' Dim oValue = oSubElement.Value.Trim()
' ' TODO: Needed when we have time for date times
' 'If oSchemaField.DataType = Constants.ColumnType.Date Then
' 'If oTemplateField.DataType = Constants.ColumnType.Date Then
' ' Dim oDate = Date.ParseExact(oValue, "yyyy-MM-dd", CultureInfo.InvariantCulture)
' ' oValue = oDate.ToString("d")
' 'End If
@@ -209,7 +209,7 @@ Namespace Documents
' oFields.Add(oSubElement.Name.ToString, New DocumentRow.FieldValue With {
' .Original = oValue,
' .Final = oValue,
' .DataType = oSchemaField.DataType,
' .DataType = oTemplateField.DataType,
' .Required = oRequired
' })
@@ -255,8 +255,8 @@ Namespace Documents
End Function
Private Function MatchDataFromWinLine(pDocument As Document, pMandators As List(Of Mandator), pMandator As Mandator, pSchema As Schema) As Document
Dim oMandators As List(Of Winline.Mandator) = pMandators.
Private Function MatchDataFromWinLine(pDocument As Document, pMandators As List(Of Mandator), pMandator As Mandator, pTemplate As Template) As Document
Dim oMandators As List(Of Mandator) = pMandators.
Where(Function(m) m.IsWhitelisted = True).
OrderBy(Function(m) m.Order).
ToList()
@@ -273,13 +273,13 @@ Namespace Documents
Throw New Exceptions.NoMandatorException($"Mandator not found for file [{pDocument.File.Name}]")
End If
pDocument = MatchDocumentData(pDocument, oMandator, pSchema)
pDocument = MatchDocumentData(pDocument, oMandator, pTemplate)
pDocument.Mandator = oMandator
Return pDocument
End Function
Private Function MatchDocumentData(pDocument As Document, pMandator As Winline.Mandator, pSchema As Schema) As Document
Private Function MatchDocumentData(pDocument As Document, pMandator As Mandator, pTemplate As Template) As Document
Dim oYear = Winline.GetWinLineYear()
If pMandator Is Nothing Then
@@ -287,7 +287,7 @@ Namespace Documents
End If
For Each oRow As DocumentRow In pDocument.Rows
Dim oTable = pSchema.Tables.Where(Function(t) t.Name = oRow.Name).SingleOrDefault()
Dim oTable = pTemplate.Tables.Where(Function(t) t.Name = oRow.Name).SingleOrDefault()
For Each oField In oRow.Fields
If oTable Is Nothing Then
@@ -348,7 +348,7 @@ Namespace Documents
Return pDocument
End Function
Private Sub SetAccountByGLN(oRow As DocumentRow, pMandator As Winline.Mandator, pNumberField As String, pNameField As String)
Private Sub SetAccountByGLN(oRow As DocumentRow, pMandator As Mandator, pNumberField As String, pNameField As String)
' Try to read the Account number (which is a GLN really) and account Name
Dim oNumberItem As DocumentRow.FieldValue = oRow.Fields.GetOrDefault(pNumberField)
Dim oNameItem As DocumentRow.FieldValue = oRow.Fields.GetOrDefault(pNameField)

View File

@@ -1,28 +0,0 @@
Namespace Documents
Public Class DocumentMatch
Public Shared Property TypeMatchingTable As New Dictionary(Of String, DocumentType) From {
{"orders", DocumentType.Order},
{"ordrsp", DocumentType.OrderResponse},
{"desadv", DocumentType.DispatchNotification},
{"invoic", DocumentType.Invoice}
}
Public Shared Property SchemaMatchingTable As New Dictionary(Of DocumentType, Type) From {
{DocumentType.Order, GetType(Schemas.OrderSchema)}
}
Public Shared Function GetDocumentTypeFromTemplateName(pTemplateName As String) As DocumentType
Return TypeMatchingTable.
Where(Function(kv) pTemplateName.Contains(kv.Key)).
Select(Function(kv) kv.Value).
FirstOrDefault()
End Function
Public Shared Function GetDocumentSchemaFromDocumentType(pDocumentType As DocumentType) As Type
Return SchemaMatchingTable.
Where(Function(kv) pDocumentType = kv.Key).
Select(Function(kv) kv.Value).
FirstOrDefault()
End Function
End Class
End Namespace