Add Filters, Fix Column Names, Improve Config
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
Public Property Guid As Integer
|
||||
Public Property SQLCommand As String
|
||||
Public Property TableId As Integer
|
||||
Public Property TableName As String
|
||||
Public Property ColumnId As Integer
|
||||
Public Property ColumnName As String
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -17,7 +17,7 @@ Namespace Templates
|
||||
Public Property GeneralConfiguration As New GeneralConfig
|
||||
Public Property FilterConfiguration As New FilterConfig
|
||||
|
||||
Private Const SQL_TBMT_FILTERS = "SELECT * FROM [DD_ECM].[dbo].[TBMT_FILTERS]"
|
||||
Private Const SQL_TBMT_FILTERS = "SELECT * FROM [DD_ECM].[dbo].[VWMT_FILTERS]"
|
||||
Private Const SQL_VWMT_ITEMS = "SELECT * FROM [DD_ECM].[dbo].[VWMT_ITEMS]"
|
||||
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"
|
||||
@@ -38,7 +38,9 @@ Namespace Templates
|
||||
.Guid = oRow.Item("GUID"),
|
||||
.SQLCommand = oRow.ItemEx("SQL_COMMAND", String.Empty),
|
||||
.TableId = oRow.ItemEx("TABLE_ID", 0),
|
||||
.ColumnName = oRow.ItemEx("COLUMN_NAME", String.Empty)
|
||||
.TableName = oRow.ItemEx("TABLE_NAME", String.Empty),
|
||||
.ColumnId = oRow.ItemEx("ITEM_ID", 0),
|
||||
.ColumnName = oRow.ItemEx("ITEM_NAME", String.Empty)
|
||||
}
|
||||
|
||||
oFilters.Add(oFilter)
|
||||
@@ -188,8 +190,8 @@ Namespace Templates
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oColumn As New FieldConfig() With {
|
||||
.Template = oRow.ItemEx("TEMPLATE_NAME", String.Empty),
|
||||
.Table = oRow.ItemEx("XML_TABLE", String.Empty),
|
||||
.Name = oRow.ItemEx("XML_ITEM", String.Empty),
|
||||
.Table = oRow.ItemEx("TABLE_NAME", String.Empty),
|
||||
.Name = oRow.ItemEx("ITEM_NAME", String.Empty),
|
||||
.Type = FieldConfig.ConvertType(ItemEx(oRow, "DATA_TYPE", String.Empty)),
|
||||
.OrderKey = oRow.ItemEx("ORDER_KEY", 0),
|
||||
.IsReadOnly = oRow.ItemEx("IS_READ_ONLY", False),
|
||||
|
||||
@@ -5,6 +5,7 @@ Imports System.Xml
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Filesystem
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Language
|
||||
Imports MultiTool.Common.Documents
|
||||
Imports MultiTool.Common.Exceptions
|
||||
Imports MultiTool.Common.Templates
|
||||
@@ -16,6 +17,7 @@ Namespace Winline
|
||||
Inherits BaseClass
|
||||
|
||||
Private ReadOnly Config As WebServiceConfig
|
||||
Private ReadOnly Filters As FilterConfig
|
||||
Private ReadOnly Serializer As Serializer
|
||||
Private ReadOnly Winline As WinlineData
|
||||
Private ReadOnly FileEx As File
|
||||
@@ -23,10 +25,11 @@ Namespace Winline
|
||||
|
||||
Public Event WebServiceProgress As EventHandler(Of String)
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pWinline As WinlineData, pWebserviceConfig As WebServiceConfig, pGeneralConfig As GeneralConfig)
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pWinline As WinlineData, pWebserviceConfig As WebServiceConfig, pGeneralConfig As GeneralConfig, pFilterConfig As FilterConfig)
|
||||
MyBase.New(pLogConfig, pDatabase)
|
||||
Serializer = New Serializer(pLogConfig)
|
||||
Config = pWebserviceConfig
|
||||
Filters = pFilterConfig
|
||||
Patterns = New Patterns(pLogConfig, pGeneralConfig)
|
||||
FileEx = New File(LogConfig)
|
||||
Winline = pWinline
|
||||
@@ -320,17 +323,29 @@ Namespace Winline
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Antwort verarbeiten")
|
||||
|
||||
Logger.Debug("Postprocessing response.")
|
||||
oResponseBody = ApplyItemFunctionsForExport(pDocument, pTemplate, pMandator, oResponseBody)
|
||||
Logger.Debug("Processing response with type '{0}'", oContentType)
|
||||
|
||||
Select Case oContentType
|
||||
Case "text/xml"
|
||||
Dim oXmlResponse = oResponseBody
|
||||
Dim oDoc = ConvertStringToDocument(oXmlResponse)
|
||||
|
||||
Logger.Debug("Applying Item Filters")
|
||||
oDoc = ApplyItemFiltersForExport(pDocument, pTemplate, pMandator, oDoc)
|
||||
|
||||
Logger.Debug("Applying Item Functions")
|
||||
oDoc = ApplyItemFunctionsForExport(pDocument, pTemplate, pMandator, oDoc)
|
||||
|
||||
'TODO: Load filters and apply
|
||||
|
||||
Dim oXml = ConvertDocumentToString(oDoc)
|
||||
|
||||
' Webservice
|
||||
WriteResponseFile(pTemplate.OutputWebserviceDirectory, oResponseBody, $"{pTemplate.Name}-{pBaseFileName}-Response.xml")
|
||||
WriteResponseFile(pTemplate.OutputWebserviceDirectory, oXml, $"{pTemplate.Name}-{pBaseFileName}-Response.xml")
|
||||
' XML
|
||||
WriteResponseFile(pTemplate.OutputXmlFileDirectory, oResponseBody, $"{pTemplate.Name}-{pBaseFileName}.xml")
|
||||
WriteResponseFile(pTemplate.OutputXmlFileDirectory, oXml, $"{pTemplate.Name}-{pBaseFileName}.xml")
|
||||
' Archive
|
||||
WriteResponseFile(FileEx.CreateDateDirectory(pTemplate.ArchiveDirectory), oResponseBody, $"{pTemplate.Name}-{pBaseFileName}.xml")
|
||||
WriteResponseFile(FileEx.CreateDateDirectory(pTemplate.ArchiveDirectory), oXml, $"{pTemplate.Name}-{pBaseFileName}.xml")
|
||||
|
||||
Case "text/html"
|
||||
WriteResponseFile(pTemplate.OutputWebserviceDirectory, oResponseBody, $"{pTemplate.Name}-{pBaseFileName}-Response.txt")
|
||||
@@ -342,10 +357,23 @@ Namespace Winline
|
||||
End Select
|
||||
End Function
|
||||
|
||||
Private Function ApplyItemFunctionsForExport(pDocument As Entities.ExportDocument, pTemplate As Template, pMandator As Mandator, oResponseBody As String) As String
|
||||
Private Function ConvertStringToDocument(pXmlString As String) As XmlDocument
|
||||
Dim oDoc As New XmlDocument()
|
||||
oDoc.LoadXml(oResponseBody)
|
||||
oDoc.LoadXml(pXmlString)
|
||||
Return oDoc
|
||||
End Function
|
||||
|
||||
Private Function ConvertDocumentToString(pXmlDocument As XmlDocument) As String
|
||||
Dim oArray As Byte()
|
||||
Using oStream As New IO.MemoryStream
|
||||
pXmlDocument.Save(oStream)
|
||||
oArray = oStream.ToArray()
|
||||
End Using
|
||||
|
||||
Return System.Text.Encoding.UTF8.GetString(oArray)
|
||||
End Function
|
||||
|
||||
Private Function ApplyItemFunctionsForExport(pDocument As Entities.ExportDocument, pTemplate As Template, pMandator As Mandator, oXMLDocument As XmlDocument) As XmlDocument
|
||||
For Each oTable In pTemplate.Tables
|
||||
Logger.Debug("Processing Table [{0}]", oTable.Name)
|
||||
|
||||
@@ -362,7 +390,7 @@ Namespace Winline
|
||||
Dim oFunction = oItem.Config.Function.Name
|
||||
|
||||
Dim oPath = $"//MESOWebService/{oTableName}/{oItemName}"
|
||||
Dim oNodes As XmlNodeList = oDoc.SelectNodes(oPath)
|
||||
Dim oNodes As XmlNodeList = oXMLDocument.SelectNodes(oPath)
|
||||
|
||||
Logger.Debug("Calling function [{0}] on note [{1}]", oFunction, oPath)
|
||||
|
||||
@@ -404,32 +432,49 @@ Namespace Winline
|
||||
Next
|
||||
Next
|
||||
|
||||
Dim oArray As Byte()
|
||||
Using oStream As New IO.MemoryStream
|
||||
oDoc.Save(oStream)
|
||||
oArray = oStream.ToArray()
|
||||
End Using
|
||||
|
||||
Dim oXml = Text.Encoding.UTF8.GetString(oArray)
|
||||
oResponseBody = oXml
|
||||
Return oResponseBody
|
||||
Return oXMLDocument
|
||||
End Function
|
||||
|
||||
Private Function ApplyItemFiltersForExport(pDocument As Entities.ExportDocument, pTemplate As Template, pMandator As Mandator, oResponseBody As String) As String
|
||||
Dim oDoc As New XmlDocument()
|
||||
oDoc.LoadXml(oResponseBody)
|
||||
Private Function ApplyItemFiltersForExport(pDocument As ExportDocument, pTemplate As Template, pMandator As Mandator, oXMLDocument As XmlDocument) As XmlDocument
|
||||
Dim oTableNames = pDocument.Schema.Tables.
|
||||
Select(Function(table) table.Name).
|
||||
ToList()
|
||||
Dim oFilters = Filters.Items.
|
||||
Where(Function(filter) oTableNames.Contains(filter.TableName)).
|
||||
ToList()
|
||||
|
||||
'TODO: Load filters and apply
|
||||
For Each oFilter As FilterConfigItem In oFilters
|
||||
Dim oTableName = oFilter.TableName
|
||||
|
||||
Dim oArray As Byte()
|
||||
Using oStream As New IO.MemoryStream
|
||||
oDoc.Save(oStream)
|
||||
oArray = oStream.ToArray()
|
||||
End Using
|
||||
If String.IsNullOrEmpty(oFilter.SQLCommand) Then
|
||||
Logger.Warn("SQL Command for filter is empty. Continuing.")
|
||||
Continue For
|
||||
End If
|
||||
|
||||
Dim oXml = Text.Encoding.UTF8.GetString(oArray)
|
||||
oResponseBody = oXml
|
||||
Return oResponseBody
|
||||
Dim oSQLResult = Database.GetDatatable(oFilter.SQLCommand)
|
||||
|
||||
If oSQLResult Is Nothing Then
|
||||
Logger.Warn("SQL Command for filter returned nothing: {0}. Continuing.", oFilter.SQLCommand)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
Dim oResultList = oSQLResult.AsEnumerable.
|
||||
Select(Of String)(Function(row) row.Item(0)).
|
||||
ToList()
|
||||
|
||||
Dim oNodes = oXMLDocument.SelectNodes($"//{oTableName}")
|
||||
|
||||
For Each oNode As XmlNode In oNodes
|
||||
Dim oSubNode = oNode.SelectSingleNode($"//{oFilter.ColumnName}")
|
||||
|
||||
If oSubNode IsNot Nothing AndAlso oResultList.Contains(oSubNode.InnerText) Then
|
||||
oNode.ParentNode.RemoveChild(oNode)
|
||||
'oDoc.RemoveChild(oNode)
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
|
||||
Return oXMLDocument
|
||||
End Function
|
||||
#End Region
|
||||
|
||||
|
||||
Reference in New Issue
Block a user