From 951c9d91222ebcf67a863fdcefbc1c147de515c5 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Fri, 8 Dec 2023 10:21:43 +0100 Subject: [PATCH] finalize --- .../Jobs/CertificateDocumentJob.vb | 36 +++++++++++++++---- .../Models/EnvelopeModel.vb | 4 +-- .../Models/HistoryModel.vb | 13 +++++++ .../Services/ActionService.vb | 6 ++++ 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/EnvelopeGenerator.Common/Jobs/CertificateDocumentJob.vb b/EnvelopeGenerator.Common/Jobs/CertificateDocumentJob.vb index 8fe94032..04d5ae75 100644 --- a/EnvelopeGenerator.Common/Jobs/CertificateDocumentJob.vb +++ b/EnvelopeGenerator.Common/Jobs/CertificateDocumentJob.vb @@ -28,6 +28,8 @@ Namespace Jobs Private Database As MSSQLServer Private Config As DbConfig + Private ActionService As ActionService + Private PDFBurner As PDFBurner Private Class EnvelopeData @@ -43,6 +45,9 @@ Namespace Jobs Logger = LogConfig.GetLogger() Try + InitializeModels() + InitializeServices() + Logger.Debug("Loading GdViewer..") GdViewer = New GdViewer() LicenseManager.RegisterKEY(oGdPictureKey) @@ -78,17 +83,33 @@ Namespace Jobs If oEnvelopeData Is Nothing Then Logger.Warn("EnvelopeData could not be loaded for Envelope [{0}]!", oId) + Throw New ArgumentNullException("EnvelopeData") + End If + + If GenerateFinalPDF(oEnvelopeData) = False Then + Logger.Warn("Document could not be finalized!") + Throw New ApplicationException("Document could not be finalized") End If - 'GenerateFinalPDF(oEnvelopeData) - 'Dim oReport As Byte() = Await GenerateReportPdf(oId) - 'MergeDocuments() + ' Dim oReport As Byte() = Await GenerateReportPdf(oId) + ' MergeDocuments() - Logger.Info("Envelope finialized!") + Dim oEnvelope = EnvelopeModel.GetById(oId) + If oEnvelope Is Nothing Then + Logger.Warn("Envelope could not loaded!") + Throw New ApplicationException("Envelope could not loaded!") + End If + + If ActionService.FinalizeEnvelope(oEnvelope) = False Then + Logger.Warn("Envelope could not be finalized!") + Throw New ApplicationException("Envelope could not be finalized") + End If + + Logger.Info("Envelope finalized!") Next - Logger.Debug("Completed job {0}", JobId) + Logger.Info("Completed job {0} successfully!", JobId) Catch ex As Exception Logger.Warn("Certificate Document job failed!") @@ -119,7 +140,6 @@ Namespace Jobs End Using End Using End Using - End Function Private Function GenerateFinalPDF(pData As EnvelopeData) As Boolean @@ -213,6 +233,10 @@ Namespace Jobs } End Function + Private Sub InitializeServices() + Dim oState = GetState() + ActionService = New ActionService(oState) + End Sub Private Sub InitializeModels() Dim oState = GetState() diff --git a/EnvelopeGenerator.Common/Models/EnvelopeModel.vb b/EnvelopeGenerator.Common/Models/EnvelopeModel.vb index 9b46f907..32f34289 100644 --- a/EnvelopeGenerator.Common/Models/EnvelopeModel.vb +++ b/EnvelopeGenerator.Common/Models/EnvelopeModel.vb @@ -60,9 +60,9 @@ Public Class EnvelopeModel End Try End Function - Public Function GetById(pEnvelopeId As String) As Envelope + Public Function GetById(pEnvelopeId As Integer) As Envelope Try - Dim oSql = $"SELECT * FROM [dbo].[TBSIG_ENVELOPE] WHERE GUID = '{pEnvelopeId}'" + Dim oSql = $"SELECT * FROM [dbo].[TBSIG_ENVELOPE] WHERE GUID = {pEnvelopeId}" Dim oTable = Database.GetDatatable(oSql) Return ToEnvelope(oTable) diff --git a/EnvelopeGenerator.Common/Models/HistoryModel.vb b/EnvelopeGenerator.Common/Models/HistoryModel.vb index 892de2ce..1d36a3ff 100644 --- a/EnvelopeGenerator.Common/Models/HistoryModel.vb +++ b/EnvelopeGenerator.Common/Models/HistoryModel.vb @@ -26,6 +26,19 @@ Public Class HistoryModel ToList() End Function + Public Function HasReceiverSigned(pEnvelopeId As Integer, pReceiverId As Integer) As Boolean + Dim oEnvelopeSigned As Integer = Constants.EnvelopeStatus.DocumentSigned + Dim oSql = $"SELECT COUNT(T.GUID) + FROM TBSIG_ENVELOPE_HISTORY T + JOIN TBSIG_RECEIVER T2 ON T.USER_REFERENCE = T2.EMAIL_ADDRESS + WHERE T.STATUS = {oEnvelopeSigned} AND + T.ENVELOPE_ID = {pEnvelopeId} AND + T2.GUID = {pReceiverId}" + Dim oRowCount As Integer = Database.GetScalarValue(oSql) + + Return oRowCount > 0 + End Function + Public Function Insert(pHistory As EnvelopeHistoryEntry) As Boolean Try Dim oSql = "INSERT INTO [dbo].[TBSIG_ENVELOPE_HISTORY] " diff --git a/EnvelopeGenerator.Common/Services/ActionService.vb b/EnvelopeGenerator.Common/Services/ActionService.vb index bbc90626..9ee5d0e7 100644 --- a/EnvelopeGenerator.Common/Services/ActionService.vb +++ b/EnvelopeGenerator.Common/Services/ActionService.vb @@ -70,6 +70,12 @@ Public Class ActionService Return EmailService.SendSignedEmail(pEnvelope, pReceiver) End Function + Public Function FinalizeEnvelope(pEnvelope As Envelope) As Boolean + If HistoryService.SetEnvelopeStatus(pEnvelope, Constants.EnvelopeStatus.EnvelopeArchived, "System") = False Then + Return False + End If + Return True + End Function End Class \ No newline at end of file