Add support for multiple functions per field, add ADDRESS function

This commit is contained in:
Jonathan Jenne
2023-06-26 11:27:51 +02:00
parent 7846e660b9
commit 68e4c59e63
9 changed files with 274 additions and 154 deletions

View File

@@ -3,6 +3,7 @@ Imports DigitalData.Modules.Language
Namespace Templates
Public Class FieldConfig
Public Property Id As Integer
Public Property Name As String
Public Property Table As String
Public Property Type As ColumnType
@@ -16,19 +17,7 @@ Namespace Templates
Public Property IsVirtual As Boolean
Public Property PreferExternalValue As Boolean
Public Property [Function] As ColumnFunction
Public ReadOnly Property FunctionName As String
Get
Return Utils.NotNull([Function]?.Name, String.Empty)
End Get
End Property
Public ReadOnly Property FunctionParams As String
Get
Return Utils.NotNull([Function]?.Params, String.Empty)
End Get
End Property
Public Property Functions As New List(Of ColumnFunction)
Public Class ColumnFunction
Public Id As XmlFunction

View File

@@ -11,7 +11,7 @@ Namespace Templates
Public ReadOnly Property SqlItems As List(Of FieldConfig)
Get
Return Items.
Where(Function(item) item.Function.Name = Constants.FUNCTION_SQL).
Where(Function(item) item.Functions.Any(Function(f) f.Name = Constants.FUNCTION_SQL)).
ToList()
End Get
End Property

View File

@@ -19,6 +19,7 @@ Namespace Templates
Private Const SQL_TBMT_FILTERS = "SELECT * FROM [DD_ECM].[dbo].[VWMT_FILTERS]"
Private Const SQL_VWMT_ITEMS = "SELECT * FROM [DD_ECM].[dbo].[VWMT_ITEMS] ORDER BY TEMPLATE_NAME, TABLE_NAME"
Private Const SQL_VWMT_FUNCTIONS = "SELECT * FROM [DD_ECM].[dbo].[VWMT_FUNCTIONS] ORDER BY ITEM_ID, SEQUENCE"
Private Const SQL_VWMT_MAPPING = "SELECT * FROM [DD_ECM].[dbo].[VWMT_MAPPING]"
Private Const SQL_TBMT_MANDATORS = "SELECT * FROM [DD_ECM].[dbo].[TBMT_MANDATORS] ORDER BY ORDER_KEY"
Private Const SQL_TBMT_CONFIG = "SELECT * FROM [DD_ECM].[dbo].[TBMT_CONFIG]"
@@ -191,6 +192,7 @@ Namespace Templates
For Each oRow As DataRow In oTable.Rows
Dim oColumn As New FieldConfig() With {
.Id = oRow.ItemEx("ITEM_ID", 0),
.Template = oRow.ItemEx("TEMPLATE_NAME", String.Empty),
.Table = oRow.ItemEx("TABLE_NAME", String.Empty),
.Name = oRow.ItemEx("ITEM_NAME", String.Empty),
@@ -202,11 +204,7 @@ Namespace Templates
.IsVirtual = oRow.ItemEx("IS_VIRTUAL", False),
.IsHead = oRow.ItemEx("IS_HEAD", True),
.PreferExternalValue = oRow.ItemEx("PREFER_EXTERNAL", True),
.[Function] = New FieldConfig.ColumnFunction With {
.Id = oRow.ItemEx("FUNCTION_ID", 0),
.Name = oRow.ItemEx("FUNCTION_NAME", String.Empty),
.Params = oRow.ItemEx("FUNCTION_PARAMETERS", String.Empty)
}
.Functions = New List(Of FieldConfig.ColumnFunction)
}
Logger.Debug("Creating Template Item for Table [{0}]: [{1}]", oColumn.Table, oColumn.Name)
@@ -227,6 +225,37 @@ Namespace Templates
End Try
End Function
Public Async Function LoadTemplateFunctions() As Task(Of Boolean)
Try
Dim oTable As DataTable = Await Database.GetDatatableAsync(SQL_VWMT_FUNCTIONS)
Dim oItems As New List(Of FieldConfig)
For Each oRow As DataRow In oTable.Rows
Dim oTemplateItemId = oRow.ItemEx("ITEM_ID", 0)
Dim oTemplateItem = TemplateConfiguration.Items.SingleOrDefault(Function(i) i.Id = oTemplateItemId)
If oTemplateItem Is Nothing Then
Logger.Warn("Function configuration could not be assigned to an existing template item, item id was [{0}]", oTemplateItemId)
Continue For
End If
oTemplateItem.Functions.Add(New FieldConfig.ColumnFunction With {
.Id = oRow.ItemEx("FUNCTION_ID", 0),
.Name = oRow.ItemEx("FUNCTION_NAME", String.Empty),
.Params = oRow.ItemEx("FUNCTION_PARAMETERS", String.Empty)
})
Next
Return True
Catch ex As Exception
Logger.Error(ex)
Return False
End Try
End Function
Public Function UpdateTemplateFromFile(pTemplate As Template, pInputDirectory As String) As Template
Dim oFullPath = Path.Combine(pInputDirectory, pTemplate.FileName)