throw new IllegalLabelException("Label name exceeds maximum allowed length"); throw new IllegalLabelException("Netsted labels are not allowed under reserved labels"); throw new IllegalLabelException("Illegal use of nested label separator");
/** * Delete label * * @param account * @param labelId * @return */ @DELETE @Path("{id}") @Produces(MediaType.APPLICATION_JSON) public Response deleteLabel( @PathParam("user") String user, @PathParam("domain") String domain, @PathParam("id") Integer labelId) { Mailbox mailbox = new Mailbox(user, domain); try { labelDAO.delete(mailbox, labelId); } catch (IllegalLabelException ile) { throw new BadRequestException(ile.getMessage()); } catch (Exception e) { logger.error("Deleting label failed", e); throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR); } return Response.noContent().build(); }
/** * Generates new label ID which does not exist in the given list * * @param existingLabels * @return */ public static int getNewLabelId(Set<Integer> existingLabels) { // generate new unique label id int labelId = LabelUtils.getNewLabelId(); int attempts = 1; while (existingLabels.contains(labelId)) { if (attempts > MAX_NEW_LABEL_ID_ATTEMPTS) { // too many attempts to get new random id! too many labels? throw new IllegalLabelException("Too many labels"); } labelId = LabelUtils.getNewLabelId(); attempts++; } return labelId; }
throw new BadRequestException(ile.getMessage()); } catch (Exception e) { logger.warn("Internal Server Error: ", e);
throw new IllegalLabelException("Invalid character detected in the custom label attribute name.");
throw new BadRequestException(ile.getMessage()); } catch (Exception e) { logger.error("Message modifications failed: ", e);
throw new IllegalLabelException("This is reserved label and can't be modified");
newLabelId = labelDAO.add(mailbox, label); } catch (IllegalLabelException ile) { throw new BadRequestException(ile.getMessage()); } catch (ExistingLabelException ele) { throw new RESTApplicationException(Status.CONFLICT, ele.getMessage());
throw new IllegalLabelException("This label cannot be removed");
labelDAO.update(mailbox, label); } catch (IllegalLabelException ile) { throw new BadRequestException(ile.getMessage()); } catch (ExistingLabelException ele) { throw new RESTApplicationException(Status.CONFLICT, ele.getMessage());
@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(); }