Ejemplo n.º 1
0
 private void updateSchoolCache(SchoolAccount accnt) {
   cacheManager
       .getCache(CacheVariables.CACHE_SCHOOL_ACCOUNTS_BY_USERNAME)
       .put(new Element(accnt.getUsername(), accnt));
   cacheManager
       .getCache(CacheVariables.CACHE_ACCOUNTS_BY_UUID)
       .put(new Element(accnt.getUuid(), accnt));
 }
Ejemplo n.º 2
0
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    HttpSession session = request.getSession(true);

    String schoolname = StringUtils.trimToEmpty(request.getParameter("schoolname"));
    String schoolusername = StringUtils.trimToEmpty(request.getParameter("username"));
    String schoolphone = StringUtils.trimToEmpty(request.getParameter("mobile"));
    String schoolemail = StringUtils.trimToEmpty(request.getParameter("email"));
    String dayBoarding = StringUtils.trimToEmpty(request.getParameter("dayBoarding"));
    String schooluuid = StringUtils.trimToEmpty(request.getParameter("schooluuid"));
    String schoolpostaladdress = StringUtils.trimToEmpty(request.getParameter("postaladdress"));
    String schoolhometown = StringUtils.trimToEmpty(request.getParameter("hometown"));

    if (StringUtils.isBlank(schoolname)) {
      session.setAttribute(
          AdminSessionConstants.SCHOOL_ACCOUNT_UPDATE_ERROR, ERROR_EMPTY_SCHOOL_NAME);

    } else if (!Wordlength(schoolname)) {
      session.setAttribute(AdminSessionConstants.SCHOOL_ACCOUNT_UPDATE_ERROR, NAME_ERROR);

    } else if (StringUtils.isBlank(schoolusername)) {
      session.setAttribute(
          AdminSessionConstants.SCHOOL_ACCOUNT_UPDATE_ERROR, ERROR_EMPTY_SCHOOL_USERNAME);

    } else if (!Wordlength(schoolusername)) {
      session.setAttribute(AdminSessionConstants.SCHOOL_ACCOUNT_UPDATE_ERROR, NAME_ERROR);

    } else if (StringUtils.isBlank(schoolphone)) {
      session.setAttribute(
          AdminSessionConstants.SCHOOL_ACCOUNT_UPDATE_ERROR, ERROR_EMPTY_SCHOOL_PHONE);

    } else if (!isNumeric(schoolphone)) {
      session.setAttribute(AdminSessionConstants.SCHOOL_ACCOUNT_UPDATE_ERROR, ERROR_PHONE_NUMERIC);

    } else if (!lengthValid(schoolphone)) {
      session.setAttribute(AdminSessionConstants.SCHOOL_ACCOUNT_UPDATE_ERROR, ERROR_PHONE_INVALID);

    } else if (StringUtils.isBlank(schoolemail)) {
      session.setAttribute(
          AdminSessionConstants.SCHOOL_ACCOUNT_UPDATE_ERROR, ERROR_EMPTY_SCHOOL_EMAIL);

    } else if (StringUtils.isBlank(dayBoarding)) {
      session.setAttribute(
          AdminSessionConstants.SCHOOL_ACCOUNT_UPDATE_ERROR, ERROR_EMPTY_SCHOOL_DB);

    } else if (!emailValidator.isValid(schoolemail)) {
      session.setAttribute(AdminSessionConstants.SCHOOL_ACCOUNT_UPDATE_ERROR, ERROR_INVALID_EMAIL);

    } else if (StringUtils.isBlank(schoolpostaladdress)) {
      session.setAttribute(
          AdminSessionConstants.SCHOOL_ACCOUNT_UPDATE_ERROR, ERROR_EMPTY_POSTAL_ADDRESS);

    } else if (StringUtils.isBlank(schoolhometown)) {
      session.setAttribute(AdminSessionConstants.SCHOOL_ACCOUNT_UPDATE_ERROR, ERROR_EMPTY_TOWN);

    } else if (!Wordlength(schoolhometown)) {
      session.setAttribute(AdminSessionConstants.SCHOOL_ACCOUNT_UPDATE_ERROR, NAME_ERROR);

    } else if (StringUtils.isBlank(schooluuid)) {
      session.setAttribute(
          AdminSessionConstants.SCHOOL_ACCOUNT_UPDATE_ERROR, ERROR_UNEXPECTED_ERROR);

    } else {

      SchoolAccount account = accountDAO.get(schooluuid);

      account.setSchoolName(schoolname);
      account.setUsername(schoolusername);
      account.setMobile(schoolphone);
      account.setEmail(schoolemail);
      account.setDayBoarding(dayBoarding);
      account.setPostalAddress(schoolpostaladdress);
      account.setTown(schoolhometown);

      if (accountDAO.update(account)) {
        session.setAttribute(
            AdminSessionConstants.SCHOOL_ACCOUNT_UPDATE_SUCCESS, SCHOOL_UPDATE_SUCCESS);
        session.setAttribute(SessionConstants.SCHOOL_ACCOUNT_SIGN_IN_KEY, schoolusername);
        updateSchoolCache(account);
      } else {
        session.setAttribute(
            AdminSessionConstants.SCHOOL_ACCOUNT_UPDATE_ERROR, SCHOOL_UPDATE_ERROR);
      }
    }

    response.sendRedirect("adminIndex.jsp");
    return;
  }