예제 #1
0
 public Collection getParentTypeUsers(int userTypeId) {
   Session objSession = null;
   List objList = null;
   try {
     logger.info("GETTING PARENT TYPE USERS");
     objSession = HibernateUtil.getSession();
     Query objQuery =
         objSession.createQuery(
             "select users.userId, users.firstName, users.lastName from UserTypesVO as userTypes, UsersVO as users  where userTypes.userTypeId = ? and userTypes.parentUserType.userTypeId = users.userTypes.userTypeId order by users.firstName");
     objQuery.setInteger(0, userTypeId);
     objList = objQuery.list();
     Iterator itr = objList.iterator();
     objList = new ArrayList();
     while (itr.hasNext()) {
       Object[] innerRow = (Object[]) itr.next();
       UsersVO objUsersVO = new UsersVO();
       objUsersVO.setUserId(String.valueOf(innerRow[0]));
       objUsersVO.setFirstName(String.valueOf(innerRow[1]));
       objUsersVO.setLastName(String.valueOf(innerRow[2]));
       objList.add(objUsersVO);
     }
     logger.info("GET PARENT TYPE USERS ENDS");
   } catch (HibernateException e) {
     logger.error("HIBERNATE EXCEPTION DURING GET PARENT TYPE USERS", e);
     e.printStackTrace();
   } finally {
     if (objSession != null) {
       objSession.close();
     }
   }
   return objList;
 }
예제 #2
0
 public UsersVO getUsers(String userId) throws Exception {
   UsersVO objUsersVO = null;
   Criteria objCriteria = null;
   Session objSession = null;
   try {
     logger.info("GET USER DETAILS OF " + userId);
     objSession = HibernateUtil.getSession();
     objCriteria = objSession.createCriteria(UsersVO.class);
     objCriteria.add(Restrictions.idEq(userId));
     List lstCust = objCriteria.list();
     if (lstCust.size() > 0) {
       objUsersVO = (UsersVO) lstCust.get(0);
       objUsersVO.setPassword(this.decrypt(objUsersVO.getPassword()));
     }
     logger.info("GET USERS ENDS");
   } catch (HibernateException e) {
     logger.error("HIBERNATE EXCEPTION DURING GET A USER", e);
     e.printStackTrace();
     throw new HibernateException(e.toString());
   } catch (Exception e) {
     logger.error("GENERAL EXCEPTION DURING GET A USER", e);
     e.printStackTrace();
     throw new Exception(e.toString());
   } finally {
     if (objSession != null) {
       objSession.close();
     }
   }
   return objUsersVO;
 }
예제 #3
0
 public boolean Authentication(String userId, String password) throws Exception {
   if (BuildConfig.DMODE) System.out.println("USER AUTHENTICATION - STARTS");
   boolean result = false;
   Session objSession = null;
   try {
     logger.info("AUTHENTICATING USER " + userId);
     objSession = HibernateUtil.getSession();
     UsersVO objUsersVO = this.getUsers(userId);
     if (objUsersVO != null && objUsersVO.getPassword().equals(password)) {
       result = true;
       logger.info("USER IS AUTHENTICATED");
     } else {
       logger.info("USER IS NOT AUTHENTICATED");
     }
   } catch (Exception sqle) {
     logger.error("GENERAL EXCEPTION DURING AUTHENTICATE THE USER", sqle);
     sqle.printStackTrace();
     throw new Exception(sqle.toString());
   } finally {
     if (objSession != null) {
       objSession.close();
     }
   }
   return result;
 }
예제 #4
0
 public static void main(String args[]) throws Exception {
   UserDAO usersDAO = new UserDAO();
   List lstResults = usersDAO.getChildPersons("rep", true);
   Iterator ite = lstResults.iterator();
   while (ite.hasNext()) {
     UsersVO objUsersVO = (UsersVO) ite.next();
     System.out.println(objUsersVO.getUserId());
   }
 }
예제 #5
0
 public boolean deleteUser(UsersVO usersVO) throws SQLException {
   boolean updateResult = false;
   Criteria objCriteria = null;
   Session objSession = null;
   List prcCustList = null;
   System.out.println("Inside User delete method");
   try {
     logger.info("DELETING THE USER");
     objSession = HibernateUtil.getSession();
     objSession.beginTransaction();
     objCriteria = objSession.createCriteria(ProspectiveCustomerVO.class);
     objCriteria.add(Restrictions.eq("salesRep.userId", usersVO.getUserId()));
     prcCustList = objCriteria.list();
     System.out.println("List Size :" + prcCustList.size());
     if (prcCustList.size() == 0) {
       System.out.println("Before Deleting UserGroup");
       objSession
           .createQuery(
               "delete from UserGroupVO as userGroupVo where userGroupVo.userVo.userId = ?")
           .setString(0, usersVO.getUserId())
           .executeUpdate();
       System.out.println("after Deleting UserGroup and before Deleting User");
       objSession.delete(usersVO);
       System.out.println("after Deleting User");
       updateResult = true;
     } else {
       throw new PricingException("USER INUSE");
     }
     objSession.getTransaction().commit();
     logger.info("USER IS DELETED");
   } catch (HibernateException e) {
     logger.error("HIBERNATE EXCEPTION DURING DELETE A USER", e);
     e.printStackTrace();
     objSession.getTransaction().rollback();
     throw new HibernateException("");
   } catch (Exception e) {
     logger.error("GENERAL EXCEPTION DURING DELETE A USER", e);
     e.printStackTrace();
     throw new SQLException();
   } finally {
     if (objSession != null) {
       objSession.close();
     }
   }
   return updateResult;
 }
