public Builder userAndNamespaceFrom(MailboxPath base) { Preconditions.checkState(!this.namespace.isPresent()); Preconditions.checkState(!this.username.isPresent()); this.namespace = Optional.ofNullable(base.getNamespace()); this.username = Optional.ofNullable(base.getUser()); return this; }
@VisibleForTesting boolean belongsToRequestedNamespaceAndUser(MailboxPath mailboxPath) { boolean belongsToRequestedNamespace = namespace .map(value -> value.equals(mailboxPath.getNamespace())) .orElse(true); boolean belongsToRequestedUser = user .map(value -> value.equals(mailboxPath.getUser())) .orElse(true); return belongsToRequestedNamespace && belongsToRequestedUser; }
@Override public QuotaRoot getQuotaRoot(MailboxPath mailboxPath) { Preconditions.checkArgument(!mailboxPath.getNamespace().contains(SEPARATOR), "Namespace should not contain " + SEPARATOR); return Optional.ofNullable(mailboxPath.getUser()) .map(user -> { Preconditions.checkArgument(!mailboxPath.getUser().contains(SEPARATOR), "Username should not contain " + SEPARATOR); return User.fromUsername(mailboxPath.getUser()); }) .map(user -> QuotaRoot.quotaRoot(mailboxPath.getNamespace() + SEPARATOR + user.asString(), user.getDomainPart())) .orElseGet(() -> QuotaRoot.quotaRoot(mailboxPath.getNamespace(), Optional.empty())); }
public JPAMailbox(MailboxPath path, long uidValidity) { this.name = path.getName(); this.user = path.getUser(); this.namespace = path.getNamespace(); this.uidValidity = uidValidity; }
public MailboxPathDataTransferObject(MailboxPath path) { this.user = path.getUser(); this.name = path.getName(); this.namespace = path.getNamespace(); }
public SimpleMailbox(MailboxPath path, long uidValidity, MailboxId mailboxId) { this.id = mailboxId; this.namespace = path.getNamespace(); this.user = path.getUser(); this.name = path.getName(); this.uidValidity = uidValidity; }
private boolean mailboxMatchesRegex(Mailbox mailbox, MailboxPath path, String regex) { return Objects.equal(mailbox.getNamespace(), path.getNamespace()) && Objects.equal(mailbox.getUser(), path.getUser()) && mailbox.getName().matches(regex); }
@Override public List<Mailbox> findMailboxWithPathLike(MailboxPath path) { List<Mailbox> mailboxesV2 = toMailboxes(path, mailboxPathV2DAO.listUserMailboxes(path.getNamespace(), path.getUser())); List<Mailbox> mailboxesV1 = toMailboxes(path, mailboxPathDAO.listUserMailboxes(path.getNamespace(), path.getUser())); List<Mailbox> mailboxesV1NotInV2 = mailboxesV1.stream() .filter(mailboxV1 -> mailboxesV2.stream() .map(Mailbox::generateAssociatedPath) .noneMatch(mailboxV2path -> mailboxV2path.equals(mailboxV1.generateAssociatedPath()))) .collect(Guavate.toImmutableList()); return ImmutableList.<Mailbox>builder() .addAll(mailboxesV2) .addAll(mailboxesV1NotInV2) .build(); }
public CompletableFuture<Optional<CassandraIdAndPath>> retrieveId(MailboxPath mailboxPath) { return cassandraAsyncExecutor.executeSingleRow( select.bind() .setUDTValue(NAMESPACE_AND_USER, mailboxBaseTupleUtil.createMailboxBaseUDT(mailboxPath.getNamespace(), mailboxPath.getUser())) .setString(MAILBOX_NAME, mailboxPath.getName())) .thenApply(rowOptional -> rowOptional.map(this::fromRowToCassandraIdAndPath)) .thenApply(value -> logGhostMailbox(mailboxPath, value)); }
@Override public CompletableFuture<Optional<CassandraIdAndPath>> retrieveId(MailboxPath mailboxPath) { return cassandraAsyncExecutor.executeSingleRow( select.bind() .setString(NAMESPACE, mailboxPath.getNamespace()) .setString(USER, sanitizeUser(mailboxPath.getUser())) .setString(MAILBOX_NAME, mailboxPath.getName())) .thenApply(rowOptional -> rowOptional.map(this::fromRowToCassandraIdAndPath)) .thenApply(value -> logGhostMailbox(mailboxPath, value)); }
@Test void updateShouldChangeMailboxPath() { testee.save(mailbox1).join(); testee.updatePath(CASSANDRA_ID_1, NEW_MAILBOX_PATH).join(); mailbox1.setNamespace(NEW_MAILBOX_PATH.getNamespace()); mailbox1.setUser(NEW_MAILBOX_PATH.getUser()); mailbox1.setName(NEW_MAILBOX_PATH.getName()); Optional<SimpleMailbox> readMailbox = testee.retrieveMailbox(CASSANDRA_ID_1).join(); assertThat(readMailbox.isPresent()).isTrue(); assertThat(readMailbox.get()).isEqualToComparingFieldByField(mailbox1); } }
private UDTValue buildUDTFromMailboxPath(MailboxPath path) { return typesProvider.getDefinedUserType(CassandraMailboxPathRegisterTable.MAILBOX_PATH) .newValue() .setString(CassandraMailboxPathRegisterTable.MailboxPath.NAMESPACE, path.getNamespace()) .setString(CassandraMailboxPathRegisterTable.MailboxPath.USER, path.getUser()) .setString(CassandraMailboxPathRegisterTable.MailboxPath.NAME, path.getName()); }
@Test void getUserMailboxesShouldReturnAllMailboxesOfUser() { testee.save(USER_INBOX_MAILBOXPATH, INBOX_ID).join(); testee.save(USER_OUTBOX_MAILBOXPATH, OUTBOX_ID).join(); testee.save(OTHER_USER_MAILBOXPATH, otherMailboxId).join(); List<CassandraIdAndPath> cassandraIds = testee .listUserMailboxes(USER_INBOX_MAILBOXPATH.getNamespace(), USER_INBOX_MAILBOXPATH.getUser()) .join() .collect(Guavate.toImmutableList()); assertThat(cassandraIds) .hasSize(2) .containsOnly(INBOX_ID_AND_PATH, new CassandraIdAndPath(OUTBOX_ID, USER_OUTBOX_MAILBOXPATH)); }
@Override public CompletableFuture<Void> delete(MailboxPath mailboxPath) { return cassandraAsyncExecutor.executeVoid(delete.bind() .setUDTValue(NAMESPACE_AND_USER, mailboxBaseTupleUtil.createMailboxBaseUDT(mailboxPath.getNamespace(), mailboxPath.getUser())) .setString(MAILBOX_NAME, mailboxPath.getName())); }
@Override public CompletableFuture<Void> delete(MailboxPath mailboxPath) { return cassandraAsyncExecutor.executeVoid(delete.bind() .setString(NAMESPACE, mailboxPath.getNamespace()) .setString(USER, sanitizeUser(mailboxPath.getUser())) .setString(MAILBOX_NAME, mailboxPath.getName())); }
public CompletableFuture<Void> updatePath(CassandraId mailboxId, MailboxPath mailboxPath) { return executor.executeVoid(updateStatement.bind() .setUUID(ID, mailboxId.asUuid()) .setString(NAME, mailboxPath.getName()) .setUDTValue(MAILBOX_BASE, mailboxBaseTupleUtil.createMailboxBaseUDT(mailboxPath.getNamespace(), mailboxPath.getUser()))); }
@Override public CompletableFuture<Boolean> save(MailboxPath mailboxPath, CassandraId mailboxId) { return cassandraAsyncExecutor.executeReturnApplied(insert.bind() .setUDTValue(NAMESPACE_AND_USER, mailboxBaseTupleUtil.createMailboxBaseUDT(mailboxPath.getNamespace(), mailboxPath.getUser())) .setString(MAILBOX_NAME, mailboxPath.getName()) .setUUID(MAILBOX_ID, mailboxId.asUuid())); }
@Test public void builderShouldUseBaseWhenGiven() throws Exception { MailboxQuery actual = MailboxQuery.builder() .userAndNamespaceFrom(mailboxPath) .build(); assertThat(actual.getNamespace()).contains(mailboxPath.getNamespace()); assertThat(actual.getUser()).contains(mailboxPath.getUser()); assertThat(actual.getMailboxNameExpression()).isEqualTo(Wildcard.INSTANCE); }
@Test public void buildShouldConstructMailboxPathWhenPrivateUserMailboxes() throws Exception { MailboxPath expected = MailboxPath.forUser("user", ""); MailboxQuery actual = MailboxQuery.builder() .username("user") .privateNamespace() .build(); assertThat(actual.getNamespace()).contains(expected.getNamespace()); assertThat(actual.getUser()).contains(expected.getUser()); assertThat(actual.getMailboxNameExpression()).isEqualTo(Wildcard.INSTANCE); }
@Override public CompletableFuture<Boolean> save(MailboxPath mailboxPath, CassandraId mailboxId) { return cassandraAsyncExecutor.executeReturnApplied(insert.bind() .setString(NAMESPACE, mailboxPath.getNamespace()) .setString(USER, sanitizeUser(mailboxPath.getUser())) .setString(MAILBOX_NAME, mailboxPath.getName()) .setUUID(MAILBOX_ID, mailboxId.asUuid())); }