@Override public boolean equals(Object obj) { if (obj instanceof MailboxAnnotation) { MailboxAnnotation o = (MailboxAnnotation) obj; return Objects.equal(key, o.getKey()) && Objects.equal(value, o.getValue()); } else { return false; } }
@Override public void insertAnnotation(MailboxId mailboxId, MailboxAnnotation mailboxAnnotation) { Preconditions.checkArgument(!mailboxAnnotation.isNil()); lock.writeLock().lock(); try { mailboxesAnnotations.put((InMemoryId)mailboxId, mailboxAnnotation.getKey().asString(), mailboxAnnotation.getValue().get()); } finally { lock.writeLock().unlock(); } }
@Override public void insertAnnotation(MailboxId mailboxId, MailboxAnnotation mailboxAnnotation) { Preconditions.checkArgument(!mailboxAnnotation.isNil()); JPAId jpaId = (JPAId) mailboxId; if (getAnnotationsByKeys(mailboxId, ImmutableSet.of(mailboxAnnotation.getKey())).isEmpty()) { getEntityManager().persist( new JPAMailboxAnnotation(jpaId.getRawId(), mailboxAnnotation.getKey().asString(), mailboxAnnotation.getValue().orElse(null))); } else { getEntityManager().find(JPAMailboxAnnotation.class, new JPAMailboxAnnotationId(jpaId.getRawId(), mailboxAnnotation.getKey().asString())) .setValue(mailboxAnnotation.getValue().orElse(null)); } }
@Override public void insertAnnotation(MailboxId mailboxId, MailboxAnnotation mailboxAnnotation) { Preconditions.checkArgument(!mailboxAnnotation.isNil()); session.execute(insertInto(CassandraAnnotationTable.TABLE_NAME) .value(CassandraAnnotationTable.MAILBOX_ID, ((CassandraId) mailboxId).asUuid()) .value(CassandraAnnotationTable.KEY, mailboxAnnotation.getKey().asString()) .value(CassandraAnnotationTable.VALUE, mailboxAnnotation.getValue().get())); }
private void composeAnnotation(ImapResponseComposer composer, ImapSession session, MailboxAnnotation annotation) throws IOException { if (annotation.isNil()) { LOGGER.warn("There is nil data of key {} on store: ", annotation.getKey().asString()); } else { composer.message(annotation.getKey().asString()); composer.quote(annotation.getValue().orElse("")); } }
@Test public void newInstanceMailboxAnnotationShouldCreateNewInstance() throws Exception { MailboxAnnotation annotation = MailboxAnnotation.newInstance(ANNOTATION_KEY, ANNOTATION_VALUE); assertThat(annotation.getKey()).isEqualTo(ANNOTATION_KEY); assertThat(annotation.getValue()).contains(ANNOTATION_VALUE); }
@Test public void nilInstanceShouldReturnAbsentValue() throws Exception { MailboxAnnotation annotation = MailboxAnnotation.nil(ANNOTATION_KEY); assertThat(annotation.getValue()).isEmpty(); }
@Test public void decodeMessageShouldReturnRequestWhenCommandHasEmptyAnnotationValue() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (/private/comment \" \") \n").getBytes()); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, null); SetAnnotationRequest request = (SetAnnotationRequest) parser.decode(command, lineReader, TAG, null); assertThat(request.getMailboxAnnotations().get(0).getValue()).isPresent(); }
@Test public void decodeMessageShouldReturnRequestWhenCommandAnnotationValueIsNILString() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (/private/comment \"NIL\") \n").getBytes()); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, null); SetAnnotationRequest request = (SetAnnotationRequest) parser.decode(command, lineReader, TAG, null); assertThat(request.getMailboxAnnotations().get(0).getValue()).isPresent(); }