/**
  * Method for redirecting to addUserDetails page on click of Create New Account link.
  *
  * @return void
  */
 public void newUserAccount() {
   final String METHOD_NAME = "newUserAccount()";
   logger.entering(CLASS_NAME, METHOD_NAME);
   RedirectScreen.redirectToPage("/DashBoardPointWeb/pages/user/userRegistration.faces");
   getRenderer().getDataRenderer().setLoginRenderer(true);
   logger.exiting(CLASS_NAME, METHOD_NAME);
 }
  public void applySecurityRestrictionsToScreenComponents() {

    final String METHOD_NAME = "applySecurityRestrictionsToScreenComponents()";
    logger.entering(CLASS_NAME, METHOD_NAME);

    if (getScreenDisplayData().getUserEmailId() != null) {
      logger.debug("tarang getUserId" + getScreenDisplayData().getUserEmailId());
    } else {
      boolean isValid = false;
      // TODO::integration with dashboard point project getting user name and pwd from url

      /* FacesContext context = FacesContext.getCurrentInstance();
      Map<String, String> paramMap = context.getExternalContext().getRequestParameterMap();
      String userId = paramMap.get("userId");
      String userPwd = paramMap.get("userPwd");
      logger.debug("tarang123 userId "+userId+"userPwd "+userPwd);
      if(!(StringValidator.isBlankOrNull(userId))&& !(StringValidator.isBlankOrNull(userPwd))){
      	logger.debug("request parameters are not null and sent for validation ");
      	isValid = validateUser(userId.toUpperCase(),userPwd);
      }*/

      if (!isValid) {
        RedirectScreen.redirectToPage("/DashBoardPointWeb/pages/authentication/login.faces");
      }
    }

    logger.exiting(CLASS_NAME, METHOD_NAME);
  }
 /**
  * This method fetches user details based on Id
  *
  * @param EntityManager entityManager
  * @return UserTable userEntity;
  */
 public List<Object[]> fetchAllUserDetail(EntityManager entityManager) {
   final String METHOD_NAME = "fetchAllUserDetail(EntityManager entityManager)";
   logger.entering(CLASS_NAME, METHOD_NAME);
   List<Object[]> userEntity = FetchAllUserDetailTask.process(entityManager);
   logger.exiting(CLASS_NAME, METHOD_NAME);
   return userEntity;
 }
 /**
  * This method fetches user details based on Id
  *
  * @param EntityManager entityManager
  * @param String userID
  * @return UserTable userEntity;
  */
 public UserTable fetchUserDetail(EntityManager entityManager, int userId) {
   final String METHOD_NAME = "fetchUserDetail(EntityManager entityManager,String userID)";
   logger.entering(CLASS_NAME, METHOD_NAME);
   UserTable userEntity = FetchUserTask.process(entityManager, userId);
   logger.exiting(CLASS_NAME, METHOD_NAME);
   return userEntity;
 }
 /**
  * This method fetches user details based on Email Id
  *
  * @param EntityManager entityManager
  * @param String userID
  * @return UserTable userEntity;
  */
 public UserTable fetchUserByEmailId(EntityManager entityManager, String emailAddress) {
   final String METHOD_NAME =
       "fetchUserByEmailId(EntityManager entityManager,String emailAddress)";
   logger.entering(CLASS_NAME, METHOD_NAME);
   UserTable userEntity = FetchUserByEmailIdTask.process(entityManager, emailAddress);
   logger.exiting(CLASS_NAME, METHOD_NAME);
   return userEntity;
 }
 /**
  * This Method set Error Messages
  *
  * @return void
  */
 public void commonErrorRendering() {
   final String METHOD_NAME = "commonErrorRendering()";
   logger.entering(CLASS_NAME, METHOD_NAME);
   getScreenDisplayData()
       .getMessage()
       .setScreenResponseMessageColor(ApplicationConstants.ERROR_MESSAGE_COLOR);
   getRenderer().getDataRenderer().setUserTextRenderer(true);
   logger.exiting(CLASS_NAME, METHOD_NAME);
 }
  /**
   * This method update a user details
   *
   * @param EntityManager entityManager
   * @param userDetailBO userDetailBO
   * @return true ;
   */
  public boolean updateUser(EntityManager entityManager, UserDetailBO userDetailBO) {
    final String METHOD_NAME = "updateUser(EntityManager entityManager, UserDetailBO userDetailBO)";
    logger.entering(CLASS_NAME, METHOD_NAME);

    UserTable userTable = UserObjectPreparationHelper.convertUserDetailBOToUserEntity(userDetailBO);

    UpdateUserTask.process(entityManager, userTable);
    logger.exiting(CLASS_NAME, METHOD_NAME);
    return true;
  }
  /**
   * Method for redirecting to corresponding pages on click of Header Image.
   *
   * @return void
   */
  public void headerAction() {
    final String METHOD_NAME = "headerAction()";
    logger.entering(CLASS_NAME, METHOD_NAME);

    if ((FacesContext.getCurrentInstance().getViewRoot().getViewId()).contains("login.xhtml")) {
      getRenderer().getDataRenderer().setLoginRenderer(true);
      getRenderer().getDataRenderer().setLogoutRenderer(false);
      RedirectScreen.redirectToPage("/DashBoardPointWeb/pages/authentication/login.faces");
    } else {
      RedirectScreen.redirectToPage("/DashBoardPointWeb/pages/authentication/login.faces");
    }

    logger.exiting(CLASS_NAME, METHOD_NAME);
  }
  @PostConstruct
  public void init() {
    final String METHOD_NAME = "init()";
    logger.entering(CLASS_NAME, METHOD_NAME);
    UserScreenDisplayData screenDisplayData = new UserScreenDisplayData();
    UserRenderer renderer = new UserRenderer();
    setScreenDisplayData(screenDisplayData);
    setRenderer(renderer);

    /* To render Login link in Index page */
    if ((FacesContext.getCurrentInstance().getViewRoot().getViewId()).contains("index.xhtml")) {
      getRenderer().getDataRenderer().setLoginRenderer(true);
    }
    logger.exiting(CLASS_NAME, METHOD_NAME);
  }
  /**
   * Method use for showing multiple Messages on the Screen.
   *
   * @param String textMsg
   * @return void
   */
  public void textScreenMsg(String textMsg) {
    final String METHOD_NAME = "textScreenMsg()";
    logger.entering(CLASS_NAME, METHOD_NAME);

    if (textMsg.equals(null)) {
      this.textMsg = textMsg;
    } else if (this.textMsg == "") {
      this.textMsg = textMsg;
    } else if (this.textMsg == null) {
      this.textMsg = textMsg;
    } else {
      this.textMsg = this.textMsg + " <br/> " + textMsg;
    }
    logger.exiting(CLASS_NAME, METHOD_NAME);
  }
 /**
  * This method fetches user details based on Email Address
  *
  * @param EntityManager entityManager
  * @param String emailAddress
  * @return boolean isProcessSuccess;
  */
 public boolean checkIfEmailAddressExist(EntityManager entityManager, String emailAddress) {
   final String METHOD_NAME =
       "fetchUserByEmailId(EntityManager entityManager, UserDetailBO userDetailBO)";
   logger.entering(CLASS_NAME, METHOD_NAME);
   boolean isProcessSuccess = CheckIfEmailIdExistTask.process(entityManager, emailAddress);
   return isProcessSuccess;
 }
  /**
   * This method creates a user
   *
   * @param EntityManager entityManager
   * @param userDetailBO userDetailBO
   * @param ScreenResponseMessageBO messages
   * @return boolean isProcessSuccess;
   */
  public boolean createUser(EntityManager entityManager, UserDetailBO userDetailBO) {
    final String METHOD_NAME =
        "createUser(EntityManager entityManager, UserDetailBO userDetailBO, ScreenResponseMessageBO messages)";
    logger.entering(CLASS_NAME, METHOD_NAME);

    boolean isProcessSuccess = false;
    UserTable userTable = UserObjectPreparationHelper.convertUserDetailBOToUserEntity(userDetailBO);
    boolean flag = false;
    flag = CheckIfUserExistsTask.process(entityManager, userDetailBO.getUserEmailId());
    if (flag == true) {
      logger.debug("Duplicate user creation");
    } else {
      CreateUserTask.process(entityManager, userTable);
      isProcessSuccess = true;
    }
    logger.exiting(CLASS_NAME, METHOD_NAME);
    return isProcessSuccess;
  }
  /**
   * Method to redirect to appropriate pages on click of links Logout and Login in header and Cancel
   * button in Login page.
   *
   * @param action
   * @return void
   */
  public void logOutCancelAction(String action) {
    final String METHOD_NAME = "logOutCancelAction()";
    logger.entering(CLASS_NAME, METHOD_NAME);

    if (action.equals("login")) {
      /* To invalidate the existing session and create a new session */
      ((HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false))
          .invalidate();
      FacesContext.getCurrentInstance().getExternalContext().getSession(true);

      logger.debug(
          "FacesContext.getCurrentInstance().getExternalContext():::::::::::::::::"
              + FacesContext.getCurrentInstance().getExternalContext());
      RedirectScreen.redirectToPage("/DashBoardPointWeb/pages/authentication/login.faces");
    } else if (action.equals("logout")) {

      /* To invalidate the existing session and create a new session */
      ((HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false))
          .invalidate();
      FacesContext.getCurrentInstance().getExternalContext().getSession(true);

      getRenderer()
          .getDataRenderer()
          .setLogoutRenderer(false); /* To make Logout link in header invisible */
      getRenderer()
          .getDataRenderer()
          .setLoginRenderer(false); /* To make Login link in header invisible */

      RedirectScreen.redirectToPage("/DashBoardPointWeb/index.faces");
    } else if (action.equals("cancel")) {
      getRenderer().getDataRenderer().setLoginRenderer(true);
      // setLogin(true);
      RedirectScreen.redirectToPage("/DashBoardPointWeb/index.faces");
    } else if (action.equals("register")) {
      RedirectScreen.redirectToPage("/DashBoardPointWeb/pages/user/userRegistration.faces");
    }

    logger.exiting(CLASS_NAME, METHOD_NAME);
  }
  /**
   * Method to validate login credentials and to redirect to corresponding pages.
   *
   * @return void
   */
  public void logInAction() {
    final String METHOD_NAME = "logInAction()";
    logger.entering(CLASS_NAME, METHOD_NAME);

    initializeAllScreenMessages();
    getScreenDisplayData().setError(false);
    getScreenDisplayData().getMessage().setScreenResponseMessageForUser("");
    getScreenDisplayData().setUserEmailId(getScreenDisplayData().getUserEmailId().toUpperCase());

    if (StringValidator.isBlankOrNull(getScreenDisplayData().getUserEmailId())) {
      logger.debug("UserId is Blank");
      getScreenDisplayData().setError(true);
      getScreenDisplayData()
          .getMessage()
          .setScreenResponseMessageForUser(
              ErrorMessages.INVALID_USER_ID_OR_INVALID_PASSWORD_MESSAGE);
      commonErrorRendering();
    }

    if (StringValidator.isBlankOrNull(getScreenDisplayData().getUserPassword())) {
      logger.debug("Password is Blank");
      getScreenDisplayData().setError(true);
      getScreenDisplayData()
          .getMessage()
          .setScreenResponseMessageForUser(
              ErrorMessages.INVALID_USER_ID_OR_INVALID_PASSWORD_MESSAGE);
      commonErrorRendering();
    }

    if (getScreenDisplayData().isError() == true) {
      logger.debug("Error: UserID & PassWord is Blanck ");
    } else {
      validateUser(
          getScreenDisplayData().getUserEmailId(), getScreenDisplayData().getUserPassword());
    }

    logger.exiting(CLASS_NAME, METHOD_NAME);
  }
  public boolean validateUser(String userEmailId, String userPwd) {
    final String METHOD_NAME = "validateUser()";
    logger.entering(CLASS_NAME, METHOD_NAME);

    UserDetailBO userDetailBO = new MaintainUserBD().fetchUserByEmailId(userEmailId);
    String deshiperPwd = SecurityUtil.decryptText(userDetailBO.getPassword());

    logger.debug("userId" + userEmailId);
    logger.debug("userPwd " + userPwd);
    logger.debug("userDetailBO.getPassword()" + userDetailBO.getPassword());
    logger.debug("deshiperPwd " + deshiperPwd);
    if (userEmailId.equals(userDetailBO.getUserEmailId()) && userPwd.equals(deshiperPwd)) {

      logger.debug("login Successfull");
      logger.debug("userId after login:"******"password after login:"******"NTVERIFD")) {

        RedirectScreen.redirectToPage("/DashBoardPointWeb/pages/user/userRegistration.faces");
      } else {

        RedirectScreen.redirectToPage("/DashBoardPointWeb/pages/home.faces");
      }

      logger.exiting(CLASS_NAME, METHOD_NAME);
      return true;
    } else {
      if (userDetailBO.getUserEmailId() != userEmailId.toUpperCase()) {
        logger.debug("Invalid UserID");
        getScreenDisplayData()
            .getMessage()
            .setScreenResponseMessageForUser(
                ErrorMessages.INVALID_USER_ID_OR_INVALID_PASSWORD_MESSAGE);
        commonErrorRendering();
      }
      if (userDetailBO.getPassword() != userPwd) {
        logger.debug("Invalid password");
        getScreenDisplayData()
            .getMessage()
            .setScreenResponseMessageForUser(
                ErrorMessages.INVALID_USER_ID_OR_INVALID_PASSWORD_MESSAGE);
        commonErrorRendering();
      }
    }
    logger.exiting(CLASS_NAME, METHOD_NAME);
    return false;
  }
  public AuthenticationBB() {
    logger.entering(CLASS_NAME);

    logger.exiting(CLASS_NAME);
  }
 public void forgotActionListener() {
   final String METHOD_NAME = "forgotActionListener()";
   logger.entering(CLASS_NAME, METHOD_NAME);
   getScreenDisplayData().setPasswordEmailAddress(getScreenDisplayData().getUserEmailId());
   logger.exiting(CLASS_NAME, METHOD_NAME);
 }
  /**
   * This Method Invokes when user forgot UserId Or PassWord, This Method send userId Or PassWord to
   * entered valid Email Address
   *
   * @param String infoNeeded
   * @return void
   */
  public void forgotIdPasswordAction(String infoNeeded) {
    final String METHOD_NAME = "forgotIdPasswordAction()";
    logger.entering(CLASS_NAME, METHOD_NAME);
    initializeAllScreenMessages();
    setTextMsg("");
    getScreenDisplayData().getMessage().setScreenResponseMessageForUser(null);
    getScreenDisplayData().setError(false);
    String tmpEmailId = getEmailToBeUsed(infoNeeded);

    if (infoNeeded.equals("userId")) {
      if (StringValidator.isBlankOrNull(getScreenDisplayData().getUserIdEmailAddress())) {
        logger.debug("Email Address is blanck or null");
        getScreenDisplayData()
            .getMessage()
            .setScreenResponseMessageForUser(
                MessageConstants.ERROR_USER_EMAIL_ADDRESS_BLANK_OR_INVALID);
        commonErrorRendering();
      } else {
        if (EmailUtil.isValidEmailAddress(tmpEmailId)) {
          boolean isSuccess = new MaintainUserBD().checkIfEmailAddressExist(tmpEmailId);
          if (isSuccess == true) {
            logger.debug("Email Address is Valid");
            EmailUtil.sendEmail(
                ("User Id: " + getScreenDisplayData().getUserEmailId()),
                tmpEmailId,
                ErrorMessages.FORGOT_LOGIN_CREDENTIAL_SUBJECT);
            getScreenDisplayData()
                .getMessage()
                .setScreenResponseMessageForUser(ErrorMessages.USER_ID_SENT_TO_EMAIL);
            getScreenDisplayData()
                .getMessage()
                .setScreenResponseMessageColor(ApplicationConstants.SUCCESS_MESSAGE_COLOR);
            getRenderer().getDataRenderer().setUserTextRenderer(true);

          } else {
            logger.debug("Email Address is not Valid");
            getScreenDisplayData()
                .getMessage()
                .setScreenResponseMessageForUser(ErrorMessages.CONTACT_US_INVALID_EMAIL_ADDRESS);
            commonErrorRendering();
          }
        } else {
          logger.debug("Invalid Email Address");
          getScreenDisplayData()
              .getMessage()
              .setScreenResponseMessageForUser(ErrorMessages.INVALID_EMAIL_ADDRESS_FORMAT);
          commonErrorRendering();
        }
      }
    } else if (infoNeeded.equals("password")) {
      if (StringValidator.isBlankOrNull(getScreenDisplayData().getPasswordEmailAddress())) {
        logger.debug("Email Address is blanck or null");
        getScreenDisplayData().setError(true);
        textScreenMsg(MessageConstants.ERROR_USER_EMAIL_ADDRESS_BLANK_OR_INVALID);
        getScreenDisplayData().getMessage().setScreenResponseMessageForUser(getTextMsg());
        commonErrorRendering();
      }

      if (StringValidator.isBlankOrNull(getScreenDisplayData().getPassCheckUserId())) {
        logger.debug("Email Address is blanck or null");
        getScreenDisplayData().setError(true);
        textScreenMsg(MessageConstants.ERROR_USER_PASWWORD_BLANK_OR_INVALID);
        getScreenDisplayData().getMessage().setScreenResponseMessageForUser(getTextMsg());
        commonErrorRendering();
      }

      if (getScreenDisplayData().isError() == true) {

      } else {
        if (EmailUtil.isValidEmailAddress(tmpEmailId)) {
          logger.debug("valid Email Address");
        } else {
          getScreenDisplayData().setError(true);
          logger.debug("Invalid Email Address");
          getScreenDisplayData()
              .getMessage()
              .setScreenResponseMessageForUser(ErrorMessages.INVALID_EMAIL_ADDRESS_FORMAT);
          commonErrorRendering();
        }

        UserDetailBO userDetailBOObject =
            new MaintainUserBD().fetchUserByEmailId(getScreenDisplayData().getPassCheckUserId());

        if (userDetailBOObject.getUserEmailId().equals("")
            || userDetailBOObject.getUserEmailId().equals(null)) {
          logger.debug("Entered userID does not exists");
          getScreenDisplayData().setError(true);
          getScreenDisplayData()
              .getMessage()
              .setScreenResponseMessageForUser(ErrorMessages.INVALID_USER_ID_MESSAGE);
          commonErrorRendering();
        }
        if (getScreenDisplayData().isError() == true) {
          logger.debug("Email Address & UserId are Not Correct");
        } else {
          if (tmpEmailId.equals(userDetailBOObject.getUserId())) {
            logger.debug("Valid Email Address:");
            EmailUtil.sendEmail(
                ("User Id: " + getScreenDisplayData().getPassCheckUserId()),
                tmpEmailId,
                ErrorMessages.FORGOT_LOGIN_CREDENTIAL_SUBJECT);
            getScreenDisplayData()
                .getMessage()
                .setScreenResponseMessageForUser(ErrorMessages.USER_ID_SENT_TO_EMAIL);
            getScreenDisplayData()
                .getMessage()
                .setScreenResponseMessageColor(ApplicationConstants.SUCCESS_MESSAGE_COLOR);
            getRenderer().getDataRenderer().setUserTextRenderer(true);
            logger.debug("UserID sent to Email Address Successfully");
          } else {
            logger.debug("Invalid Email Address");
            getScreenDisplayData()
                .getMessage()
                .setScreenResponseMessageForUser(ErrorMessages.CONTACT_US_INVALID_EMAIL_ADDRESS);
            commonErrorRendering();
          }
        }
      }
    }
    logger.exiting(CLASS_NAME, METHOD_NAME);
    RedirectScreen.redirectToPage("/DashBoardPointWeb/pages/authentication/login.faces");
  }
 /**
  * Method Initializing Screen Messages.
  *
  * @return void
  */
 public void initializeAllScreenMessages() {
   final String METHOD_NAME = "initializeAllScreenMessages()";
   logger.entering(CLASS_NAME, METHOD_NAME);
   getScreenDisplayData().setMessage(new ScreenResponseMessageBO());
   logger.exiting(CLASS_NAME, METHOD_NAME);
 }