better handling of invalid zugferd files
This commit is contained in:
parent
90cd63c484
commit
eacf8e2743
@ -8,6 +8,7 @@ Imports System.Text.RegularExpressions
|
|||||||
Imports System.Xml
|
Imports System.Xml
|
||||||
Imports DigitalData.Modules.Database
|
Imports DigitalData.Modules.Database
|
||||||
Imports DigitalData.Modules.Interfaces
|
Imports DigitalData.Modules.Interfaces
|
||||||
|
Imports DigitalData.Modules.Interfaces.Exceptions
|
||||||
Imports DigitalData.Modules.Jobs.Exceptions
|
Imports DigitalData.Modules.Jobs.Exceptions
|
||||||
Imports DigitalData.Modules.Logging
|
Imports DigitalData.Modules.Logging
|
||||||
Imports FirebirdSql.Data.FirebirdClient
|
Imports FirebirdSql.Data.FirebirdClient
|
||||||
@ -260,10 +261,23 @@ Public Class ImportZUGFeRDFiles
|
|||||||
|
|
||||||
Try
|
Try
|
||||||
oDocument = _zugferd.ExtractZUGFeRDFile(oFile.FullName)
|
oDocument = _zugferd.ExtractZUGFeRDFile(oFile.FullName)
|
||||||
Catch ex As Exception
|
Catch ex As ZUGFeRDExecption
|
||||||
_logger.Warn("File is not a valid ZUGFeRD document! Skipping.")
|
Select Case ex.ErrorType
|
||||||
oFileAttachmentFiles.Add(oFile)
|
Case ZUGFeRDInterface.ErrorType.NoZugferd
|
||||||
Continue For
|
_logger.Warn("File is not a valid ZUGFeRD document! Skipping.")
|
||||||
|
oFileAttachmentFiles.Add(oFile)
|
||||||
|
Continue For
|
||||||
|
|
||||||
|
Case ZUGFeRDInterface.ErrorType.NoValidZugferd
|
||||||
|
_logger.Warn("File is an Incorrectly formatted ZUGFeRD document!")
|
||||||
|
Throw New InvalidFerdException()
|
||||||
|
|
||||||
|
Case Else
|
||||||
|
_logger.Warn("Unexpected Error occurred while extracting ZUGFeRD Information from file {0}", oFile.FullName)
|
||||||
|
Throw ex
|
||||||
|
End Select
|
||||||
|
|
||||||
|
|
||||||
End Try
|
End Try
|
||||||
|
|
||||||
oMD5CheckSum = CreateMD5(oFile.FullName)
|
oMD5CheckSum = CreateMD5(oFile.FullName)
|
||||||
@ -482,6 +496,20 @@ Public Class ImportZUGFeRDFiles
|
|||||||
Dim oBody = "<p>The invoice attached to your email has already been processed in our system.</p>"
|
Dim oBody = "<p>The invoice attached to your email has already been processed in our system.</p>"
|
||||||
Dim oEmailData = MoveAndRenameEmailToRejected(args, oFileGroupId)
|
Dim oEmailData = MoveAndRenameEmailToRejected(args, oFileGroupId)
|
||||||
AddToEmailQueue(oFileGroupId, oBody, oEmailData)
|
AddToEmailQueue(oFileGroupId, oBody, oEmailData)
|
||||||
|
|
||||||
|
Catch ex As InvalidFerdException
|
||||||
|
_logger.Error(ex)
|
||||||
|
|
||||||
|
oMoveDirectory = args.ErrorDirectory
|
||||||
|
|
||||||
|
Dim oBody = """
|
||||||
|
<p>Your email contained a ZUGFeRD document but it was incorrectly formatted.</p>
|
||||||
|
<p>Possible reasons include:<ul>
|
||||||
|
<li>Amount value has incorrect format (25,01 instead of 25.01)</li>
|
||||||
|
</ul></p>
|
||||||
|
"""
|
||||||
|
Dim oEmailData = MoveAndRenameEmailToRejected(args, oFileGroupId)
|
||||||
|
AddToEmailQueue(oFileGroupId, oBody, oEmailData)
|
||||||
Catch ex As TooMuchFerdsException
|
Catch ex As TooMuchFerdsException
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
|
|
||||||
@ -549,7 +577,7 @@ Public Class ImportZUGFeRDFiles
|
|||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
|
|
||||||
_filesystem.MoveTo(oFile.FullName, oFinalMoveDirectory)
|
_filesystem.MoveTo(oFile.FullName, oFinalMoveDirectory)
|
||||||
_logger.Info("Finished processing file {0}", oFile.Name)
|
_logger.Info("Finished processing file {0}", oFile.Name)
|
||||||
_logger.Info("File moved to {0}", oFinalMoveDirectory)
|
_logger.Info("File moved to {0}", oFinalMoveDirectory)
|
||||||
Next
|
Next
|
||||||
|
|||||||
@ -21,6 +21,14 @@ Public Class Exceptions
|
|||||||
End Sub
|
End Sub
|
||||||
End Class
|
End Class
|
||||||
|
|
||||||
|
Public Class InvalidFerdException
|
||||||
|
Inherits ApplicationException
|
||||||
|
|
||||||
|
Public Sub New()
|
||||||
|
MyBase.New("ZUGFeRD document found but was not formatted correctly")
|
||||||
|
End Sub
|
||||||
|
End Class
|
||||||
|
|
||||||
Public Class NoFerdsException
|
Public Class NoFerdsException
|
||||||
Inherits ApplicationException
|
Inherits ApplicationException
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,8 @@ Public Class ZUGFeRDInterface
|
|||||||
|
|
||||||
Public Enum ErrorType
|
Public Enum ErrorType
|
||||||
NoValidFile
|
NoValidFile
|
||||||
ExtractionFailed
|
NoZugferd
|
||||||
|
NoValidZugferd
|
||||||
End Enum
|
End Enum
|
||||||
|
|
||||||
Public Sub New(LogConfig As LogConfig)
|
Public Sub New(LogConfig As LogConfig)
|
||||||
@ -33,7 +34,7 @@ Public Class ZUGFeRDInterface
|
|||||||
Dim oXmlDocument = ValidateZUGFeRDFile(Path)
|
Dim oXmlDocument = ValidateZUGFeRDFile(Path)
|
||||||
|
|
||||||
If IsNothing(oXmlDocument) Then
|
If IsNothing(oXmlDocument) Then
|
||||||
Throw New ZUGFeRDExecption(ErrorType.ExtractionFailed, "Datei ist kein gültiges ZUGFeRD Format.")
|
Throw New ZUGFeRDExecption(ErrorType.NoZugferd, "Datei ist keine ZUGFeRD Datei.")
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Return SerializeZUGFeRDDocument(oXmlDocument)
|
Return SerializeZUGFeRDDocument(oXmlDocument)
|
||||||
@ -70,7 +71,7 @@ Public Class ZUGFeRDInterface
|
|||||||
|
|
||||||
If Not oProcessOutput.ToLower.Contains(ZUGFERD_CONVERTER_SUCCESS_MESSAGE.ToLower) Then
|
If Not oProcessOutput.ToLower.Contains(ZUGFERD_CONVERTER_SUCCESS_MESSAGE.ToLower) Then
|
||||||
_logger.Warn("File {0} is not a valid ZUGFeRD File!", Path)
|
_logger.Warn("File {0} is not a valid ZUGFeRD File!", Path)
|
||||||
Throw New ZUGFeRDExecption(ErrorType.NoValidFile, "Datei ist kein gültiges ZUGFeRD Format.")
|
Throw New ZUGFeRDExecption(ErrorType.NoZugferd, "Datei ist keine ZUGFeRD Datei.")
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Try
|
Try
|
||||||
@ -93,7 +94,7 @@ Public Class ZUGFeRDInterface
|
|||||||
Return oSerializer.Deserialize(oReader)
|
Return oSerializer.Deserialize(oReader)
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
Throw ex
|
Throw New ZUGFeRDExecption(ErrorType.NoValidZugferd, "Datei ist eine ungültige ZUGFeRD Datei.")
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user