Exemple #1
0
  @POST
  @Path("/{accountId:" + UUID_PATTERN + "}/" + EMAILS)
  @Consumes(APPLICATION_JSON)
  @Produces(APPLICATION_JSON)
  public Response addEmail(
      final AccountEmailJson json,
      @PathParam(ID_PARAM_NAME) final String id,
      @HeaderParam(HDR_CREATED_BY) final String createdBy,
      @HeaderParam(HDR_REASON) final String reason,
      @HeaderParam(HDR_COMMENT) final String comment,
      @javax.ws.rs.core.Context final HttpServletRequest request)
      throws AccountApiException {
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);

    final UUID accountId = UUID.fromString(id);

    // Make sure the account exist or we will confuse the history and auditing code
    accountUserApi.getAccountById(accountId, callContext);

    accountUserApi.addEmail(accountId, json.toAccountEmail(UUID.randomUUID()), callContext);

    return uriBuilder.buildResponse(AccountResource.class, "getEmails", json.getAccountId());
  }
Exemple #2
0
  @DELETE
  @Path("/{accountId:" + UUID_PATTERN + "}/" + EMAILS + "/{email}")
  @Produces(APPLICATION_JSON)
  public Response removeEmail(
      @PathParam(ID_PARAM_NAME) final String id,
      @PathParam("email") final String email,
      @HeaderParam(HDR_CREATED_BY) final String createdBy,
      @HeaderParam(HDR_REASON) final String reason,
      @HeaderParam(HDR_COMMENT) final String comment,
      @javax.ws.rs.core.Context final HttpServletRequest request) {
    final UUID accountId = UUID.fromString(id);

    final List<AccountEmail> emails =
        accountUserApi.getEmails(accountId, context.createContext(request));
    for (AccountEmail cur : emails) {
      if (cur.getEmail().equals(email)) {
        final AccountEmailJson accountEmailJson = new AccountEmailJson(accountId.toString(), email);
        final AccountEmail accountEmail = accountEmailJson.toAccountEmail(cur.getId());
        accountUserApi.removeEmail(
            accountId, accountEmail, context.createContext(createdBy, reason, comment, request));
      }
    }
    return Response.status(Status.OK).build();
  }