ImportZUGFeRD: fix shti

This commit is contained in:
Jonathan Jenne 2019-05-10 17:19:45 +02:00
parent 2e19d878e0
commit cc9ab1b0b0
3 changed files with 46 additions and 13 deletions

View File

@ -163,11 +163,15 @@ Public Class ThreadRunner
Dim tableName = row.Item("TABLE_NAME") Dim tableName = row.Item("TABLE_NAME")
Dim description = row.Item("DESCRIPTION") Dim description = row.Item("DESCRIPTION")
Dim isRequired = row.Item("IS_REQUIRED") Dim isRequired = row.Item("IS_REQUIRED")
Dim isGrouped = row.Item("IS_GROUPED")
Dim groupScope = row.Item("GROUP_SCOPE")
args.PropertyMap.Add(xmlPath, New XmlItemProperty() With { args.PropertyMap.Add(xmlPath, New XmlItemProperty() With {
.Description = description, .Description = description,
.TableName = tableName, .TableName = tableName,
.IsRequired = isRequired .IsRequired = isRequired,
.IsGrouped = isGrouped,
.GroupScope = groupScope
}) })
Next Next

View File

@ -300,13 +300,15 @@ Public Class ImportZUGFeRDFiles
' Iterate through groups to get group scope and group items ' Iterate through groups to get group scope and group items
For Each oGroup In oGroupedProperties For Each oGroup In oGroupedProperties
Dim oGroupScope = oGroup.Key Dim oGroupScope As String = oGroup.Key
Dim oPropertyList As New Dictionary(Of XmlItemProperty, List(Of Object)) Dim oPropertyList As New Dictionary(Of XmlItemProperty, List(Of Object))
Dim oRowCount = 0 Dim oRowCount = 0
_logger.Debug("Fetching Property values for group {0}.", oGroupScope)
' get properties as a nested object, see `oPropertyList` ' get properties as a nested object, see `oPropertyList`
For Each oProperty As KeyValuePair(Of String, XmlItemProperty) In oGroup For Each oProperty As KeyValuePair(Of String, XmlItemProperty) In oGroup
Dim oPropertyValues As List(Of Object) = PropertyValues.GetPropValues(oDocument, oProperty.Key) Dim oPropertyValues As List(Of Object) = PropertyValues.GetPropValue(oDocument, oProperty.Key)
oPropertyList.Add(oProperty.Value, oPropertyValues) oPropertyList.Add(oProperty.Value, oPropertyValues)
@ -316,6 +318,8 @@ Public Class ImportZUGFeRDFiles
End If End If
Next Next
_logger.Debug("Done Fetching Property values.")
' Structure of oPropertyList ' Structure of oPropertyList
' [ # Propertyname # Row 1 # Row 2 ' [ # Propertyname # Row 1 # Row 2
' PositionsMenge: [BilledQuantity1, BilledQuantity2, ...], ' PositionsMenge: [BilledQuantity1, BilledQuantity2, ...],
@ -323,23 +327,39 @@ Public Class ImportZUGFeRDFiles
' ... ' ...
' ] ' ]
For oRowIndex = 0 To oRowCount - 1 For oRowIndex = 0 To oRowCount - 1
_logger.Debug("Processing row {0}", oRowIndex)
For Each oColumn As KeyValuePair(Of XmlItemProperty, List(Of Object)) In oPropertyList For Each oColumn As KeyValuePair(Of XmlItemProperty, List(Of Object)) In oPropertyList
Dim oTableName As String = oColumn.Key.TableName Dim oTableName As String = oColumn.Key.TableName
Dim oPropertyDescription As String = oColumn.Key.Description Dim oPropertyDescription As String = oColumn.Key.Description
Dim oPropertyValue = oColumn.Value.Item(oRowIndex) Dim oPropertyValue = oColumn.Value.Item(oRowIndex)
Dim oRowCounter = oRowIndex + 1 Dim oRowCounter = oRowIndex + 1
If String.IsNullOrEmpty(oPropertyValue) Then _logger.Debug("Processing property {0}.", oPropertyDescription)
If TypeOf oPropertyValue Is List(Of Object) Then
Select Case oPropertyValue.Count
Case 0
oPropertyValue = String.Empty
Case Else
Dim oList As List(Of Object) = DirectCast(oPropertyValue, List(Of Object))
oPropertyValue = oList.Item(0)
End Select
End If
If IsNothing(oPropertyValue) OrElse String.IsNullOrEmpty(oPropertyValue) Then
If oColumn.Key.IsRequired Then If oColumn.Key.IsRequired Then
_logger.Warn("Property {0} is empty or not found. Continuing with Empty String.", oPropertyDescription) _logger.Warn("Property {0} is empty or not found but was required. Continuing with Empty String.", oPropertyDescription)
oMissingProperties.Add(oPropertyDescription) oMissingProperties.Add(oPropertyDescription)
Else Else
_logger.Warn("Property {0} is empty or not found. Continuing with Empty String.", oPropertyDescription) _logger.Warn("Property {0} is empty or not found. Continuing with Empty String.", oPropertyDescription)
End If End If
oPropertyDescription = String.Empty oPropertyValue = String.Empty
End If End If
_logger.Debug("Property {0} has value {1}", oPropertyDescription, oPropertyValue)
Dim oCommand = $"INSERT INTO {oTableName} (REFERENCE_GUID, ITEM_DESCRIPTION, ITEM_VALUE, GROUP_COUNTER) VALUES ('{oFileGroupId}', '{oPropertyDescription}', '{oPropertyValue}', {oRowCounter})" Dim oCommand = $"INSERT INTO {oTableName} (REFERENCE_GUID, ITEM_DESCRIPTION, ITEM_VALUE, GROUP_COUNTER) VALUES ('{oFileGroupId}', '{oPropertyDescription}', '{oPropertyValue}', {oRowCounter})"
_logger.Debug("Mapping Property {0} to value {1}. Will be inserted into table {2} with RowCounter {3}", oPropertyDescription, oPropertyValue, oTableName, oRowCounter) _logger.Debug("Mapping Property {0} to value {1}. Will be inserted into table {2} with RowCounter {3}", oPropertyDescription, oPropertyValue, oTableName, oRowCounter)
@ -360,12 +380,21 @@ Public Class ImportZUGFeRDFiles
' Iterate through default properties ' Iterate through default properties
For Each Item As KeyValuePair(Of String, XmlItemProperty) In oDefaultProperties For Each Item As KeyValuePair(Of String, XmlItemProperty) In oDefaultProperties
Dim oPropertyValueList As List(Of Object) = PropertyValues.GetPropValue(oDocument, Item.Key) Dim oPropertyValueList As List(Of Object) = PropertyValues.GetPropValue(oDocument, Item.Key)
Dim oPropertyValue = oPropertyValueList.
DefaultIfEmpty(New List(Of Object) From {Nothing}).
First()
Dim oPropertyDescription As String = Item.Value.Description Dim oPropertyDescription As String = Item.Value.Description
Dim oPropertyValue As Object = Nothing
If String.IsNullOrEmpty(oPropertyValue) Then If IsNothing(oPropertyValueList) Then
oPropertyValue = Nothing
ElseIf TypeOf oPropertyValueList Is List(Of Object) Then
Select Case oPropertyValueList.Count
Case 0
oPropertyValue = Nothing
Case Else
oPropertyValue = oPropertyValueList.First()
End Select
End If
If IsNothing(oPropertyValue) OrElse String.IsNullOrEmpty(oPropertyValue) Then
If Item.Value.IsRequired Then If Item.Value.IsRequired Then
_logger.Warn("Property {0} is empty but marked as required! Skipping.", oPropertyDescription) _logger.Warn("Property {0} is empty but marked as required! Skipping.", oPropertyDescription)
oMissingProperties.Add(oPropertyDescription) oMissingProperties.Add(oPropertyDescription)

View File

@ -10,7 +10,7 @@ Public Class PropertyValues
Dim oNameParts As String() = PropertyName.Split("."c) Dim oNameParts As String() = PropertyName.Split("."c)
If IsNothing(Obj) Then If IsNothing(Obj) Then
Return Nothing Return New List(Of Object)
End If End If
If oNameParts.Length = 1 Then If oNameParts.Length = 1 Then
@ -31,11 +31,11 @@ Public Class PropertyValues
Dim oInfo As PropertyInfo = oType.GetProperty(oPartName) Dim oInfo As PropertyInfo = oType.GetProperty(oPartName)
If IsNothing(oInfo) Then If IsNothing(oInfo) Then
Return Nothing Return New List(Of Object)
End If End If
If IsNothing(oInfo.GetValue(Obj, Nothing)) Then If IsNothing(oInfo.GetValue(Obj, Nothing)) Then
Return Nothing Return New List(Of Object)
End If End If
Obj = oInfo.GetValue(Obj, Nothing) Obj = oInfo.GetValue(Obj, Nothing)