refactor(EnvelopeGenerator.Common): umbenennen in EnvelopeGenerator.CommonService
This commit is contained in:
177
EnvelopeGenerator.CommonServices/Services/ActionService.vb
Normal file
177
EnvelopeGenerator.CommonServices/Services/ActionService.vb
Normal file
@@ -0,0 +1,177 @@
|
||||
Imports EnvelopeGenerator.Domain.Entities
|
||||
Imports EnvelopeGenerator.Domain.Constants
|
||||
Imports EnvelopeGenerator.CommonServices.My.Resources
|
||||
Imports DigitalData.Modules.Database
|
||||
|
||||
Public Class ActionService
|
||||
Inherits BaseService
|
||||
|
||||
|
||||
Private ReadOnly EmailService As EmailService
|
||||
Private ReadOnly HistoryService As HistoryService
|
||||
|
||||
Private ReadOnly ReceiverModel As ReceiverModel
|
||||
|
||||
Private myDatabase As MSSQLServer
|
||||
|
||||
|
||||
Public Sub New(pState As State, pDD_ECM As MSSQLServer)
|
||||
MyBase.New(pState)
|
||||
myDatabase = pDD_ECM
|
||||
EmailService = New EmailService(pState)
|
||||
HistoryService = New HistoryService(pState)
|
||||
ReceiverModel = New ReceiverModel(pState)
|
||||
End Sub
|
||||
|
||||
Public Function SendEnvelope(pEnvelope As Domain.Entities.Envelope) As Boolean
|
||||
If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.EnvelopeQueued, pEnvelope.User.Email) = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Dim oSendResult = pEnvelope.Receivers.
|
||||
Select(Function(r) EmailService.SendDocumentReceivedEmail(pEnvelope, r)).
|
||||
All(Function(r) r = True)
|
||||
|
||||
If oSendResult = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
Public Function SetStatusDocumentRotationChanged(pEnvelope As Domain.Entities.Envelope) As Boolean
|
||||
If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.DocumentMod_Rotation, pEnvelope.User.Email) = False Then
|
||||
Return False
|
||||
End If
|
||||
Return True
|
||||
End Function
|
||||
Public Function Resend_Receiver(pEnvelope As Domain.Entities.Envelope, pmail As String) As Boolean
|
||||
If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.EnvelopeQueued, pEnvelope.User.Email) = False Then
|
||||
Return False
|
||||
End If
|
||||
Dim oSendResult As Boolean = False
|
||||
For Each oReceiver In pEnvelope.Receivers
|
||||
EmailService.SendDocumentReceivedEmail(pEnvelope, oReceiver)
|
||||
Next
|
||||
Return oSendResult
|
||||
End Function
|
||||
Public Function ResendReceiver(pEnvelope As Domain.Entities.Envelope, pReceiver As Receiver) As Boolean
|
||||
Return EmailService.SendDocumentReceivedEmail(pEnvelope, pReceiver)
|
||||
End Function
|
||||
|
||||
|
||||
Public Function DeleteEnvelope(pEnvelope As Domain.Entities.Envelope, pReason As String) As Boolean
|
||||
Dim oStatus As EnvelopeStatus
|
||||
If pEnvelope.IsAlreadySent Then
|
||||
oStatus = EnvelopeStatus.EnvelopeWithdrawn
|
||||
Else
|
||||
oStatus = EnvelopeStatus.EnvelopeDeleted
|
||||
End If
|
||||
Dim oUpd = $"UPDATE TBSIG_ENVELOPE SET REJECTION_REASON = '{pReason}' WHERE GUID = {pEnvelope.Id}"
|
||||
myDatabase.ExecuteNonQuery(oUpd)
|
||||
If HistoryService.SetEnvelopeStatus(pEnvelope, oStatus, pEnvelope.User.Email) = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Dim oSendResult = pEnvelope.Receivers.
|
||||
Select(Function(r) EmailService.SendEnvelopeDeletedEmail(pEnvelope, r, pReason)).
|
||||
All(Function(r) r = True)
|
||||
|
||||
If oSendResult = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
Public Function API_SendWithdrawn_Mails(pEnvelope As Domain.Entities.Envelope, pReason As String) As Boolean
|
||||
Dim oSendResult As Boolean = False
|
||||
For Each oReceiver As Receiver In pEnvelope.Receivers
|
||||
If EmailService.SendEnvelopeDeletedEmail(pEnvelope, oReceiver, pReason) = False Then
|
||||
Return False
|
||||
End If
|
||||
Next
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function OpenEnvelope(pEnvelope As Domain.Entities.Envelope, pReceiver As Receiver) As Boolean
|
||||
Dim oUserReference = pReceiver.EmailAddress
|
||||
|
||||
If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.DocumentOpened, oUserReference) = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function RequestAccessCode(pEnvelope As Domain.Entities.Envelope, pReceiver As Receiver) As Boolean
|
||||
Dim oUserReference = pReceiver.EmailAddress
|
||||
|
||||
If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.AccessCodeRequested, oUserReference) = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function EnterCorrectAccessCode(pEnvelope As Domain.Entities.Envelope, pReceiver As Receiver) As Boolean
|
||||
Dim oUserReference = pReceiver.EmailAddress
|
||||
|
||||
If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.AccessCodeCorrect, oUserReference) = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function EnterIncorrectAccessCode(pEnvelope As Domain.Entities.Envelope, pReceiver As Receiver) As Boolean
|
||||
Dim oUserReference = pReceiver.EmailAddress
|
||||
|
||||
If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.AccessCodeIncorrect, oUserReference) = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function SignEnvelope(pEnvelope As Domain.Entities.Envelope, pReceiver As Receiver) As Boolean
|
||||
Dim oUserReference = pReceiver.EmailAddress
|
||||
|
||||
If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.DocumentSigned, oUserReference) = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return EmailService.SendSignedEmail(pEnvelope, pReceiver)
|
||||
End Function
|
||||
|
||||
Public Function FinalizeEnvelope(pEnvelope As Domain.Entities.Envelope) As Boolean
|
||||
If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.EnvelopeArchived, "System") = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function CompleteEnvelope(pEnvelope As Domain.Entities.Envelope, pReceiver As Domain.Entities.Receiver) As Boolean ', pAttachment As String
|
||||
If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.MessageCompletionSent, pReceiver.EmailAddress) = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return EmailService.SendDocumentCompletedEmailToReceiver(pEnvelope, pReceiver) ', pAttachment
|
||||
End Function
|
||||
|
||||
Public Function CompleteEnvelope(pEnvelope As Domain.Entities.Envelope) As Boolean ', pAttachment As String
|
||||
If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.MessageCompletionSent, pEnvelope.User.Email) = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return EmailService.SendDocumentCompletedEmailToCreator(pEnvelope) ', pAttachment
|
||||
End Function
|
||||
|
||||
Public Function CreateReport(pEnvelope As Domain.Entities.Envelope) As Boolean
|
||||
If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.EnvelopeReportCreated, "System") = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
End Class
|
||||
10
EnvelopeGenerator.CommonServices/Services/BaseService.vb
Normal file
10
EnvelopeGenerator.CommonServices/Services/BaseService.vb
Normal file
@@ -0,0 +1,10 @@
|
||||
Imports DigitalData.Modules.Base
|
||||
Public Class BaseService
|
||||
Inherits BaseClass
|
||||
|
||||
Friend Property State As State
|
||||
Public Sub New(pState As State)
|
||||
MyBase.New(pState.LogConfig)
|
||||
State = pState
|
||||
End Sub
|
||||
End Class
|
||||
145
EnvelopeGenerator.CommonServices/Services/EmailService.vb
Normal file
145
EnvelopeGenerator.CommonServices/Services/EmailService.vb
Normal file
@@ -0,0 +1,145 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports EnvelopeGenerator.Domain.Entities
|
||||
|
||||
Public Class EmailService
|
||||
Inherits BaseService
|
||||
|
||||
Private ReadOnly EmailModel As EmailModel
|
||||
Private ReadOnly EmailTemplate As TemplateService
|
||||
|
||||
Public Sub New(pState As State)
|
||||
MyBase.New(pState)
|
||||
|
||||
EmailModel = New EmailModel(pState)
|
||||
EmailTemplate = New TemplateService(pState)
|
||||
End Sub
|
||||
|
||||
Public Function SendEnvelopeDeletedEmail(pEnvelope As Envelope, pReceiver As Receiver, pReason As String) As Boolean
|
||||
Logger.Debug("SendEnvelopeDeletedEmail - Creating email data object...")
|
||||
Dim oEmailData As New EmailData(pEnvelope, pReceiver, Domain.Constants.EnvelopeStatus.MessageDeletionSent) With
|
||||
{
|
||||
.SignatureLink = "",
|
||||
.ADDED_WHO_PROCESS = pEnvelope.CURRENT_WORK_APP
|
||||
}
|
||||
|
||||
EmailTemplate.FillEnvelopeDeletedEmailBody(oEmailData, pReason)
|
||||
|
||||
If EmailModel.Insert(oEmailData) = False Then
|
||||
Logger.Error("EMail data could not be inserted.")
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function SendDocumentReceivedEmail(pEnvelope As Envelope, pReceiver As Receiver) As Boolean
|
||||
Logger.Debug("Creating email data object.")
|
||||
Dim oEmailData As New EmailData(pEnvelope, pReceiver, Domain.Constants.EnvelopeStatus.MessageInvitationSent) With
|
||||
{
|
||||
.SignatureLink = Helpers.GetEnvelopeURL(State.DbConfig.SignatureHost, pEnvelope.Uuid, pReceiver.Signature),
|
||||
.ADDED_WHO_PROCESS = pEnvelope.CURRENT_WORK_APP
|
||||
}
|
||||
|
||||
EmailTemplate.FillDocumentReceivedEmailBody(oEmailData)
|
||||
|
||||
If EmailModel.Insert(oEmailData) = False Then
|
||||
Logger.Error("EMail data could not be inserted.")
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function GetReceiverUrl(pEnvelope As Envelope, pReceiver As Receiver) As String
|
||||
Logger.Debug($"State.DbConfig.SignatureHost: {State.DbConfig.SignatureHost}")
|
||||
Logger.Debug($" pEnvelope.Uuid: {pEnvelope.Uuid}")
|
||||
Logger.Debug($" pReceiver.Signature: {pReceiver.Signature}")
|
||||
Dim oEmailData As New EmailData(pEnvelope, pReceiver, Domain.Constants.EnvelopeStatus.MessageInvitationSent) With
|
||||
{
|
||||
.SignatureLink = Helpers.GetEnvelopeURL(State.DbConfig.SignatureHost, pEnvelope.Uuid, pReceiver.Signature),
|
||||
.ADDED_WHO_PROCESS = pEnvelope.CURRENT_WORK_APP
|
||||
}
|
||||
Return oEmailData.SignatureLink
|
||||
End Function
|
||||
|
||||
|
||||
Public Function SendDocumentAccessCodeReceivedEmail(pEnvelope As Envelope, pReceiver As Receiver) As Boolean
|
||||
Logger.Debug("Creating email data object.")
|
||||
Logger.Debug($"State.DbConfig.SignatureHost: {State.DbConfig.SignatureHost}")
|
||||
Logger.Debug($" pEnvelope.Uuid: {pEnvelope.Uuid}")
|
||||
Logger.Debug($" pReceiver.Signature: {pReceiver.Signature}")
|
||||
Dim oEmailData As New EmailData(pEnvelope, pReceiver, Domain.Constants.EnvelopeStatus.MessageAccessCodeSent) With
|
||||
{
|
||||
.SignatureLink = Helpers.GetEnvelopeURL(State.DbConfig.SignatureHost, pEnvelope.Uuid, pReceiver.Signature),
|
||||
.ADDED_WHO_PROCESS = pEnvelope.CURRENT_WORK_APP
|
||||
}
|
||||
|
||||
EmailTemplate.FillDocumentAccessCodeReceivedEmailBody(oEmailData)
|
||||
|
||||
If EmailModel.Insert(oEmailData) = False Then
|
||||
Logger.Error("EMail data could not be inserted.")
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function SendSignedEmail(pEnvelope As Envelope, pReceiver As Receiver) As Boolean
|
||||
Logger.Debug("Creating email data object.")
|
||||
Dim oEmailData = New EmailData(pEnvelope, pReceiver, Domain.Constants.EnvelopeStatus.MessageConfirmationSent) With
|
||||
{
|
||||
.SignatureLink = ""
|
||||
}
|
||||
|
||||
EmailTemplate.FillDocumentSignedEmailBody(oEmailData)
|
||||
|
||||
If EmailModel.Insert(oEmailData) = False Then
|
||||
Logger.Error("EMail data could not be inserted.")
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function SendDocumentCompletedEmailToReceiver(pEnvelope As Envelope, pReceiver As Receiver) As Boolean ', pAttachment As String
|
||||
Logger.Debug("Creating email data object.")
|
||||
Dim oEmailData = New EmailData(pEnvelope, pReceiver, Domain.Constants.EnvelopeStatus.MessageCompletionSent) With
|
||||
{
|
||||
.SignatureLink = "",
|
||||
.ATT1_RELATED_ID = pEnvelope.Id,
|
||||
.ATT1_REL_TYPE = "EnvelopeResult"
|
||||
}
|
||||
' .EmailAttachment = pAttachment,
|
||||
Logger.Debug("Sending mail to receiver: [{0}]", oEmailData.EmailAdress)
|
||||
|
||||
EmailTemplate.FillDocumentCompletedEmailBody(oEmailData)
|
||||
|
||||
If EmailModel.Insert(oEmailData) = False Then
|
||||
Logger.Error("EMail data could not be inserted.")
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function SendDocumentCompletedEmailToCreator(pEnvelope As Envelope) As Boolean ', pAttachment As String
|
||||
Logger.Debug("Creating email data object.")
|
||||
Dim oEmailData = New EmailData(pEnvelope, Domain.Constants.EnvelopeStatus.MessageCompletionSent) With
|
||||
{
|
||||
.SignatureLink = "",
|
||||
.ATT1_RELATED_ID = pEnvelope.Id,
|
||||
.ATT1_REL_TYPE = "EnvelopeResult"
|
||||
}
|
||||
'.EmailAttachment = pAttachment,
|
||||
EmailTemplate.FillDocumentCompletedEmailBody(oEmailData)
|
||||
|
||||
If EmailModel.Insert(oEmailData) = False Then
|
||||
Logger.Error("EMail data could not be inserted.")
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
|
||||
End Class
|
||||
36
EnvelopeGenerator.CommonServices/Services/HistoryService.vb
Normal file
36
EnvelopeGenerator.CommonServices/Services/HistoryService.vb
Normal file
@@ -0,0 +1,36 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports EnvelopeGenerator.Domain.Constants
|
||||
Imports EnvelopeGenerator.Domain.Entities
|
||||
|
||||
Public Class HistoryService
|
||||
Inherits BaseService
|
||||
|
||||
Private ReadOnly EnvelopeModel As EnvelopeModel
|
||||
Private ReadOnly ReceiverModel As ReceiverModel
|
||||
Private ReadOnly HistoryModel As HistoryModel
|
||||
|
||||
Public Sub New(pState As State)
|
||||
MyBase.New(pState)
|
||||
|
||||
EnvelopeModel = New EnvelopeModel(pState)
|
||||
ReceiverModel = New ReceiverModel(pState)
|
||||
HistoryModel = New HistoryModel(pState)
|
||||
End Sub
|
||||
|
||||
Public Function SetEnvelopeStatus(pEnvelope As Envelope, pStatus As EnvelopeStatus, pUserReference As String) As Boolean
|
||||
Dim oResult = HistoryModel.Insert(New EnvelopeHistory() With {
|
||||
.EnvelopeId = pEnvelope.Id,
|
||||
.ActionDate = Now(),
|
||||
.Status = pStatus,
|
||||
.UserReference = pUserReference
|
||||
})
|
||||
|
||||
If oResult = False Then
|
||||
Logger.Warn("Could not set Envelope status to [{0}] for Envelope [{1}].", pStatus.ToString, pEnvelope.Id)
|
||||
Return False
|
||||
End If
|
||||
|
||||
Logger.Debug("Envelope status set to [{0}] for Envelope [{1}].", pStatus.ToString, pEnvelope.Id)
|
||||
Return True
|
||||
End Function
|
||||
End Class
|
||||
90
EnvelopeGenerator.CommonServices/Services/TemplateService.vb
Normal file
90
EnvelopeGenerator.CommonServices/Services/TemplateService.vb
Normal file
@@ -0,0 +1,90 @@
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports EnvelopeGenerator.Domain.Constants
|
||||
|
||||
Public Class TemplateService
|
||||
Inherits BaseService
|
||||
|
||||
Private _replaceDictionary As Dictionary(Of String, String)
|
||||
|
||||
Private ReadOnly DbConfig As DbConfig
|
||||
Private ReadOnly EmailHtmlTemplateModel As EmailTemplateModel
|
||||
|
||||
Public Sub New(pState As State)
|
||||
MyBase.New(pState)
|
||||
|
||||
DbConfig = pState.DbConfig
|
||||
EmailHtmlTemplateModel = New EmailTemplateModel(pState)
|
||||
End Sub
|
||||
|
||||
Private Sub InitDictionary(pEmailData As EmailData, Optional pReason As String = "")
|
||||
Logger.Debug("Initializing dictionary..")
|
||||
|
||||
_replaceDictionary = New Dictionary(Of String, String) From {
|
||||
{"[NAME_RECEIVER]", pEmailData.ReceiverName},
|
||||
{"[NAME_SENDER]", pEmailData.SenderName},
|
||||
{"[NAME_PORTAL]", DbConfig.ExternalProgramName},
|
||||
{"[SIGNATURE_TYPE]", "signieren"},
|
||||
{"[LINK_TO_DOCUMENT]", pEmailData.SignatureLink},
|
||||
{"[LINK_TO_DOCUMENT_TEXT]", $"{pEmailData.SignatureLink.Truncate(40)}.."},
|
||||
{"[DOCUMENT_TITLE]", pEmailData.EnvelopeTitle},
|
||||
{"[MESSAGE]", pEmailData.Message},
|
||||
{"[DOCUMENT_ACCESS_CODE]", pEmailData.ReceiverAccessCode},
|
||||
{"[REASON]", pReason}
|
||||
}
|
||||
End Sub
|
||||
|
||||
Public Sub FillDocumentReceivedEmailBody(pEmailData As EmailData)
|
||||
InitDictionary(pEmailData)
|
||||
Dim oTemplate = EmailHtmlTemplateModel.GetById(EmailTemplateType.DocumentReceived)
|
||||
|
||||
pEmailData.EmailBody = FillTemplate(oTemplate.Body)
|
||||
pEmailData.EmailSubject = FillTemplate(oTemplate.Subject)
|
||||
End Sub
|
||||
|
||||
Public Sub FillEnvelopeDeletedEmailBody(pEmailData As EmailData, pReason As String)
|
||||
InitDictionary(pEmailData, pReason)
|
||||
Dim oTemplate = EmailHtmlTemplateModel.GetById(EmailTemplateType.DocumentDeleted)
|
||||
|
||||
pEmailData.EmailBody = FillTemplate(oTemplate.Body, pReason)
|
||||
pEmailData.EmailSubject = FillTemplate(oTemplate.Subject)
|
||||
End Sub
|
||||
|
||||
Public Sub FillDocumentSignedEmailBody(pEmailData As EmailData)
|
||||
InitDictionary(pEmailData)
|
||||
Dim oTemplate = EmailHtmlTemplateModel.GetById(EmailTemplateType.DocumentSigned)
|
||||
|
||||
pEmailData.EmailBody = FillTemplate(oTemplate.Body)
|
||||
pEmailData.EmailSubject = FillTemplate(oTemplate.Subject)
|
||||
End Sub
|
||||
|
||||
Public Sub FillDocumentCompletedEmailBody(pEmailData As EmailData)
|
||||
InitDictionary(pEmailData)
|
||||
Dim oTemplate = EmailHtmlTemplateModel.GetById(EmailTemplateType.DocumentCompleted)
|
||||
|
||||
pEmailData.EmailBody = FillTemplate(oTemplate.Body)
|
||||
pEmailData.EmailSubject = FillTemplate(oTemplate.Subject)
|
||||
End Sub
|
||||
|
||||
Public Sub FillDocumentAccessCodeReceivedEmailBody(pEmailData As EmailData)
|
||||
InitDictionary(pEmailData)
|
||||
Dim oTemplate = EmailHtmlTemplateModel.GetById(EmailTemplateType.DocumentAccessCodeReceived)
|
||||
|
||||
pEmailData.EmailBody = FillTemplate(oTemplate.Body)
|
||||
pEmailData.EmailSubject = FillTemplate(oTemplate.Subject)
|
||||
End Sub
|
||||
|
||||
Private Function FillTemplate(pTemplate As String, Optional pReason As String = "") As String
|
||||
Dim oText As String = pTemplate
|
||||
|
||||
For Each dictItem As KeyValuePair(Of String, String) In _replaceDictionary
|
||||
If oText.Contains(dictItem.Key) Then
|
||||
|
||||
oText = oText.Replace(dictItem.Key, dictItem.Value)
|
||||
|
||||
End If
|
||||
Next
|
||||
|
||||
Return oText
|
||||
End Function
|
||||
End Class
|
||||
Reference in New Issue
Block a user