From 466d0a3a7aa0497c2fa1b0e8898ed330fc0d3390 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 10 Mar 2026 04:07:14 +0100 Subject: [PATCH] Refactor envelope and annotation data retrieval logic Add private helper functions ReadEnvelope and LoadAnnotationDataForEnvelope to centralize retrieval of envelope byte data and annotation JSON from the database. Update PDF annotation burning logic to use these helpers, improving code reuse and testability. --- .../FinalizeDocument/FinalizeDocumentJob.vb | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/EnvelopeGenerator.CommonServices/Jobs/FinalizeDocument/FinalizeDocumentJob.vb b/EnvelopeGenerator.CommonServices/Jobs/FinalizeDocument/FinalizeDocumentJob.vb index cfd2af5e..c921b4df 100644 --- a/EnvelopeGenerator.CommonServices/Jobs/FinalizeDocument/FinalizeDocumentJob.vb +++ b/EnvelopeGenerator.CommonServices/Jobs/FinalizeDocument/FinalizeDocumentJob.vb @@ -230,6 +230,29 @@ Namespace Jobs Return Task.FromResult(True) End Function + +#Region "From BBTests" + Private Function ReadEnvelope(pEnvID As Integer) As Byte() + Dim strSql As String = "Select [BYTE_DATA] from [TBSIG_ENVELOPE_DOCUMENT] WHERE ENVELOPE_ID = " & pEnvID + Dim obyteDB = Database.GetScalarValue(strSql) + If Not IsDBNull(obyteDB) Then + Dim fileData As Byte() = DirectCast(Database.GetScalarValue(strSql), Byte()) + If fileData IsNot Nothing Then + Return fileData + End If + End If + + Throw New InvalidOperationException($"Byte data is null. Envelope ID: {pEnvID}") + + End Function + + Private Function LoadAnnotationDataForEnvelope(pEnvID As Integer) As DataTable + Dim oSql = $"SELECT VALUE FROM [TBSIG_DOCUMENT_STATUS] WHERE ENVELOPE_ID = {pEnvID}" + Return Database.GetDatatable(oSql) + + End Function +#End Region + Private Sub Update_File_DB(pFilePath As String, pEnvelopeID As Long) Dim SqlCom As SqlCommand Dim imageData As Byte() @@ -418,7 +441,18 @@ Namespace Jobs End Try End If - Return PDFBurner.BurnAnnotsToPDF(oInputDocumentBuffer, oAnnotations, pEnvelopeData.EnvelopeId) +#Region "From BBTests" + Dim oTable = LoadAnnotationDataForEnvelope(pEnvelopeId) + Dim oJsonList = oTable.Rows. + Cast(Of DataRow). + Select(Function(r As DataRow) r.Item("VALUE").ToString()). + ToList() + + Dim oBuffer As Byte() = ReadEnvelope(pEnvelopeId) + +#End Region + + Return PDFBurner.BurnAnnotsToPDF(oBuffer, oJsonList, pEnvelopeId) End Function Private Function GetEnvelopeData(pEnvelopeId As Integer) As EnvelopeData