public AttachmentId getAttachmentId() { return attachment.getAttachmentId(); }
@Override public void storeAttachmentForOwner(Attachment attachment, Username owner) throws MailboxException { attachmentsById.put(attachment.getAttachmentId(), attachment); ownersByAttachmentId.put(attachment.getAttachmentId(), owner); }
@Override public void storeAttachmentsForMessage(Collection<Attachment> attachments, MessageId ownerMessageId) throws MailboxException { for (Attachment attachment: attachments) { attachmentsById.put(attachment.getAttachmentId(), attachment); messageIdsByAttachmentId.put(attachment.getAttachmentId(), ownerMessageId); } }
@Override public void storeAttachmentForOwner(Attachment attachment, Username owner) throws MailboxException { ownerDAO.addOwner(attachment.getAttachmentId(), owner) .thenCompose(any -> blobStore.save(attachment.getBytes())) .thenApply(blobId -> CassandraAttachmentDAOV2.from(attachment, blobId)) .thenCompose(attachmentDAOV2::storeAttachment) .join(); }
private Result migrateAttachment(Attachment attachment) { try { blobStore.save(attachment.getBytes()) .thenApply(blobId -> CassandraAttachmentDAOV2.from(attachment, blobId)) .thenCompose(attachmentDAOV2::storeAttachment) .thenCompose(any -> attachmentDAOV1.deleteAttachment(attachment.getAttachmentId())) .join(); return Result.COMPLETED; } catch (Exception e) { LOGGER.error("Error while performing attachmentDAO V2 migration", e); return Result.PARTIAL; } } }
public static DAOAttachment from(Attachment attachment, BlobId blobId) { return new DAOAttachment( attachment.getAttachmentId(), blobId, attachment.getType(), attachment.getSize()); }
@Test void deleteAttachmentShouldRemoveAttachment() throws Exception { Attachment attachment = Attachment.builder() .attachmentId(ATTACHMENT_ID) .type("application/json") .bytes("{\"property\":`\"value\"}".getBytes(StandardCharsets.UTF_8)) .build(); testee.storeAttachment(attachment).join(); testee.deleteAttachment(attachment.getAttachmentId()).join(); assertThat(testee.getAttachment(attachment.getAttachmentId()).join()) .isEmpty(); } }
public CompletableFuture<Void> storeAttachment(Attachment attachment) throws IOException { return cassandraAsyncExecutor.executeVoid( insertStatement.bind() .setString(ID, attachment.getAttachmentId().getId()) .setLong(SIZE, attachment.getSize()) .setString(TYPE, attachment.getType()) .setBytes(PAYLOAD, ByteBuffer.wrap(attachment.getBytes()))); }
private UploadResponse uploadContent(String contentType, InputStream inputStream, MailboxSession session) throws IOException, MailboxException { Attachment attachment = Attachment.builder() .bytes(ByteStreams.toByteArray(inputStream)) .type(contentType) .build(); attachmentManager.storeAttachment(attachment, session); return UploadResponse.builder() .blobId(attachment.getAttachmentId().getId()) .type(attachment.getType()) .size(attachment.getSize()) .build(); }