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())); }
private MailboxNamespace getNamespace(MailboxPath mailboxPath, boolean isOwner) { if (isOwner) { return MailboxNamespace.personal(); } return MailboxNamespace.delegated(mailboxPath.getUser()); }
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(); }
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); }
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)); }
Task.Result handleMessageReIndexing(MailboxPath path, MessageUid uid) throws MailboxException { MailboxSession mailboxSession = mailboxManager.createSystemSession(path.getUser()); Mailbox mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession) .findMailboxByPath(path); return handleMessageReIndexing(mailboxSession, mailbox, uid); }
@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)); }
@Override public void setRights(MailboxPath mailboxPath, MailboxACL mailboxACL, MailboxSession session) throws MailboxException { assertSharesBelongsToUserDomain(mailboxPath.getUser(), mailboxACL.getEntries()); MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); Mailbox mailbox = mapper.findMailboxByPath(mailboxPath); setRights(mailboxACL, mapper, mailbox, session); }
@Override public void createMailbox(MailboxPath mailboxPath) throws Exception { MailboxManager mailboxManager = getMailboxManager(); MailboxSession mailboxSession = mailboxManager.createSystemSession(mailboxPath.getUser()); mailboxManager.startProcessingRequest(mailboxSession); mailboxManager.createMailbox(mailboxPath, mailboxSession); mailboxManager.logout(mailboxSession, true); mailboxManager.endProcessingRequest(mailboxSession); }
@Override public void replaceRights(MailboxPath mailboxPath, String targetUser, Rfc4314Rights rights) throws MailboxException { MailboxSession mailboxSession = mailboxManager.createSystemSession(mailboxPath.getUser()); ACLCommand command = MailboxACL.command().forUser(targetUser).rights(rights).asReplacement(); mailboxManager.applyRightsCommand(mailboxPath, command, mailboxSession); }
@Override public void addRights(MailboxPath mailboxPath, String targetUser, Rfc4314Rights rights) throws MailboxException { MailboxSession mailboxSession = mailboxManager.createSystemSession(mailboxPath.getUser()); ACLCommand command = MailboxACL.command().forUser(targetUser).rights(rights).asAddition(); mailboxManager.applyRightsCommand(mailboxPath, command, mailboxSession); }
@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()); }
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); }