Refactor: remove strict checks and logging in finalization
Removed exception throwing and logging for failed report creation, email sending, and envelope finalization in FinalizeDocumentJob. Now, these methods are called without checking their return values. Also improved exception message for file export to include envelope Id and added null-forgiving operator to _config.ExportPath.
This commit is contained in:
@@ -81,23 +81,18 @@ public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration
|
|||||||
var burnedDocument = pdfBurner!.BurnAnnotsToPDF(envelope.DefaultDocument.ByteData!, annotations, envelope.Id)
|
var burnedDocument = pdfBurner!.BurnAnnotsToPDF(envelope.DefaultDocument.ByteData!, annotations, envelope.Id)
|
||||||
?? throw new ApplicationException("Document could not be finalized");
|
?? throw new ApplicationException("Document could not be finalized");
|
||||||
|
|
||||||
if (!actionService.CreateReport(envelope, cancel))
|
actionService.CreateReport(envelope, cancel);
|
||||||
{
|
|
||||||
logger.LogWarning("Document Report could not be created!");
|
|
||||||
throw new ApplicationException("Document Report could not be created");
|
|
||||||
}
|
|
||||||
|
|
||||||
var report = reportCreator!.CreateReport(envelope);
|
var report = reportCreator!.CreateReport(envelope);
|
||||||
|
|
||||||
var mergedDocument = pdfMerger!.MergeDocuments(burnedDocument, report);
|
var mergedDocument = pdfMerger!.MergeDocuments(burnedDocument, report);
|
||||||
|
|
||||||
var outputDirectoryPath = Path.Combine(_config.ExportPath, _parentFolderUid);
|
var outputDirectoryPath = Path.Combine(_config!.ExportPath, _parentFolderUid);
|
||||||
|
|
||||||
if (!Directory.Exists(outputDirectoryPath))
|
if (!Directory.Exists(outputDirectoryPath))
|
||||||
Directory.CreateDirectory(outputDirectoryPath);
|
Directory.CreateDirectory(outputDirectoryPath);
|
||||||
|
|
||||||
var outputFilePath = Path.Combine(outputDirectoryPath, $"{envelope.Uuid}.pdf");
|
var outputFilePath = Path.Combine(outputDirectoryPath, $"{envelope.Uuid}.pdf");
|
||||||
logger.LogInformation("Output path is [{outputFilePath}]", outputFilePath);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -105,23 +100,15 @@ public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.LogWarning("Could not export final document to disk!");
|
throw new ExportDocumentException("Could not export final document to disk. Envelope Id is " + envelope.Id, ex);
|
||||||
throw new ExportDocumentException("Could not export final document to disk!", ex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var outputFile = await File.ReadAllBytesAsync(outputFilePath, cancel);
|
var outputFile = await File.ReadAllBytesAsync(outputFilePath, cancel);
|
||||||
await envRepo.UpdateAsync(e => e.DocResult = outputFile, e => e.Id == envelope.Id, cancel);
|
await envRepo.UpdateAsync(e => e.DocResult = outputFile, e => e.Id == envelope.Id, cancel);
|
||||||
|
|
||||||
if (!SendFinalEmails(envelope))
|
SendFinalEmails(envelope);
|
||||||
throw new ApplicationException("Final emails could not be sent!");
|
|
||||||
|
|
||||||
logger.LogInformation("Report-mails successfully sent!");
|
actionService?.FinalizeEnvelope(envelope);
|
||||||
|
|
||||||
if (actionService?.FinalizeEnvelope(envelope) == false)
|
|
||||||
{
|
|
||||||
logger.LogWarning("Envelope could not be finalized!");
|
|
||||||
throw new ApplicationException("Envelope could not be finalized");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool SendFinalEmails(Envelope envelope)
|
private bool SendFinalEmails(Envelope envelope)
|
||||||
|
|||||||
Reference in New Issue
Block a user