refactor(PDFBurner): enhance annotation ID handling and validation
- Added parsing of annotation `id` into `envelopeId`, `receiverId`, `index`, and `internalType`. - Added validation for `id` format, ensuring it has exactly 4 parts and numeric checks for relevant fields. - Throws `BurnAnnotationException` if `id` is null, empty, or incorrectly formatted. - Maintains existing functionality for adding image, ink, and widget annotations.
This commit is contained in:
parent
a29f918125
commit
b67f26cc21
@ -76,35 +76,35 @@ Namespace Jobs.FinalizeDocument
|
|||||||
Dim isSeal = True 'First element is signature seal
|
Dim isSeal = True 'First element is signature seal
|
||||||
|
|
||||||
Dim formFieldIndex = 0
|
Dim formFieldIndex = 0
|
||||||
For Each oAnnotation In oAnnotationData.annotations
|
For Each oAnnotation In oAnnotationData.annotations
|
||||||
Logger.Debug("Adding AnnotationID: " + oAnnotation.id)
|
Logger.Debug("Adding AnnotationID: " + oAnnotation.id)
|
||||||
|
|
||||||
Select Case oAnnotation.type
|
Select Case oAnnotation.type
|
||||||
Case ANNOTATION_TYPE_IMAGE
|
Case ANNOTATION_TYPE_IMAGE
|
||||||
|
|
||||||
If (isSeal) Then
|
If (isSeal) Then
|
||||||
oAnnotation.bbox.Item(1) = yPosOfSigAnnot
|
oAnnotation.bbox.Item(1) = yPosOfSigAnnot
|
||||||
End If
|
End If
|
||||||
|
|
||||||
AddImageAnnotation(oAnnotation, oAnnotationData.attachments)
|
AddImageAnnotation(oAnnotation, oAnnotationData.attachments)
|
||||||
Exit Select
|
Exit Select
|
||||||
|
|
||||||
Case ANNOTATION_TYPE_INK
|
Case ANNOTATION_TYPE_INK
|
||||||
AddInkAnnotation(oAnnotation)
|
AddInkAnnotation(oAnnotation)
|
||||||
Exit Select
|
Exit Select
|
||||||
|
|
||||||
Case ANNOTATION_TYPE_WIDGET
|
Case ANNOTATION_TYPE_WIDGET
|
||||||
'Add form field values
|
'Add form field values
|
||||||
Dim formFieldValue = oAnnotationData.formFieldValues.FirstOrDefault(Function(fv) fv.name = oAnnotation.id)
|
Dim formFieldValue = oAnnotationData.formFieldValues.FirstOrDefault(Function(fv) fv.name = oAnnotation.id)
|
||||||
If formFieldValue IsNot Nothing AndAlso Not _pdfBurnerParams.IgnoredLabels.Contains(formFieldValue.value) Then
|
If formFieldValue IsNot Nothing AndAlso Not _pdfBurnerParams.IgnoredLabels.Contains(formFieldValue.value) Then
|
||||||
AddFormFieldValue(oAnnotation, formFieldValue, formFieldIndex)
|
AddFormFieldValue(oAnnotation, formFieldValue, formFieldIndex)
|
||||||
formFieldIndex += 1
|
formFieldIndex += 1
|
||||||
End If
|
End If
|
||||||
Exit Select
|
Exit Select
|
||||||
End Select
|
End Select
|
||||||
|
|
||||||
isSeal = False
|
isSeal = False
|
||||||
Next
|
Next
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Function AddImageAnnotation(pAnnotation As Annotation, pAttachments As Dictionary(Of String, Attachment)) As Void
|
Private Function AddImageAnnotation(pAnnotation As Annotation, pAttachments As Dictionary(Of String, Attachment)) As Void
|
||||||
@ -193,7 +193,50 @@ Namespace Jobs.FinalizeDocument
|
|||||||
End Class
|
End Class
|
||||||
|
|
||||||
Friend Class Annotation
|
Friend Class Annotation
|
||||||
|
|
||||||
|
Private _id As Integer
|
||||||
|
|
||||||
|
Public envelopeId As Integer
|
||||||
|
|
||||||
|
Public receiverId As Integer
|
||||||
|
|
||||||
|
Public index As Integer
|
||||||
|
|
||||||
|
Public internalType As String
|
||||||
|
|
||||||
Public Property id As String
|
Public Property id As String
|
||||||
|
Get
|
||||||
|
Return _id
|
||||||
|
End Get
|
||||||
|
Set(value As String)
|
||||||
|
_id = value
|
||||||
|
|
||||||
|
If String.IsNullOrWhiteSpace(id) Then
|
||||||
|
Throw New BurnAnnotationException("The identifier of annotation is null or empty.")
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim parts As String() = value.Split("-"c)
|
||||||
|
|
||||||
|
If (parts.Length <> 4) Then
|
||||||
|
Throw New BurnAnnotationException($"The identifier of annotation has more or less than 4 sub-part. Id: {_id}")
|
||||||
|
End If
|
||||||
|
|
||||||
|
If Not Integer.TryParse(parts(0), envelopeId) Then
|
||||||
|
Throw New BurnAnnotationException($"The envelope ID of annotation is not integer. Id: {_id}")
|
||||||
|
End If
|
||||||
|
|
||||||
|
If Not Integer.TryParse(parts(1), receiverId) Then
|
||||||
|
Throw New BurnAnnotationException($"The receiver ID of annotation is not integer. Id: {_id}")
|
||||||
|
End If
|
||||||
|
|
||||||
|
If Not Integer.TryParse(parts(2), index) Then
|
||||||
|
Throw New BurnAnnotationException($"The index of annotation is not integer. Id: {_id}")
|
||||||
|
End If
|
||||||
|
|
||||||
|
internalType = parts(3)
|
||||||
|
End Set
|
||||||
|
End Property
|
||||||
|
|
||||||
Public Property bbox As List(Of Double)
|
Public Property bbox As List(Of Double)
|
||||||
Public Property type As String
|
Public Property type As String
|
||||||
Public Property isSignature As Boolean
|
Public Property isSignature As Boolean
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user