Interfaces/Jobs: add new method FilterPropertyMap

This commit is contained in:
Jonathan Jenne 2023-02-28 13:49:16 +01:00
parent 214edf22a5
commit a80b943dc5
2 changed files with 14 additions and 15 deletions

View File

@ -5,6 +5,7 @@ Imports System.Xml.XPath
Imports System.Xml.Xsl Imports System.Xml.Xsl
Imports DigitalData.Modules.Interfaces.Exceptions Imports DigitalData.Modules.Interfaces.Exceptions
Imports DigitalData.Modules.Interfaces.ZUGFeRD Imports DigitalData.Modules.Interfaces.ZUGFeRD
Imports DigitalData.Modules.Interfaces.ZUGFeRDInterface
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports GdPicture14 Imports GdPicture14
@ -101,6 +102,17 @@ Public Class ZUGFeRDInterface
AllowedFilenames = oAllowedFilenames AllowedFilenames = oAllowedFilenames
End Sub End Sub
Public Function FilterPropertyMap(pPropertyMap As Dictionary(Of String, XmlItemProperty), pSpecification As String) As Dictionary(Of String, XmlItemProperty)
If pSpecification = ZUGFERD_SPEC_10 Then
Return pPropertyMap.
Where(Function(kv) kv.Value.Specification = pSpecification Or kv.Value.Specification = ZUGFERD_SPEC_DEFAULT).
ToDictionary(Function(kv) kv.Key, Function(kv) kv.Value)
Else
Return pPropertyMap.
Where(Function(kv) kv.Value.Specification = pSpecification).
ToDictionary(Function(kv) kv.Key, Function(kv) kv.Value)
End If
End Function
''' <summary> ''' <summary>
''' Validates a ZUGFeRD File and extracts the XML Document from it ''' Validates a ZUGFeRD File and extracts the XML Document from it

View File

@ -299,7 +299,8 @@ Public Class ImportZUGFeRDFiles
' Check the document against the configured property map and return: ' Check the document against the configured property map and return:
' - a List of valid properties ' - a List of valid properties
' - a List of missing properties ' - a List of missing properties
Dim oPropertyMap = GetPropertyMapFor(oArgs, oDocument.Specification)
Dim oPropertyMap = _zugferd.FilterPropertyMap(oArgs.PropertyMap, oDocument.Specification)
Dim oCheckResult = _zugferd.PropertyValues.CheckPropertyValues(oDocument.SchemaObject, oPropertyMap, oMessageId) Dim oCheckResult = _zugferd.PropertyValues.CheckPropertyValues(oDocument.SchemaObject, oPropertyMap, oMessageId)
_logger.Info("Properties checked: [{0}] missing properties / [{1}] valid properties found.", oCheckResult.MissingProperties.Count, oCheckResult.ValidProperties.Count) _logger.Info("Properties checked: [{0}] missing properties / [{1}] valid properties found.", oCheckResult.MissingProperties.Count, oCheckResult.ValidProperties.Count)
@ -619,20 +620,6 @@ Public Class ImportZUGFeRDFiles
_firebird.ExecuteNonQueryWithConnection(oCommand, pConnections.FirebirdConnection, Firebird.TransactionMode.ExternalTransaction, pConnections.FirebirdTransaction) _firebird.ExecuteNonQueryWithConnection(oCommand, pConnections.FirebirdConnection, Firebird.TransactionMode.ExternalTransaction, pConnections.FirebirdTransaction)
End Sub End Sub
Private Function GetPropertyMapFor(pWorkerArgs As WorkerArgs, pSpecification As String) As Dictionary(Of String, XmlItemProperty)
Dim oPropertyMap = DoGetPropertyMapFor(pWorkerArgs, pSpecification)
_logger.Debug("Found [{0}] Properties for Specification [{1}].", oPropertyMap.Count, pSpecification)
' If no properties were found, fall back to the default specification before giving up
If oPropertyMap.Count = 0 Then
_logger.Warn("No Properties found for Specification [{0}]. Loading default property map!", pSpecification)
Return DoGetPropertyMapFor(pWorkerArgs, ZUGFeRDInterface.ZUGFERD_SPEC_DEFAULT)
End If
Return oPropertyMap
End Function
Private Function DoGetPropertyMapFor(pWorkerArgs As WorkerArgs, pSpecification As String) As Dictionary(Of String, XmlItemProperty) Private Function DoGetPropertyMapFor(pWorkerArgs As WorkerArgs, pSpecification As String) As Dictionary(Of String, XmlItemProperty)
Return pWorkerArgs.PropertyMap. Return pWorkerArgs.PropertyMap.
Where(Function(kv) kv.Value.Specification = pSpecification). Where(Function(kv) kv.Value.Specification = pSpecification).