[ws] Unifi attachments
which detects newly inserted attachments (it does not run for x_snd_eb tables). This after insert rule creates Bonded Attachment (BA) records as required by calling AttachmentHandler.createBondAttachment(current)
.Message.processOutbound
is called against the target record, with an option that indicates that this was as a result of an attachment being added.AttachmentHandler#getAttachmentsToSend
, called from Message#send
Transaction#send
method will create a new request and call Message#generatePayload
. This method processes the Stage to Request (Outbound)
script, if present, and if that returns no payload then the XML template will be processed.<snd_eb_attachments>
which finds each Bonded Attachment in the Sending state, embeds an attachment placeholder for each one into the payload, and sets the BA to the Sent state (the UI Macro is part of "[ws] Unifi Standard API" application).AttachmentSender
to insert <x-attachment-data>
elements. There will be one element per attachment returned and it will contain the sys_id of sys_attachment to be sent. AttachmentSender
is essentially an iterator over all BA records for a specific transaction where the state is Sending. It marks each BA as Sent once it has been selectedHttpRequest#send
which calls the static method AttachmentHandler.injectAttachments
. This replaces the <x-attachment-data>
elements with Base64 data. This behaviour is hard-coded.extract_attachments
script is calledsnd_eb_api_utils.extractAttachments
script expects an XML document or string as input and searches for an element called eb:Attachments
.eb:Attachment
elements which each have eb:FileName
, eb:MimeCode
and eb:Data
child nodes. The text content of these are read and stored in a result
object. The text content of the Data element is removed from the input XML (so when it is passed back we can log the inbound request_payload without the attachment data).AttachmentHandler.saveAttachment
(with the raw Base64 data already decoded). This method creates the attachment and links it to the HTTPRequest record (note that this will not trigger the after insert rule on the Attachments table, since HTTPRequest is an x_snd_eb type table). The method is expected to return an x-attachment-data
tag containing the sys_id of the attachment created as an attribute. This tag is inserted into the original XML.x-attachment-data
placeholder tags substituted for the raw attachment data.AttachmentHandler.createInboundAttachments
script expects to process a request_payload
which has x-attachment-data
placeholders embedded within. The sys_ids of these placeholders are extracted using regex search, and for each sys_id we call AttachmentHandler.addToTransaction
, which creates a Bonded Attachment in the Ready state (There will be no Bond specified on the BA at this point).x-attachment-data
placeholder tags is hard-coded into Unifi.