} catch (IllegalArgumentException e) { String errorMessage = "Invalid Location specified, please specify a location in URI format."; throw new RobotRegistrationException(errorMessage + " " + e.getLocalizedMessage(), e);
/** * Handles POST request for the register page. */ private void doRegisterPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { String username = req.getParameter("username"); String location = req.getParameter("location"); if (Strings.isNullOrEmpty(username) || Strings.isNullOrEmpty(location)) { doRegisterGet(req, resp, "Please complete all fields."); return; } ParticipantId id; try { id = ParticipantId.of(username + "@" + domain); } catch (InvalidParticipantAddress e) { doRegisterGet(req, resp, "Invalid username specified, use alphanumeric characters only."); return; } RobotAccountData robotAccount; try{ robotAccount = robotRegistrar.registerNew(id, location); } catch (RobotRegistrationException e) { doRegisterGet(req, resp, e.getMessage()); return; } catch (PersistenceException e) { LOG.severe("Failed to retrieve account data for " + id, e); doRegisterGet(req, resp, "Failed to retrieve account data for " + id.getAddress()); return; } onRegisterSuccess(req, resp, robotAccount); }
/** * Ensures that the account belongs to a robot. * * @param existingAccount the account to check. * @throws RobotRegistrationException if the account is not robot. */ private void throwExceptionIfNotRobot(AccountData existingAccount) throws RobotRegistrationException { if (!existingAccount.isRobot()) { throw new RobotRegistrationException(existingAccount.getId().getAddress() + " is not a robot account!"); } }
@Override public RobotAccountData registerNew(ParticipantId robotId, String location) throws RobotRegistrationException, PersistenceException { Preconditions.checkNotNull(robotId); Preconditions.checkNotNull(location); Preconditions.checkArgument(!location.isEmpty()); if (accountStore.getAccount(robotId) != null) { throw new RobotRegistrationException(robotId.getAddress() + " is already in use, please choose another one."); } return registerRobot(robotId, location); }