@Override public Attachment getAttachment(AttachmentId attachmentId) throws AttachmentNotFoundException { Preconditions.checkArgument(attachmentId != null); if (!attachmentsById.containsKey(attachmentId)) { throw new AttachmentNotFoundException(attachmentId.getId()); } return attachmentsById.get(attachmentId); }
@Override public Attachment getAttachment(AttachmentId attachmentId) throws AttachmentNotFoundException { Preconditions.checkArgument(attachmentId != null); return getAttachmentInternal(attachmentId) .join() .orElseThrow(() -> new AttachmentNotFoundException(attachmentId.getId())); }
public CompletableFuture<Optional<Attachment>> getAttachment(AttachmentId attachmentId) { Preconditions.checkArgument(attachmentId != null); return cassandraAsyncExecutor.executeSingleRow( selectStatement.bind() .setString(ID, attachmentId.getId())) .thenApply(optional -> optional.map(this::attachment)); }
public CompletableFuture<Void> deleteAttachment(AttachmentId attachmentId) { return cassandraAsyncExecutor.executeVoid( deleteStatement .bind() .setString(ID, attachmentId.getId())); }
@Override public Attachment getAttachment(AttachmentId attachmentId, MailboxSession mailboxSession) throws MailboxException, AttachmentNotFoundException { if (!userHasAccessToAttachment(attachmentId, mailboxSession)) { throw new AttachmentNotFoundException(attachmentId.getId()); } return attachmentMapperFactory.getAttachmentMapper(mailboxSession).getAttachment(attachmentId); }
@Test public void fromStringShouldWork() { String expectedId = "f07e5a815613c5abeddc4b682247a4c42d8a95df"; AttachmentId attachmentId = AttachmentId.from(expectedId); assertThat(attachmentId.getId()).isEqualTo(expectedId); }
public void retrieveAndSaveAttachmentDetails(String user, String messageId, String attachmentId, ComposedMessageId composedMessageId) throws MailboxException { AttachmentId mailboxAttachmentId = mainStepdefs.messageIdProbe .retrieveAttachmentIds(composedMessageId.getMessageId(), user) .get(0); inputToMessageId.put(messageId, composedMessageId.getMessageId()); attachmentsByMessageId.put(messageId, attachmentId); blobIdByAttachmentId.put(attachmentId, mailboxAttachmentId.getId()); }
private UDTValue toUDT(MessageAttachment messageAttachment) { return typesProvider.getDefinedUserType(ATTACHMENTS) .newValue() .setString(Attachments.ID, messageAttachment.getAttachmentId().getId()) .setString(Attachments.NAME, messageAttachment.getName().orElse(null)) .setString(Attachments.CID, messageAttachment.getCid().map(Cid::getValue).orElse(null)) .setBool(Attachments.IS_INLINE, messageAttachment.isInline()); }
@Test public void fromBlobIdShouldWork() { String expectedId = "f07e5a815613c5abeddc4b682247a4c42d8a95df"; AttachmentId attachmentId = AttachmentId.from(BlobId.fromString(expectedId)); assertThat(attachmentId.getId()).isEqualTo(expectedId); }
public CompletableFuture<Void> storeAttachmentForMessageId(AttachmentId attachmentId, MessageId ownerMessageId) { return cassandraAsyncExecutor.executeVoid( insertStatement.bind() .setUUID(ATTACHMENT_ID_AS_UUID, attachmentId.asUUID()) .setString(ATTACHMENT_ID, attachmentId.getId()) .setString(MESSAGE_ID, ownerMessageId.serialize())); } }
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(); }
private Attachment fromMailboxAttachment(MessageAttachment attachment) { return Attachment.builder() .blobId(BlobId.of(attachment.getAttachmentId().getId())) .type(attachment.getAttachment().getType()) .size(attachment.getAttachment().getSize()) .name(attachment.getName()) .cid(attachment.getCid().map(Cid::getValue)) .isInline(attachment.isInline()) .build(); }
public CompletableFuture<Void> storeAttachment(DAOAttachment attachment) { return cassandraAsyncExecutor.executeVoid( insertStatement.bind() .setUUID(ID_AS_UUID, attachment.getAttachmentId().asUUID()) .setString(ID, attachment.getAttachmentId().getId()) .setLong(SIZE, attachment.getSize()) .setString(TYPE, attachment.getType()) .setString(BLOB_ID, attachment.getBlobId().asString())); }