예제 #6
0
  public TeamDetails getTeam(String salesRepuserId) {
    TeamDetails objTeamDetails = new TeamDetails();
    try {
      UserDAO objUserDAO = new UserDAO();
      RolesDAO objRolesDAO = new RolesDAO();
      UsersVO objSalesRep = objUserDAO.getUsers(salesRepuserId);
      String roleName = objRolesDAO.getRoleName(objSalesRep.getUserId());
      UsersVO objSalesManager = null;

      if (roleName.equals("SALES REP")) {
        if (objSalesRep != null) {
          objSalesManager = objSalesRep.getParentUser();
        }
        objTeamDetails.setSalesRep(objSalesRep);
        objTeamDetails.setSalesManager(objSalesManager);
        objTeamDetails.setPricingAnalyst(objSalesManager.getParentUser());
      } else if (roleName.equals("SALES MANAGER")) {
        objTeamDetails.setSalesRep(objSalesRep);
        objTeamDetails.setSalesManager(objSalesRep);
        objSalesManager = objSalesRep;
        objTeamDetails.setPricingAnalyst(objSalesManager.getParentUser());
      } else {
        objTeamDetails.setSalesRep(objSalesRep);
        objTeamDetails.setSalesManager(objSalesRep);
        objTeamDetails.setPricingAnalyst(objSalesRep);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return objTeamDetails;
  }
예제 #7
0
  public boolean addUsers(UsersVO usersVO, RolesVO objRolesVO)
      throws ConstraintViolationException, HibernateException {
    boolean addResult = false;
    Session objSession = null;
    try {
      logger.info("ADDING A NEW USER");
      objSession = HibernateUtil.getSession();
      // To save the user
      objSession.beginTransaction();
      usersVO.setPassword(this.encrypt(usersVO.getPassword()));
      objSession.save(usersVO);
      objSession.getTransaction().commit();

      // To save the Role for that user
      objSession.beginTransaction();
      UserGroupVO objUserGroupVO = new UserGroupVO();
      objUserGroupVO.setUserVo(usersVO);
      objUserGroupVO.setRole(objRolesVO);
      objSession.save(objUserGroupVO);
      objSession.getTransaction().commit();
      addResult = true;
      logger.info("NEW USER ADDED");
    } catch (ConstraintViolationException e) {
      logger.error("CONSTRAINT VIOLATION EXCEPTION DURING ADD A NEW USER", e);
      objSession.getTransaction().rollback();
      throw new ConstraintViolationException(
          "User Id already exist", new SQLException(), usersVO.getUserId());
    } catch (HibernateException e) {
      logger.error("HIBERNATE EXCEPTION DURING ADD A NEW USER", e);
      objSession.getTransaction().rollback();
      e.printStackTrace();
      throw new HibernateException("User does not saved.");
    } finally {
      if (objSession != null) {
        objSession.close();
      }
    }
    return addResult;
  }
예제 #8
0
  public boolean updateUser(UsersVO userVO, RolesVO objRolesVO) {
    boolean updateResult = false;
    Session objSession = null;
    try {
      logger.info("UPDATING THE USER");
      objSession = HibernateUtil.getSession();
      objSession.beginTransaction();
      if (BuildConfig.DMODE) System.out.println("userVO:" + userVO.getUserId());
      userVO.setPassword(this.encrypt(userVO.getPassword()));
      objSession.saveOrUpdate(userVO);
      updateResult = true;
      objSession.getTransaction().commit();

      if (objRolesVO != null) {
        // To update the Role for that user
        objSession.beginTransaction();
        objSession
            .createQuery(
                "delete from UserGroupVO as userGroupVo where userGroupVo.userVo.userId = ?")
            .setString(0, userVO.getUserId())
            .executeUpdate();
        UserGroupVO objUserGroupVO = new UserGroupVO();
        objUserGroupVO.setUserVo(userVO);
        objUserGroupVO.setRole(objRolesVO);
        objSession.save(objUserGroupVO);
        objSession.getTransaction().commit();
      }
      logger.info("USER IS UPDATED");
    } catch (HibernateException e) {
      logger.error("HIBERNATE EXCEPTION DURING UPDATE THE USER", e);
      objSession.getTransaction().rollback();
      e.printStackTrace();
    } finally {
      if (objSession != null) {
        objSession.close();
      }
    }
    return updateResult;
  }