示例#1
0
  @Override
  public List<Result> getResult(Examination examination, User user) throws DatabaseException {
    List<Result> resultList = null;
    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet rs = null;

    try {
      connection = DBUtility.getConnection();
      statement = connection.prepareStatement(SELECT_BY_EXAM_USER);
      statement.setInt(1, examination.getExaminationId());
      statement.setInt(2, user.getUserId());
      rs = statement.executeQuery();

      resultList = createResultObject(rs);

    } catch (ClassNotFoundException ex) {
      LOG.log(Level.SEVERE, null, ex);
      throw new DatabaseException(ex);
    } catch (SQLException ex) {
      LOG.log(Level.SEVERE, null, ex);
      throw new DatabaseException(ex);
    } finally {
      DBUtility.close(rs);
      DBUtility.close(statement);
      DBUtility.close(connection);
    }

    return resultList;
  }
  private String doOperation(HttpServletRequest request, String operation)
      throws ApplicationException, NumberFormatException {
    String nextPage = "/WEB-INF/jsp/forgotPassword.jsp";

    switch (Integer.parseInt(operation)) {
      case ApplicationConstants.UPDATE_OPERATION:
        String username = request.getParameter("username");
        if (username != null && !username.equals(ApplicationConstants.EMPTY)) {

          // Get user object from the database
          UserService userService = new UserServiceImpl();
          User user = userService.getUser(username);
          if (user != null) {

            // Generate a random password
            String password = RandomPasswordGenerator.generatePassword(6, 8, 3, 2, 1);

            // update user object in database
            user.setPassword(password);

            // Save the details
            userService.saveOrUpdateUser(user);

            OperationStatus status = new OperationStatus(ApplicationConstants.FGT_PWD_SUCCESS_MSG);
            request.setAttribute(ApplicationConstants.FGT_PWD_STATUS, status);
          } else {
            OperationStatus status = new OperationStatus(1, ApplicationConstants.NO_SUCH_USER);
            request.setAttribute(ApplicationConstants.FGT_PWD_STATUS, status);
          }
        }

        break;

      case ApplicationConstants.CANCEL_OPERATION:
        nextPage = "home.htm";
        break;
    }

    return nextPage;
  }