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

@@ -375,59 +375,61 @@ Namespace Winline
For Each oTable In pTemplate.Tables
Logger.Debug("Processing Table [{0}]", oTable.Name)
For Each oItem As Template.Column In oTable.Columns
For Each oColumn As Template.Column In oTable.Columns
Dim oTableName As String = oTable.Name
Dim oItemName As String = oItem.Name
Dim oItemName As String = oColumn.Name
Logger.Debug("Processing item [{0}]", oItemName)
If oItem.Config.Function Is Nothing Then
Continue For
End If
For Each oFunction As FieldConfig.ColumnFunction In oColumn.Config.Functions
Dim oFunction = oItem.Config.Function.Name
Dim oFunctionName = oFunction.Name
Dim oFunctionParams = oFunction.Params
Dim oPath = $"//MESOWebService/{oTableName}/{oItemName}"
Dim oNodes As XmlNodeList = oXMLDocument.SelectNodes(oPath)
Dim oPath = $"//MESOWebService/{oTableName}/{oItemName}"
Dim oNodes As XmlNodeList = oXMLDocument.SelectNodes(oPath)
Logger.Debug("Calling function [{0}] on node [{1}]", oFunction, oPath)
Logger.Debug("Calling function [{0}] on node [{1}]", oFunctionName, oPath)
For Each oNode As XmlNode In oNodes
If oItem.Config.Function.Name = "GLN" Then
Dim oGLN = Winline.TryGetGLN(oNode.InnerText, pMandator)
For Each oNode As XmlNode In oNodes
If oFunctionName = Constants.FUNCTION_GLN Then
Dim oGLN = Winline.TryGetGLN(oNode.InnerText, pMandator)
If oGLN Is Nothing Then
Throw New MissingAttributeException(Constants.FUNCTION_GLN)
End If
oNode.InnerText = oGLN
ElseIf oFunctionName = Constants.FUNCTION_EAN Then
Dim oEAN = Winline.TryGetEAN(oNode.InnerText, pMandator)
If oEAN Is Nothing Then
' 21.04.2022: Relax the EAN Check
' Since it is possible to have articles without a proper EAN in export,
' we dont throw here, but leave the original value in case of a failure.
' Throw New Exceptions.MissingAttributeException("EAN")
Logger.Warn("EAN could not be retrieved for Node {0}. Skipping.", oNode.Name)
Continue For
End If
oNode.InnerText = oEAN
ElseIf oFunctionName = Constants.FUNCTION_SQL Then
Dim oSQL = Patterns.ReplaceForExport(pDocument, pMandator, oFunctionParams)
Dim oValue = Database.GetScalarValue(oSQL)
If oValue Is Nothing Then
Throw New MissingAttributeException(Constants.FUNCTION_SQL)
End If
oNode.InnerText = oValue
If oGLN Is Nothing Then
Throw New MissingAttributeException("GLN")
End If
oNode.InnerText = oGLN
ElseIf oItem.Config.Function.Name = "EAN" Then
Dim oEAN = Winline.TryGetEAN(oNode.InnerText, pMandator)
If oEAN Is Nothing Then
' 21.04.2022: Relax the EAN Check
' Since it is possible to have articles without a proper EAN in export,
' we dont throw here, but leave the original value in case of a failure.
' Throw New Exceptions.MissingAttributeException("EAN")
Logger.Warn("EAN could not be retrieved for Node {0}. Skipping.", oNode.Name)
Continue For
End If
oNode.InnerText = oEAN
ElseIf oItem.Config.Function.Name = "SQL" Then
Dim oSQL = Patterns.ReplaceForExport(pDocument, pMandator, oItem.Config.Function.Params)
Dim oValue = Database.GetScalarValue(oSQL)
If oValue Is Nothing Then
Throw New MissingAttributeException("SQL")
End If
oNode.InnerText = oValue
End If
Next
Next
Next
Next