Add FIELD Function, fix virtual columns
This commit is contained in:
parent
efd2aeb775
commit
ce78dea8cb
@ -1,6 +1,7 @@
|
|||||||
Imports System.IO
|
Imports System.IO
|
||||||
Imports System.Text.RegularExpressions
|
Imports System.Text.RegularExpressions
|
||||||
Imports DigitalData.Modules.Logging
|
Imports DigitalData.Modules.Logging
|
||||||
|
Imports DigitalData.Modules.Language
|
||||||
Imports MultiTool.Shared.Exceptions
|
Imports MultiTool.Shared.Exceptions
|
||||||
Imports MultiTool.Shared.Templates
|
Imports MultiTool.Shared.Templates
|
||||||
Imports MultiTool.Shared.Winline
|
Imports MultiTool.Shared.Winline
|
||||||
@ -102,14 +103,12 @@ Namespace Documents
|
|||||||
''' Loads a single document from the FullName Property in the Document Object
|
''' Loads a single document from the FullName Property in the Document Object
|
||||||
''' </summary>
|
''' </summary>
|
||||||
''' <example>
|
''' <example>
|
||||||
'''
|
|
||||||
''' A document might look like this:
|
''' A document might look like this:
|
||||||
''' <MESOWebService>
|
''' <MESOWebService>
|
||||||
''' <Row1></Row1>
|
''' <Row1></Row1>
|
||||||
''' <Row2></Row2>
|
''' <Row2></Row2>
|
||||||
''' <Row3></Row3>
|
''' <Row3></Row3>
|
||||||
''' </MESOWebService>
|
''' </MESOWebService>
|
||||||
'''
|
|
||||||
''' </example>
|
''' </example>
|
||||||
Private Function LoadDocumentData(pDocument As Document, pTemplate As Template, pTemplateConfig As TemplateConfig) As Document
|
Private Function LoadDocumentData(pDocument As Document, pTemplate As Template, pTemplateConfig As TemplateConfig) As Document
|
||||||
Dim oText As String = IO.File.ReadAllText(pDocument.FullName)
|
Dim oText As String = IO.File.ReadAllText(pDocument.FullName)
|
||||||
@ -197,17 +196,6 @@ Namespace Documents
|
|||||||
oColumnSortKey += 1
|
oColumnSortKey += 1
|
||||||
Next
|
Next
|
||||||
|
|
||||||
' Create Virtual fields
|
|
||||||
Dim oVirtualColumns = pTemplateConfig.Items.Where(Function(item) item.IsVirtual And item.Table = oTable.Name).ToList()
|
|
||||||
For Each oColumn In oVirtualColumns
|
|
||||||
oFields.Add(oColumn.Name, New DocumentRow.FieldValue With {
|
|
||||||
.DataType = oColumn.Type,
|
|
||||||
.IsRequired = oColumn.IsRequired,
|
|
||||||
.SortKey = oColumn.OrderKey,
|
|
||||||
.IsVirtual = True
|
|
||||||
})
|
|
||||||
Next
|
|
||||||
|
|
||||||
' Create a DocumentRow object for each Top Level Element
|
' Create a DocumentRow object for each Top Level Element
|
||||||
Dim oRow = New DocumentRow With {
|
Dim oRow = New DocumentRow With {
|
||||||
.SortKey = oRowSortKey,
|
.SortKey = oRowSortKey,
|
||||||
@ -335,7 +323,7 @@ Namespace Documents
|
|||||||
|
|
||||||
Private Function ApplyFieldFunctionForImport(pDocument As Document, pMandator As Mandator, pTemplate As Template) As Document
|
Private Function ApplyFieldFunctionForImport(pDocument As Document, pMandator As Mandator, pTemplate As Template) As Document
|
||||||
For Each oRow As DocumentRow In pDocument.Rows
|
For Each oRow As DocumentRow In pDocument.Rows
|
||||||
Dim oTable = pTemplate.Tables.Where(Function(table) table.Name = oRow.TableName).SingleOrDefault()
|
Dim oTable = pDocument.Schema.Tables.Where(Function(table) table.Name = oRow.TableName).SingleOrDefault()
|
||||||
|
|
||||||
For Each oField In oRow.Fields
|
For Each oField In oRow.Fields
|
||||||
If oTable Is Nothing Then
|
If oTable Is Nothing Then
|
||||||
@ -357,10 +345,26 @@ Namespace Documents
|
|||||||
|
|
||||||
If IsNothing(oParam) Then
|
If IsNothing(oParam) Then
|
||||||
Logger.Warn("FIELD function needs exactly one parameter!")
|
Logger.Warn("FIELD function needs exactly one parameter!")
|
||||||
Return pDocument
|
Continue For
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
Dim oFieldName = oParam.Key
|
||||||
|
Dim oSubKey = oParam.Value
|
||||||
|
|
||||||
|
Dim oReferencedField = oRow.Fields.
|
||||||
|
Where(Function(field) field.Key = oFieldName).
|
||||||
|
FirstOrDefault()
|
||||||
|
|
||||||
|
If IsNothing(oReferencedField) = False Then
|
||||||
|
Dim oValue As String = Utils.NotNull(oReferencedField.Value.GetValue(oSubKey), String.Empty)
|
||||||
|
|
||||||
|
If oValue <> String.Empty Then
|
||||||
|
oField.Value.Final = oValue
|
||||||
|
End If
|
||||||
|
Else
|
||||||
|
Logger.Warn("Referenced Field [{0}] was not found!", oFieldName)
|
||||||
|
Continue For
|
||||||
|
End If
|
||||||
|
|
||||||
End If
|
End If
|
||||||
Next
|
Next
|
||||||
@ -400,8 +404,6 @@ Namespace Documents
|
|||||||
field.Value.Final = oMapping.DestinationValue
|
field.Value.Final = oMapping.DestinationValue
|
||||||
End Sub)
|
End Sub)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Else
|
Else
|
||||||
' don't do anything
|
' don't do anything
|
||||||
|
|
||||||
|
|||||||
@ -65,13 +65,22 @@
|
|||||||
Public Property IsVirtual As Boolean = False
|
Public Property IsVirtual As Boolean = False
|
||||||
Public Property SortKey As Integer = 0
|
Public Property SortKey As Integer = 0
|
||||||
|
|
||||||
|
Public Function GetValue(pValueType) As String
|
||||||
|
Select Case pValueType
|
||||||
|
Case "Original"
|
||||||
|
Return Original
|
||||||
|
Case "External"
|
||||||
|
Return External
|
||||||
|
Case "Final"
|
||||||
|
Return Final
|
||||||
|
Case Else
|
||||||
|
Return Nothing
|
||||||
|
End Select
|
||||||
|
End Function
|
||||||
|
|
||||||
Public ReadOnly Property HasError As Boolean
|
Public ReadOnly Property HasError As Boolean
|
||||||
Get
|
Get
|
||||||
Return [Error] <> FieldError.None Or (IsRequired And Final = String.Empty)
|
Return [Error] <> FieldError.None Or (IsRequired And Final = String.Empty)
|
||||||
|
|
||||||
'Return IsRequired = True And (
|
|
||||||
' [Error] <> FieldError.None Or Final = String.Empty
|
|
||||||
')
|
|
||||||
End Get
|
End Get
|
||||||
End Property
|
End Property
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,9 @@ Namespace Templates
|
|||||||
Public Property Parameter2 As String
|
Public Property Parameter2 As String
|
||||||
Public Property FinalSQL As String
|
Public Property FinalSQL As String
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Tabledata from XSD
|
||||||
|
''' </summary>
|
||||||
Public Property Tables As New List(Of Table)
|
Public Property Tables As New List(Of Table)
|
||||||
|
|
||||||
Public Property InputDirectory As String
|
Public Property InputDirectory As String
|
||||||
@ -68,6 +71,9 @@ Namespace Templates
|
|||||||
End If
|
End If
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Table from XSD
|
||||||
|
''' </summary>
|
||||||
Class Table
|
Class Table
|
||||||
Public Property Name As String
|
Public Property Name As String
|
||||||
Public Property Columns As New List(Of Column)
|
Public Property Columns As New List(Of Column)
|
||||||
|
|||||||
@ -240,9 +240,11 @@ Namespace Templates
|
|||||||
Return pTemplate
|
Return pTemplate
|
||||||
End If
|
End If
|
||||||
|
|
||||||
For Each oTable In pTemplate.Tables
|
Dim oTemplate = CreateVirtualColumns(pTemplate, pTemplateConfig)
|
||||||
|
|
||||||
|
For Each oTable In oTemplate.Tables
|
||||||
For Each oColumn As Template.Column In oTable.Columns
|
For Each oColumn As Template.Column In oTable.Columns
|
||||||
Dim oConfig = pTemplateConfig.GetColumn(oColumn.Name, oTable.Name)
|
Dim oConfig As TemplateConfigItem = pTemplateConfig.GetColumn(oColumn.Name, oTable.Name)
|
||||||
|
|
||||||
If oConfig Is Nothing Then
|
If oConfig Is Nothing Then
|
||||||
oConfig = New TemplateConfigItem With {
|
oConfig = New TemplateConfigItem With {
|
||||||
@ -255,6 +257,31 @@ Namespace Templates
|
|||||||
Next
|
Next
|
||||||
Next
|
Next
|
||||||
|
|
||||||
|
Return oTemplate
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Function CreateVirtualColumns(pTemplate As Template, pTemplateConfig As TemplateConfig) As Template
|
||||||
|
For Each oConfigItem In pTemplateConfig.Items
|
||||||
|
' Find the table that relates to this config item
|
||||||
|
Dim oTable = pTemplate.Tables.Where(Function(table) table.Name = oConfigItem.Table).FirstOrDefault()
|
||||||
|
|
||||||
|
If oTable Is Nothing Then
|
||||||
|
Logger.Warn("Table [{0}] for item [{1}] does exist in this Template!", oConfigItem.Table, oConfigItem.Name)
|
||||||
|
Continue For
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim oColumnExists = oTable.Columns.Any(Function(column) column.Name = oConfigItem.Name)
|
||||||
|
|
||||||
|
If oColumnExists = False And oConfigItem.IsVirtual = True Then
|
||||||
|
oTable.Columns.Add(New Template.Column() With {
|
||||||
|
.Name = oConfigItem.Name,
|
||||||
|
.Config = oConfigItem,
|
||||||
|
.DataType = Constants.ColumnType.String,
|
||||||
|
.IsRequired = False
|
||||||
|
})
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
|
||||||
Return pTemplate
|
Return pTemplate
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user