@Override public Map<Integer, String> getAll(final Mailbox mailbox) { return AccountPersistence.getLabels(mailbox.getId()).getNameMap(); }
/** * Delete all indexes * * @param mutator * @param mailbox */ public static void deleteIndexes(Mutator<String> mutator, final String mailbox) { // get all labels LabelMap labels = AccountPersistence.getLabels(mailbox); for (Integer labelId : labels.getIds()) { deleteIndex(mutator, mailbox, labelId); } // delete purge index String key = getLabelKey(mailbox, PurgeIndexPersistence.PURGE_LABEL_ID); mutator.addDeletion(key, CF_LABEL_INDEX, null, strSe); }
@Override public LabelMap getAllWithMetadata(final Mailbox mailbox) throws IOException { // get labels LabelMap labels = AccountPersistence.getLabels(mailbox.getId()); // set labels' counters Map<Integer, LabelCounters> counters = LabelCounterPersistence.getAll(mailbox.getId()); for (int labelId : counters.keySet()) { if (labels.containsId(labelId) && counters.containsKey(labelId)) { labels.get(labelId).setCounters(counters.get(labelId)); } else if (labels.containsId(labelId) && !counters.containsKey(labelId)) { // assume zeros for all counters if not yet initialised labels.get(labelId).setCounters(new LabelCounters()); } else if (!labels.containsId(labelId) && counters.containsKey(labelId)) { logger.warn("Found counters for label {}/{}, but label does not exist.", mailbox.getId(), labelId); } } return labels; }
@Override public int add(Mailbox mailbox, Label label) { // get all existing labels LabelMap existingLabels = AccountPersistence.getLabels(mailbox.getId()); LabelUtils.validateLabelName(label.getName(), existingLabels); try { // generate new label id int labelId = LabelUtils.getNewLabelId(existingLabels.getIds()); label.setId(labelId); } catch (IllegalLabelException ile) { // log and rethrow logger.warn("{} reached max random label id attempts with {} labels", mailbox, existingLabels.size()); throw ile; } // begin batch operation Mutator<String> mutator = createMutator(keyspace, strSe); // add new label AccountPersistence.putLabel(mutator, mailbox.getId(), label); // commit batch operation mutator.execute(); return label.getId(); }
LabelMap allLabels = AccountPersistence.getLabels(mailbox.getId()); LabelIndexPersistence.remove(mutator, mailbox.getId(), invalidMessageIds, allLabels.getIds());
@Override public void update(Mailbox mailbox, Label label) throws IOException { // get all existing labels LabelMap existingLabels = AccountPersistence.getLabels(mailbox.getId()); // validate only if name is changed (skips letter case changes) if (label.getName() != null && !existingLabels.containsName(label.getName())) { LabelUtils.validateLabelName(label.getName(), existingLabels); } // check if label id reserved if (ReservedLabels.contains(label.getId())) { throw new ExistingLabelException("This is reserved label and can't be modified"); } // check if label id exists if (!existingLabels.containsId(label.getId())) { throw new IllegalLabelException("Label does not exist"); } // begin batch operation Mutator<String> mutator = createMutator(keyspace, strSe); // set new name AccountPersistence.putLabel(mutator, mailbox.getId(), label); // commit batch operation mutator.execute(); }