private CompletableFuture<Void> manageRecentOnFlagsUpdate(CassandraId mailboxId, UpdatedFlags updatedFlags) { if (updatedFlags.isModifiedToUnset(Flags.Flag.RECENT)) { return mailboxRecentDAO.removeFromRecent(mailboxId, updatedFlags.getUid()); } if (updatedFlags.isModifiedToSet(Flags.Flag.RECENT)) { return mailboxRecentDAO.addToRecent(mailboxId, updatedFlags.getUid()); } return CompletableFuture.completedFuture(null); }
private CompletableFuture<Void> updateDeletedOnFlagsUpdate(CassandraId mailboxId, UpdatedFlags updatedFlags) { if (updatedFlags.isModifiedToSet(Flags.Flag.DELETED)) { return deletedMessageDAO.addDeleted(mailboxId, updatedFlags.getUid()); } else if (updatedFlags.isModifiedToUnset(Flags.Flag.DELETED)) { return deletedMessageDAO.removeDeleted(mailboxId, updatedFlags.getUid()); } else { return CompletableFuture.completedFuture(null); } }
private CompletableFuture<Void> updateFirstUnseenOnFlagsUpdate(CassandraId mailboxId, UpdatedFlags updatedFlags) { if (updatedFlags.isModifiedToUnset(Flags.Flag.SEEN)) { return firstUnseenDAO.addUnread(mailboxId, updatedFlags.getUid()); } if (updatedFlags.isModifiedToSet(Flags.Flag.SEEN)) { return firstUnseenDAO.removeUnread(mailboxId, updatedFlags.getUid()); } return CompletableFuture.completedFuture(null); } }
private CompletableFuture<FlagsUpdateStageResult> updateIndexesForUpdatesResult(CassandraId mailboxId, FlagsUpdateStageResult result) { return FluentFutureStream.of( result.getSucceeded().stream() .map(Throwing .function((UpdatedFlags updatedFlags) -> indexTableHandler.updateIndexOnFlagsUpdate(mailboxId, updatedFlags)) .fallbackTo(failedindex -> { LOGGER.error("Could not update flag indexes for mailboxId {} UID {}. This will lead to inconsistencies across Cassandra tables", mailboxId, failedindex.getUid()); return CompletableFuture.completedFuture(null); }))) .completableFuture() .thenApply(any -> result); }
@Override public Map<MessageUid, Flags> setFlags(final Flags flags, final FlagsUpdateMode flagsUpdateMode, final MessageRange set, MailboxSession mailboxSession) throws MailboxException { if (!isWriteable(mailboxSession)) { throw new ReadOnlyException(getMailboxPath(), mailboxSession.getPathDelimiter()); } final SortedMap<MessageUid, Flags> newFlagsByUid = new TreeMap<>(); trimFlags(flags, mailboxSession); final MessageMapper messageMapper = mapperFactory.getMessageMapper(mailboxSession); Iterator<UpdatedFlags> it = messageMapper.execute(() -> messageMapper.updateFlags(getMailboxEntity(), new FlagsUpdateCalculator(flags, flagsUpdateMode), set)); final SortedMap<MessageUid, UpdatedFlags> uFlags = new TreeMap<>(); while (it.hasNext()) { UpdatedFlags flag = it.next(); newFlagsByUid.put(flag.getUid(), flag.getNewFlags()); uFlags.put(flag.getUid(), flag); } dispatcher.flagsUpdated(mailboxSession, new ArrayList<>(uFlags.keySet()), getMailboxEntity(), new ArrayList<>(uFlags.values())); return newFlagsByUid; }
private UpdatedRepresentation createUpdatedDocumentPartFromUpdatedFlags(Mailbox mailbox, UpdatedFlags updatedFlags) { try { return new UpdatedRepresentation( indexIdFor(mailbox, updatedFlags.getUid()), messageToElasticSearchJson.getUpdatedJsonMessagePart( updatedFlags.getNewFlags(), updatedFlags.getModSeq())); } catch (JsonProcessingException e) { throw new RuntimeException("Error while creating updatedDocumentParts", e); } }
private void dispatchFlagsChange(MailboxSession mailboxSession, MailboxId mailboxId, UpdatedFlags updatedFlags) throws MailboxException { if (updatedFlags.flagsChanged()) { Mailbox mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId); dispatcher.flagsUpdated(mailboxSession, updatedFlags.getUid(), mailbox, updatedFlags); } }
public UpdatedFlagsDataTransferObject(UpdatedFlags updatedFlags) { this.uid = updatedFlags.getUid().asLong(); this.modseq = updatedFlags.getModSeq(); this.oldFlags = new FlagsDataTransferObject(updatedFlags.getOldFlags()); this.newFlags = new FlagsDataTransferObject(updatedFlags.getNewFlags()); }