/** * Creates a user deletion request. * * @param httpRequest The HttpServletRequest with the parameters. * @throws InvalidRequestException Thrown if the parameters cannot be parsed. * @throws IOException There was an error reading from the request. */ public UserDeletionRequest(HttpServletRequest httpRequest) throws IOException, InvalidRequestException { super(httpRequest, null, TokenLocation.PARAMETER, null); LOGGER.info("Creating a user deletion request."); Set<String> tUsernames = null; try { tUsernames = UserValidators.validateUsernames(httpRequest.getParameter(InputKeys.USER_LIST)); if (tUsernames == null) { setFailed( ErrorCode.USER_INVALID_USERNAME, "The list of usernames must contain at least one username."); throw new ValidationException("The list of usernames must contain at least one username."); } else if (httpRequest.getParameterValues(InputKeys.USER_LIST).length > 1) { setFailed(ErrorCode.USER_INVALID_USERNAME, "Multiple username parameters were given."); throw new ValidationException("Multiple username parameters were given."); } } catch (ValidationException e) { e.failRequest(this); LOGGER.info(e.toString()); } usernames = tUsernames; }
/** * Creates a new user update request. * * @param httpRequest The HttpServletRequest with the parameters to build this request. * @throws InvalidRequestException Thrown if the parameters cannot be parsed. * @throws IOException There was an error reading from the request. */ public UserUpdateRequest(HttpServletRequest httpRequest) throws IOException, InvalidRequestException { super(httpRequest, null, TokenLocation.PARAMETER, null); LOGGER.info("Creating a user update request."); String tUsername = null; String tEmailAddress = null; Boolean tAdmin = null; Boolean tEnabled = null; Boolean tNewAccount = null; Boolean tCampaignCreationPrivilege = null; String tFirstName = null; String tLastName = null; String tOrganization = null; String tPersonalId = null; boolean tDeletePersonalInfo = false; try { String[] t; t = getParameterValues(InputKeys.USERNAME); if (t.length > 1) { throw new ValidationException( ErrorCode.USER_INVALID_USERNAME, "Multiple username parameters were given: " + InputKeys.USERNAME); } else if (t.length == 1) { tUsername = UserValidators.validateUsername(t[0]); } if ((tUsername == null) || (t.length == 0)) { throw new ValidationException( ErrorCode.USER_INVALID_USERNAME, "The username is missing or not a valid username: "******"Multiple email address parameters were given: " + InputKeys.EMAIL_ADDRESS); } else if (t.length == 1) { tEmailAddress = UserValidators.validateEmailAddress(t[0]); } t = getParameterValues(InputKeys.USER_ADMIN); if (t.length > 1) { throw new ValidationException( ErrorCode.USER_INVALID_ADMIN_VALUE, "Multiple admin parameters were given: " + InputKeys.USER_ADMIN); } else if (t.length == 1) { tAdmin = UserValidators.validateAdminValue(t[0]); } t = getParameterValues(InputKeys.USER_ENABLED); if (t.length > 1) { throw new ValidationException( ErrorCode.USER_INVALID_ENABLED_VALUE, "Multiple enabled parameters were given: " + InputKeys.USER_ENABLED); } else if (t.length == 1) { tEnabled = UserValidators.validateEnabledValue(t[0]); } t = getParameterValues(InputKeys.NEW_ACCOUNT); if (t.length > 1) { throw new ValidationException( ErrorCode.USER_INVALID_NEW_ACCOUNT_VALUE, "Multiple new account parameters were given: " + InputKeys.NEW_ACCOUNT); } else if (t.length == 1) { tNewAccount = UserValidators.validateNewAccountValue(t[0]); } t = getParameterValues(InputKeys.CAMPAIGN_CREATION_PRIVILEGE); if (t.length > 1) { throw new ValidationException( ErrorCode.USER_INVALID_CAMPAIGN_CREATION_PRIVILEGE, "Multiple campaign creation privilege parameters were given: " + InputKeys.CAMPAIGN_CREATION_PRIVILEGE); } else if (t.length == 1) { tCampaignCreationPrivilege = UserValidators.validateCampaignCreationPrivilegeValue(t[0]); } t = getParameterValues(InputKeys.FIRST_NAME); if (t.length > 1) { throw new ValidationException( ErrorCode.USER_INVALID_FIRST_NAME_VALUE, "Multiple first name parameters were given: " + InputKeys.FIRST_NAME); } else if (t.length == 1) { tFirstName = UserValidators.validateFirstName(t[0]); } t = getParameterValues(InputKeys.LAST_NAME); if (t.length > 1) { throw new ValidationException( ErrorCode.USER_INVALID_LAST_NAME_VALUE, "Multiple last name parameters were given: " + InputKeys.LAST_NAME); } else if (t.length == 1) { tLastName = UserValidators.validateLastName(t[0]); } t = getParameterValues(InputKeys.ORGANIZATION); if (t.length > 1) { throw new ValidationException( ErrorCode.USER_INVALID_ORGANIZATION_VALUE, "Multiple organization parameters were given: " + InputKeys.ORGANIZATION); } else if (t.length == 1) { tOrganization = UserValidators.validateOrganization(t[0]); } t = getParameterValues(InputKeys.PERSONAL_ID); if (t.length > 1) { throw new ValidationException( ErrorCode.USER_INVALID_PERSONAL_ID_VALUE, "Multiple personal ID parameters were given: " + InputKeys.PERSONAL_ID); } else if (t.length == 1) { tPersonalId = UserValidators.validatePersonalId(t[0]); } t = getParameterValues(InputKeys.USER_DELETE_PERSONAL_INFO); if (t.length > 1) { throw new ValidationException( ErrorCode.USER_INVALID_DELETE_PERSONAL_INFO, "Multiple delete personal info parameters were given: " + InputKeys.USER_DELETE_PERSONAL_INFO); } else if (t.length == 1) { tDeletePersonalInfo = UserValidators.validateDeletePersonalInfo(t[0]); } } catch (ValidationException e) { e.failRequest(this); e.logException(LOGGER); } username = tUsername; emailAddress = tEmailAddress; admin = tAdmin; enabled = tEnabled; newAccount = tNewAccount; campaignCreationPrivilege = tCampaignCreationPrivilege; firstName = tFirstName; lastName = tLastName; organization = tOrganization; personalId = tPersonalId; deletePersonalInfo = tDeletePersonalInfo; }