use of uk.nhs.adaptors.pss.translator.storage.StorageDataUploadWrapper in project nia-patient-switching-standard-adaptor by NHSDigital.
the class AttachmentHandlerService method storeAttachments.
public void storeAttachments(List<InboundMessage.Attachment> attachments, String conversationId) throws ValidationException, InlineAttachmentProcessingException {
if (!StringUtils.hasText(conversationId)) {
throw new ValidationException("ConversationId cannot be null or empty");
}
if (attachments != null) {
for (InboundMessage.Attachment attachment : attachments) {
try {
InlineAttachment inlineAttachment = new InlineAttachment(attachment);
byte[] decodedPayload = Base64.getMimeDecoder().decode(inlineAttachment.getPayload());
byte[] payload;
if (inlineAttachment.isCompressed()) {
GZIPInputStream inputStream = new GZIPInputStream(new ByteArrayInputStream(decodedPayload));
payload = inputStream.readAllBytes();
} else {
payload = decodedPayload;
}
StorageDataUploadWrapper dataWrapper = new StorageDataUploadWrapper(attachment.getContentType(), conversationId, payload);
String filename = inlineAttachment.getOriginalFilename();
storageManagerService.uploadFile(filename, dataWrapper, conversationId);
} catch (StorageException ex) {
throw new InlineAttachmentProcessingException("Unable to upload inline attachment to storage: " + ex.getMessage());
} catch (IOException ex) {
throw new InlineAttachmentProcessingException("Unable to decompress attachment: " + ex.getMessage());
} catch (ParseException ex) {
throw new InlineAttachmentProcessingException("Unable to parse inline attachment description: " + ex.getMessage());
}
}
}
}
Aggregations