Updated `using` directives to include `DigitalData.Core.Exceptions` for enhanced exception handling. Updated the `[Obsolete]` attribute message to reflect PSPDFKit library deprecation. Renamed `cancellationToken` to `cancel` for consistency. Added validation to ensure `PsPdfKitAnnotation` is only supported for the `LegacyWeb` receiver type. Introduced stricter checks for missing or invalid annotation data, throwing `BadRequestException` when necessary. Updated `await next` calls to use the renamed parameter. These changes improve code clarity, enforce stricter validation, and enhance error handling.
51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using DigitalData.Core.Exceptions;
|
|
using EnvelopeGenerator.Application.Common.Dto;
|
|
using EnvelopeGenerator.Application.DocReceiverElements.Commands;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using MediatR;
|
|
|
|
namespace EnvelopeGenerator.Application.DocReceiverElements.Behaviors;
|
|
|
|
/// <summary>
|
|
/// Pipeline behavior that saves annotations.
|
|
/// Executes first in the signing process.
|
|
/// </summary>
|
|
[Obsolete("The PSPDFKit library is deprecated.")]
|
|
public class AnnotationBehavior : IPipelineBehavior<SigningCommand, Unit>
|
|
{
|
|
private readonly IRepository<ElementAnnotation> _repo;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="AnnotationBehavior"/> class.
|
|
/// </summary>
|
|
/// <param name="repository"></param>
|
|
public AnnotationBehavior(IRepository<ElementAnnotation> repository)
|
|
{
|
|
_repo = repository;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="next"></param>
|
|
/// <param name="cancel"></param>
|
|
/// <returns></returns>
|
|
public async Task<Unit> Handle(SigningCommand request, RequestHandlerDelegate<Unit> next, CancellationToken cancel)
|
|
{
|
|
if(request.ReceiverAppType != ReceiverAppType.LegacyWeb)
|
|
if(request.PsPdfKitAnnotation is null)
|
|
return await next(cancel);
|
|
else
|
|
throw new BadRequestException("PsPdfKit Annotation are only supported for the legacy web receiver type.");
|
|
|
|
if (request.PsPdfKitAnnotation is PsPdfKitAnnotation annot)
|
|
await _repo.CreateAsync(annot.Structured, cancel);
|
|
else
|
|
throw new BadRequestException("Annotation data is missing or invalid.");
|
|
|
|
return await next(cancel);
|
|
}
|
|
}
|