protected void processRequest() throws Exception {
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());

    FormProcessor fp = new FormProcessor(request);
    int userId = fp.getInt(ARG_USERID);
    int action = fp.getInt(ARG_ACTION);

    UserAccountBean u = (UserAccountBean) udao.findByPK(userId);

    String message;
    if (!u.isActive()) {
      message = respage.getString("the_specified_user_not_exits");
    } else if (!EntityAction.contains(action)) {
      message = respage.getString("the_specified_action_on_the_user_is_invalid");
    } else if (!EntityAction.get(action).equals(EntityAction.DELETE)
        && !EntityAction.get(action).equals(EntityAction.RESTORE)) {
      message = respage.getString("the_specified_action_is_not_allowed");
    } else {
      EntityAction desiredAction = EntityAction.get(action);
      u.setUpdater(ub);

      if (desiredAction.equals(EntityAction.DELETE)) {
        udao.delete(u);

        if (udao.isQuerySuccessful()) {
          message = respage.getString("the_user_has_been_deleted");
          // YW 07-31-2007 << for feature that deletion doesn't need email the deleted user.
          /*
          //YW 07-26-2007 << catch exception (eg. timeout) and inform users.
          try {
          	sendDeleteEmail(u);
          } catch (Exception e) {
          	message += "  However, there has been an error sending the user an email regarding this deletion.";
          }
          */
          // YW >>
        } else {
          message = respage.getString("the_user_could_not_be_deleted_due_database_error");
        }
      } else {
        SecurityManager sm = SecurityManager.getInstance();
        String password = sm.genPassword();
        String passwordHash = sm.encrytPassword(password);

        u.setPasswd(passwordHash);
        u.setPasswdTimestamp(null);

        udao.restore(u);

        if (udao.isQuerySuccessful()) {
          message = respage.getString("the_user_has_been_restored");

          try {
            sendRestoreEmail(u, password);
          } catch (Exception e) {
            message += respage.getString("however_was_error_sending_user_email_regarding");
          }
        } else {
          message = respage.getString("the_user_could_not_be_deleted_due_database_error");
        }
      }
    }

    addPageMessage(message);
    forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
  }
  protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);

    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    addEntityList(
        "studies",
        sdao.findAll(),
        "A user cannot be created, because there is no study to set as an active study for the user.",
        Page.ADMIN_SYSTEM);
    addEntityList(
        "roles",
        getRoles(),
        "A user cannot be created, because there are no roles to set as a role within the active study for the user.",
        Page.ADMIN_SYSTEM);

    ArrayList types = UserType.toArrayList();
    types.remove(UserType.INVALID);
    if (!ub.isTechAdmin()) {
      types.remove(UserType.TECHADMIN);
    }
    addEntityList(
        "types",
        types,
        "A user cannot be created, because there are no user types within the active study for the user.",
        Page.ADMIN_SYSTEM);

    if (!fp.isSubmitted()) {
      forwardPage(Page.CREATE_ACCOUNT);
    } else {
      UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
      Validator v = new Validator(request);

      // username must not be blank,
      // must be in the format specified by Validator.USERNAME,
      // and must be unique
      v.addValidation(INPUT_USERNAME, Validator.NO_BLANKS);
      v.addValidation(
          INPUT_USERNAME,
          Validator.LENGTH_NUMERIC_COMPARISON,
          NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,
          64);
      v.addValidation(INPUT_USERNAME, Validator.IS_A_USERNAME);

      v.addValidation(INPUT_USERNAME, Validator.USERNAME_UNIQUE, udao);

      v.addValidation(INPUT_FIRST_NAME, Validator.NO_BLANKS);
      v.addValidation(INPUT_LAST_NAME, Validator.NO_BLANKS);
      v.addValidation(
          INPUT_FIRST_NAME,
          Validator.LENGTH_NUMERIC_COMPARISON,
          NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,
          50);
      v.addValidation(
          INPUT_LAST_NAME,
          Validator.LENGTH_NUMERIC_COMPARISON,
          NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,
          50);

      v.addValidation(INPUT_EMAIL, Validator.NO_BLANKS);
      v.addValidation(
          INPUT_EMAIL,
          Validator.LENGTH_NUMERIC_COMPARISON,
          NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,
          120);
      v.addValidation(INPUT_EMAIL, Validator.IS_A_EMAIL);

      v.addValidation(INPUT_INSTITUTION, Validator.NO_BLANKS);
      v.addValidation(
          INPUT_INSTITUTION,
          Validator.LENGTH_NUMERIC_COMPARISON,
          NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,
          255);

      v.addValidation(INPUT_STUDY, Validator.ENTITY_EXISTS, sdao);
      v.addValidation(INPUT_ROLE, Validator.IS_VALID_TERM, TermType.ROLE);

      HashMap errors = v.validate();

      if (errors.isEmpty()) {
        UserAccountBean createdUserAccountBean = new UserAccountBean();
        createdUserAccountBean.setName(fp.getString(INPUT_USERNAME));
        createdUserAccountBean.setFirstName(fp.getString(INPUT_FIRST_NAME));
        createdUserAccountBean.setLastName(fp.getString(INPUT_LAST_NAME));
        createdUserAccountBean.setEmail(fp.getString(INPUT_EMAIL));
        createdUserAccountBean.setInstitutionalAffiliation(fp.getString(INPUT_INSTITUTION));

        SecurityManager secm = SecurityManager.getInstance();
        String password = secm.genPassword();
        String passwordHash = secm.encrytPassword(password);

        createdUserAccountBean.setPasswd(passwordHash);

        createdUserAccountBean.setPasswdTimestamp(null);
        createdUserAccountBean.setLastVisitDate(null);

        createdUserAccountBean.setStatus(Status.AVAILABLE);
        createdUserAccountBean.setPasswdChallengeQuestion("");
        createdUserAccountBean.setPasswdChallengeAnswer("");
        createdUserAccountBean.setPhone("");
        createdUserAccountBean.setOwner(ub);

        int studyId = fp.getInt(INPUT_STUDY);
        Role r = Role.get(fp.getInt(INPUT_ROLE));
        createdUserAccountBean = addActiveStudyRole(createdUserAccountBean, studyId, r);
        UserType type = UserType.get(fp.getInt("type"));
        logger.warning("*** found type: " + fp.getInt("type"));
        logger.warning("*** setting type: " + type.getDescription());
        createdUserAccountBean.addUserType(type);
        createdUserAccountBean = (UserAccountBean) udao.create(createdUserAccountBean);
        String displayPwd = fp.getString(INPUT_DISPLAY_PWD);

        if (createdUserAccountBean.isActive()) {
          addPageMessage(
              "The user account \""
                  + createdUserAccountBean.getName()
                  + "\" was created successfully. ");
          if ("no".equalsIgnoreCase(displayPwd)) {
            try {
              sendNewAccountEmail(createdUserAccountBean, password);
            } catch (Exception e) {
              addPageMessage(
                  "There was an error sending the account-creating email.  Please contact the user directly regarding account creation.  You may reset the user's password by editing the user's account.");
            }
          } else {
            addPageMessage(
                "User Password: "******". Please write down the password and provide it directly to the user.");
          }
        } else {
          addPageMessage(
              "The user account \""
                  + createdUserAccountBean.getName()
                  + "\" could not be created due to a database error.");
        }
        if (createdUserAccountBean.isActive()) {
          request.setAttribute(
              ViewUserAccountServlet.ARG_USER_ID,
              new Integer(createdUserAccountBean.getId()).toString());
          forwardPage(Page.VIEW_USER_ACCOUNT_SERVLET);
        } else {
          forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
        }
      } else {
        String textFields[] = {
          INPUT_USERNAME,
          INPUT_FIRST_NAME,
          INPUT_LAST_NAME,
          INPUT_EMAIL,
          INPUT_INSTITUTION,
          INPUT_DISPLAY_PWD
        };
        fp.setCurrentStringValuesAsPreset(textFields);

        String ddlbFields[] = {INPUT_STUDY, INPUT_ROLE, INPUT_TYPE};
        fp.setCurrentIntValuesAsPreset(ddlbFields);

        HashMap presetValues = fp.getPresetValues();
        setPresetValues(presetValues);

        setInputMessages(errors);
        addPageMessage("There were some errors in your submission.  See below for details.");

        forwardPage(Page.CREATE_ACCOUNT);
      }
    }
  }