Jobs/ZUGFeRD: Properly create history entries
This commit is contained in:
parent
81b9fa7f63
commit
de7c92e44e
@ -254,8 +254,8 @@ Public Class ImportZUGFeRDFiles
|
|||||||
oRejected = False
|
oRejected = False
|
||||||
End Try
|
End Try
|
||||||
If oRejected = False Then
|
If oRejected = False Then
|
||||||
HISTORY_ID = oMD5DT.Rows(0).Item("GUID")
|
Dim oHistoryId = oMD5DT.Rows(0).Item("GUID")
|
||||||
Throw New MD5HashException($"There is already an identical invoice! - HistoryID [{HISTORY_ID}]")
|
Throw New MD5HashException($"There is already an identical invoice! - HistoryID [{oHistoryId}]")
|
||||||
Else
|
Else
|
||||||
_logger.Info("ZuGFeRDFile already has been worked, but formerly obviously was rejected!")
|
_logger.Info("ZuGFeRDFile already has been worked, but formerly obviously was rejected!")
|
||||||
End If
|
End If
|
||||||
@ -336,18 +336,20 @@ Public Class ImportZUGFeRDFiles
|
|||||||
'If no errors occurred...
|
'If no errors occurred...
|
||||||
'Log the History
|
'Log the History
|
||||||
If oMD5CheckSum <> String.Empty Then
|
If oMD5CheckSum <> String.Empty Then
|
||||||
Dim oInsertCommand = $"INSERT INTO TBEDM_ZUGFERD_HISTORY_IN (MESSAGE_ID, MD5HASH) VALUES ('{oMessageId}', '{oMD5CheckSum}')"
|
Create_HistoryEntry(oMessageId, oMD5CheckSum, "SUCCESS", oFBTransaction)
|
||||||
_firebird.ExecuteNonQueryWithConnection(oInsertCommand, oFBConnection, Firebird.TransactionMode.ExternalTransaction, oFBTransaction)
|
|
||||||
|
|
||||||
' History ID is only need in case of an error
|
'Dim oInsertCommand = $"INSERT INTO TBEDM_ZUGFERD_HISTORY_IN (MESSAGE_ID, MD5HASH) VALUES ('{oMessageId}', '{oMD5CheckSum}')"
|
||||||
oFBTransaction.Commit()
|
'_firebird.ExecuteNonQueryWithConnection(oInsertCommand, oFBConnection, Firebird.TransactionMode.ExternalTransaction, oFBTransaction)
|
||||||
|
'' History ID is only need in case of an error
|
||||||
Try
|
'oFBTransaction.Commit()
|
||||||
Dim oSQL = $"SELECT MAX(GUID) FROM TBEDM_ZUGFERD_HISTORY_IN WHERE MESSAGE_ID = '{oMessageId}'"
|
'Try
|
||||||
HISTORY_ID = _firebird.GetScalarValue(oSQL)
|
' Dim oSQL = $"SELECT MAX(GUID) FROM TBEDM_ZUGFERD_HISTORY_IN WHERE MESSAGE_ID = '{oMessageId}'"
|
||||||
Catch ex As Exception
|
' HISTORY_ID = _firebird.GetScalarValue(oSQL)
|
||||||
HISTORY_ID = 0
|
'Catch ex As Exception
|
||||||
End Try
|
' HISTORY_ID = 0
|
||||||
|
'End Try
|
||||||
|
Else
|
||||||
|
Create_HistoryEntry(oMessageId, String.Empty, "SUCCESS (with empty MD5Hash)", oFBTransaction)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
oIsSuccess = True
|
oIsSuccess = True
|
||||||
@ -355,10 +357,11 @@ Public Class ImportZUGFeRDFiles
|
|||||||
|
|
||||||
Catch ex As MD5HashException
|
Catch ex As MD5HashException
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
'oFBTransaction.Rollback()
|
|
||||||
|
|
||||||
Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - Already processed (MD5Hash)' WHERE GUID = '{HISTORY_ID}'"
|
'Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = '{oMessage}' WHERE MESSAGE_ID = '{oMessageId}'"
|
||||||
_firebird.ExecuteNonQuery(oSQL)
|
'_firebird.ExecuteNonQuery(oSQL, oFBTransaction)
|
||||||
|
Dim oMessage = "REJECTED - Already processed (MD5Hash)"
|
||||||
|
Update_HistoryEntry(oMessageId, oMD5CheckSum, oMessage, oFBTransaction)
|
||||||
|
|
||||||
Dim oBody = EmailStrings.EMAIL_MD5_ERROR
|
Dim oBody = EmailStrings.EMAIL_MD5_ERROR
|
||||||
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
|
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
|
||||||
@ -367,10 +370,13 @@ Public Class ImportZUGFeRDFiles
|
|||||||
|
|
||||||
Catch ex As InvalidFerdException
|
Catch ex As InvalidFerdException
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
'oFBTransaction.Rollback()
|
|
||||||
|
|
||||||
Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - ZUGFeRD yes but incorrect format' WHERE GUID = '{HISTORY_ID}'"
|
'Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - ZUGFeRD yes but incorrect format' WHERE GUID = '{HISTORY_ID}'"
|
||||||
_firebird.ExecuteNonQuery(oSQL)
|
'_firebird.ExecuteNonQuery(oSQL, oFBTransaction)
|
||||||
|
|
||||||
|
' When InvalidFerdException is thrown, we don't have a MD5Hash yet.
|
||||||
|
' That 's why we set it to String.Empty here.
|
||||||
|
Create_HistoryEntry(oMessageId, String.Empty, "REJECTED - ZUGFeRD yes but incorrect format", oFBTransaction)
|
||||||
|
|
||||||
Dim oBody = EmailStrings.EMAIL_INVALID_DOCUMENT
|
Dim oBody = EmailStrings.EMAIL_INVALID_DOCUMENT
|
||||||
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
|
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
|
||||||
@ -379,10 +385,10 @@ Public Class ImportZUGFeRDFiles
|
|||||||
|
|
||||||
Catch ex As TooMuchFerdsException
|
Catch ex As TooMuchFerdsException
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
'oFBTransaction.Rollback()
|
|
||||||
|
|
||||||
Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - More than one ZUGFeRD-document in email' WHERE GUID = '{HISTORY_ID}'"
|
'Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - More than one ZUGFeRD-document in email' WHERE GUID = '{HISTORY_ID}'"
|
||||||
_firebird.ExecuteNonQuery(oSQL)
|
'_firebird.ExecuteNonQuery(oSQL, oFBTransaction)
|
||||||
|
Create_HistoryEntry(oMessageId, oMD5CheckSum, "REJECTED - More than one ZUGFeRD-document in email", oFBTransaction)
|
||||||
|
|
||||||
Dim oBody = EmailStrings.EMAIL_TOO_MUCH_FERDS
|
Dim oBody = EmailStrings.EMAIL_TOO_MUCH_FERDS
|
||||||
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
|
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
|
||||||
@ -391,10 +397,10 @@ Public Class ImportZUGFeRDFiles
|
|||||||
|
|
||||||
Catch ex As NoFerdsException
|
Catch ex As NoFerdsException
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
'oFBTransaction.Rollback()
|
|
||||||
|
|
||||||
Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - no ZUGFeRD-Document in email' WHERE GUID = '{HISTORY_ID}'"
|
'Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - no ZUGFeRD-Document in email' WHERE GUID = '{HISTORY_ID}'"
|
||||||
_firebird.ExecuteNonQuery(oSQL)
|
'_firebird.ExecuteNonQuery(oSQL, oFBTransaction)
|
||||||
|
Create_HistoryEntry(oMessageId, oMD5CheckSum, "REJECTED - no ZUGFeRD-Document in email", oFBTransaction)
|
||||||
|
|
||||||
Dim oBody = EmailStrings.EMAIL_NO_FERDS
|
Dim oBody = EmailStrings.EMAIL_NO_FERDS
|
||||||
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
|
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
|
||||||
@ -403,14 +409,14 @@ Public Class ImportZUGFeRDFiles
|
|||||||
|
|
||||||
Catch ex As MissingValueException
|
Catch ex As MissingValueException
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
'oFBTransaction.Rollback()
|
|
||||||
|
|
||||||
Dim oMessage As String = ""
|
Dim oMessage As String = ""
|
||||||
For Each prop In oMissingProperties
|
For Each prop In oMissingProperties
|
||||||
oMessage &= $"- {prop}"
|
oMessage &= $"- {prop}"
|
||||||
Next
|
Next
|
||||||
Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - Missing Required Properties: [{oMessage}]' WHERE GUID = '{HISTORY_ID}'"
|
'Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - Missing Required Properties: [{oMessage}]' WHERE GUID = '{HISTORY_ID}'"
|
||||||
_firebird.ExecuteNonQuery(oSQL)
|
'_firebird.ExecuteNonQuery(oSQL, oFBTransaction)
|
||||||
|
Create_HistoryEntry(oMessageId, oMD5CheckSum, $"REJECTED - Missing Required Properties: [{oMessage}]", oFBTransaction)
|
||||||
|
|
||||||
Dim oBody = CreateBodyForMissingProperties(ex.File.Name, oMissingProperties)
|
Dim oBody = CreateBodyForMissingProperties(ex.File.Name, oMissingProperties)
|
||||||
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
|
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
|
||||||
@ -652,4 +658,32 @@ Public Class ImportZUGFeRDFiles
|
|||||||
Return ""
|
Return ""
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
Private Function Create_HistoryEntry(MessageId As String, MD5Checksum As String, Message As String, Transaction As FbTransaction) As Boolean
|
||||||
|
Try
|
||||||
|
Dim oSQL = $"INSERT INTO TBEDM_ZUGFERD_HISTORY_IN (COMMENT, MD5HASH, MESSAGE_ID) VALUES ('{Message}', '{MD5Checksum}', '{MessageId}')"
|
||||||
|
_firebird.ExecuteNonQueryWithConnection(oSQL, Transaction.Connection, Firebird.TransactionMode.ExternalTransaction, Transaction)
|
||||||
|
|
||||||
|
Return True
|
||||||
|
Catch ex As Exception
|
||||||
|
_logger.Warn("History Entry count not be created for message id [{0}] and md5 [{1}]", MessageId, MD5Checksum)
|
||||||
|
_logger.Error(ex)
|
||||||
|
|
||||||
|
Return False
|
||||||
|
End Try
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Function Update_HistoryEntry(MessageId As String, MD5Checksum As String, Message As String, Transaction As FbTransaction) As Boolean
|
||||||
|
Try
|
||||||
|
Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = '{Message}' WHERE MD5HASH = '{MD5Checksum}' AND MESSAGE_ID = '{MessageId}'"
|
||||||
|
_firebird.ExecuteNonQueryWithConnection(oSQL, Transaction.Connection, Firebird.TransactionMode.ExternalTransaction, Transaction)
|
||||||
|
|
||||||
|
Return True
|
||||||
|
Catch ex As Exception
|
||||||
|
_logger.Warn("History Entry count not be updated for message id [{0}] and md5 [{1}]", MessageId, MD5Checksum)
|
||||||
|
_logger.Error(ex)
|
||||||
|
|
||||||
|
Return False
|
||||||
|
End Try
|
||||||
|
End Function
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user