Add logging for ApplyItemFiltersForExport, fix xpath bug

This commit is contained in:
Jonathan Jenne 2022-07-04 12:54:37 +02:00
parent dc14c80d59
commit 73bc1517f3

View File

@ -336,8 +336,6 @@ Namespace Winline
Logger.Debug("Applying Item Functions")
oDoc = ApplyItemFunctionsForExport(pDocument, pTemplate, pMandator, oDoc)
'TODO: Load filters and apply
Dim oXml = ConvertDocumentToString(oDoc)
' Webservice
@ -444,14 +442,20 @@ Namespace Winline
Where(Function(filter) oTableNames.Contains(filter.TableName)).
ToList()
Logger.Info("Applying [{0}] filters before exporting.", oFilters.Count)
For Each oFilter As FilterConfigItem In oFilters
Dim oTableName = oFilter.TableName
Logger.Debug("Applying filter for Table [{0}]", oTableName)
If String.IsNullOrEmpty(oFilter.SQLCommand) Then
Logger.Warn("SQL Command for filter is empty. Continuing.")
Continue For
End If
Logger.Debug("Executing SQL Command: [{0}]", oFilter.SQLCommand)
Dim oSQLResult = Database.GetDatatable(oFilter.SQLCommand)
If oSQLResult Is Nothing Then
@ -460,18 +464,34 @@ Namespace Winline
End If
Dim oResultList = oSQLResult.AsEnumerable.
Select(Of String)(Function(row) row.Item(0)).
Select(Function(row) row.ItemEx(0, String.Empty).Trim).
ToList()
Dim oNodes = oXMLDocument.SelectNodes($"//{oTableName}")
Logger.Debug("Filterlist contains [{0}] items", oResultList.Count)
For Each oNode As XmlNode In oNodes
Dim oSubNode = oNode.SelectSingleNode($"//{oFilter.ColumnName}")
Dim oTableNodes = oXMLDocument.SelectNodes($"//{oTableName}")
If oSubNode IsNot Nothing AndAlso oResultList.Contains(oSubNode.InnerText) Then
oNode.ParentNode.RemoveChild(oNode)
'oDoc.RemoveChild(oNode)
Logger.Debug("Table contains [{0}] elements", oTableNodes.Count)
For Each oElementNode As XmlNode In oTableNodes
Dim oPath As String = $"./{oFilter.ColumnName}"
Dim oSubNode = oElementNode.SelectSingleNode(oPath)
If oSubNode Is Nothing Then
Logger.Warn("Column [{0}] was not found in element.", oFilter.ColumnName)
Continue For
End If
Dim oNodeValue = oSubNode.InnerText.Trim
Logger.Debug("Element Value is [{0}]", oNodeValue)
If Not oResultList.Contains(oNodeValue) Then
Logger.Warn("Element for Column [{0}] was not found in filterlist.", oFilter.ColumnName)
Continue For
End If
Logger.Info("Removing node [{0}] containing value [{1}]", oPath, oNodeValue)
oElementNode.ParentNode.RemoveChild(oElementNode)
Next
Next