public ApiException toBadRequestException() { String msg = StringUtils.toDelineatedString("\n", this); return ApiException.badRequest(msg); } }
public Account executeOperation(Account account, CreateAccountAction operation) { if (account != null) { String msg = String.format("The email address \"%s\" already exists.", operation.getEmailAddress()); throw ApiException.badRequest(msg); } account = new Account(operation); store.create(account); return account; }
public Account executeOperation(Account account, LogInAction operation) { if (account == null) { throw ApiException.badRequest(Account.INVALID_USER_NAME_OR_PASSWORD); } if (account.hasTempPassword()) { account.clearTempPassword(); store.update(account); } return account; }
@POST public Response updateClient(@FormParam("domainKey") String domainKey, @FormParam("domainPassword") String domainPassword, @FormParam("retentionDays") int retentionDays) throws Exception { Domain domain = getDomain(); DomainStore domainStore = execContext.getDomainStore(); if (domain.getDomainKey().equals(domainKey) == false && domainStore.getByDomainKey(domainKey) != null) { // The specified name is not the same as the current value but it is already in use by another account. String msg = String.format("The client name %s already exists.", domainKey); throw ApiException.badRequest(msg); } UpdateDomainAction action = new UpdateDomainAction(domainKey, domainPassword, retentionDays); execContext.setLastMessage("Domain configuration changed."); domain.apply(action); domainStore.update(domain); URI uri = execContext.getUriInfo().getBaseUriBuilder().path("manage").path("domain").path(domain.getDomainKey()).build(); return Response.seeOther(uri).build(); }
@POST @Path("/domain") public Response createDomain(@FormParam("domainKey") String domainKey, @FormParam("domainPassword") String domainPassword) throws Exception { if (execContext.getDomainStore().getByDomainKey(domainKey) != null) { throw ApiException.badRequest(String.format("The domain \"%s\" already exists.", domainKey)); } CreateDomainAction action = new CreateDomainAction(execContext.getAccount(), domainKey, domainPassword); Domain domain = execContext.getAccount().add(action); execContext.getDomainStore().create(domain); execContext.getAccountStore().update(execContext.getAccount()); return Response.seeOther(new URI("manage/domain/"+domain.getDomainKey())).build(); } }
public Account executeOperation(Account account, ResetPasswordAction operation) { if (account == null) { throw ApiException.badRequest("The email address was not found."); } String tempPassword = account.createTempPassword(); store.update(account); String message = String.format("<h1 style='margin-top:0'>Password Reset</h1><p>Your temporary password for %s is %s.</p>", account.getEmailAddress(), tempPassword); sendEmail(operation.getTemplateUrl(), account.getEmailAddress(), "Password Reset", message); return account; }
if (errors.isEmpty() == false) { String msg = StringUtils.toDelineatedString("\n", errors); throw ApiException.badRequest(msg);