Add FIELD Function, fix virtual columns
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
Imports System.IO
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Language
|
||||
Imports MultiTool.Shared.Exceptions
|
||||
Imports MultiTool.Shared.Templates
|
||||
Imports MultiTool.Shared.Winline
|
||||
@@ -102,14 +103,12 @@ Namespace Documents
|
||||
''' Loads a single document from the FullName Property in the Document Object
|
||||
''' </summary>
|
||||
''' <example>
|
||||
'''
|
||||
''' A document might look like this:
|
||||
''' <MESOWebService>
|
||||
''' <Row1></Row1>
|
||||
''' <Row2></Row2>
|
||||
''' <Row3></Row3>
|
||||
''' </MESOWebService>
|
||||
'''
|
||||
''' </example>
|
||||
Private Function LoadDocumentData(pDocument As Document, pTemplate As Template, pTemplateConfig As TemplateConfig) As Document
|
||||
Dim oText As String = IO.File.ReadAllText(pDocument.FullName)
|
||||
@@ -197,17 +196,6 @@ Namespace Documents
|
||||
oColumnSortKey += 1
|
||||
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
|
||||
Dim oRow = New DocumentRow With {
|
||||
.SortKey = oRowSortKey,
|
||||
@@ -335,7 +323,7 @@ Namespace Documents
|
||||
|
||||
Private Function ApplyFieldFunctionForImport(pDocument As Document, pMandator As Mandator, pTemplate As Template) As Document
|
||||
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
|
||||
If oTable Is Nothing Then
|
||||
@@ -357,10 +345,26 @@ Namespace Documents
|
||||
|
||||
If IsNothing(oParam) Then
|
||||
Logger.Warn("FIELD function needs exactly one parameter!")
|
||||
Return pDocument
|
||||
Continue For
|
||||
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
|
||||
Next
|
||||
@@ -400,8 +404,6 @@ Namespace Documents
|
||||
field.Value.Final = oMapping.DestinationValue
|
||||
End Sub)
|
||||
|
||||
|
||||
|
||||
Else
|
||||
' don't do anything
|
||||
|
||||
|
||||
@@ -65,13 +65,22 @@
|
||||
Public Property IsVirtual As Boolean = False
|
||||
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
|
||||
Get
|
||||
Return [Error] <> FieldError.None Or (IsRequired And Final = String.Empty)
|
||||
|
||||
'Return IsRequired = True And (
|
||||
' [Error] <> FieldError.None Or Final = String.Empty
|
||||
')
|
||||
End Get
|
||||
End Property
|
||||
|
||||
|
||||
Reference in New Issue
Block a user