private UserVO userPojoToVo(NdgUser user) { UserVO vo = new UserVO(); RoleVO roleVO = new RoleVO(); roleVO.setName(user.getRole().getRoleName()); vo.setRole(roleVO); CompanyVO companyVO = new CompanyVO(); companyVO.setCompanyName(user.getCompany().getCompanyName()); companyVO.setCompanyType(user.getCompany().getCompanyType()); companyVO.setCompanyCountry(user.getCompany().getCompanyCountry()); companyVO.setCompanyIndustry(user.getCompany().getCompanyIndustry()); companyVO.setCompanySize(user.getCompany().getCompanySize()); vo.setCompany(companyVO); vo.setUsername(user.getUsername()); vo.setPassword(user.getPassword()); vo.setFirstName(user.getFirstName()); vo.setLastName(user.getLastName()); vo.setEmail(user.getEmail()); vo.setUserAdmin(user.getUserAdmin()); vo.setCountryCode(user.getCountryCode()); vo.setAreaCode(user.getAreaCode()); vo.setPhoneNumber(user.getPhoneNumber()); vo.setRetCode(UserVO.AUTHENTICATED); vo.setUserValidated(user.getUserValidated()); vo.setValidationKey(user.getValidationKey()); vo.setHasFullPermissions(user.getHasFullPermissions()); return vo; }
public UserVO validateLogin(String username, String password) throws MSMApplicationException { NdgUser user = findNdgUserByName(username); UserVO vo = new UserVO(); if (user != null) { try { if (user.getPassword().equals(MD5.createMD5(password))) { if ((user.getUserValidated() == 'y' || user.getUserValidated() == 'Y')) { vo = userPojoToVo(user); vo.setRetCode(UserVO.AUTHENTICATED); vo.setFirstTimeUse(user.getFirstTimeUse()); try { NdgUser userAdmin = findNdgUserByName(user.getUserAdmin()); vo.setHasFullPermissions(userAdmin.getHasFullPermissions()); } catch (Exception e) { log.error("validateLogin: userAdmin not found - admin = " + user.getUserAdmin()); } Query query = manager.createNamedQuery("userbalance.findByUserAdmin"); query.setParameter("useradmin", user.getUserAdmin()); UserBalance userAdminBalance = null; try { userAdminBalance = (UserBalance) query.getSingleResult(); } catch (Exception e) { log.info("New user: "******"LIMIT_IMEIS"))); initialUserBalance.setResults( Integer.parseInt(properties.getProperty("LIMIT_RESULTS"))); initialUserBalance.setSendAlerts( Integer.parseInt(properties.getProperty("LIMIT_SEND_ALERTS"))); initialUserBalance.setSurveys( Integer.parseInt(properties.getProperty("LIMIT_SURVEYS"))); initialUserBalance.setUser(findNdgUserByName(user.getUserAdmin())); initialUserBalance.setUsers(Integer.parseInt(properties.getProperty("LIMIT_USER"))); } catch (Exception e) { initialUserBalance.setImeis(0); initialUserBalance.setResults(0); initialUserBalance.setSendAlerts(0); initialUserBalance.setSurveys(0); initialUserBalance.setUser(findNdgUserByName(user.getUserAdmin())); initialUserBalance.setUsers(0); } UserBalanceVO balanceVO = new UserBalanceVO(); balanceVO.setImeis(initialUserBalance.getImeis()); balanceVO.setResults(initialUserBalance.getResults()); balanceVO.setSendAlerts(initialUserBalance.getSendAlerts()); balanceVO.setSurveys(initialUserBalance.getSurveys()); balanceVO.setUsers(initialUserBalance.getUsers()); vo.setUserBalance(balanceVO); manager.persist(initialUserBalance); } else { UserBalanceVO balanceVO = new UserBalanceVO(); balanceVO.setImeis(userAdminBalance.getImeis()); balanceVO.setResults(userAdminBalance.getResults()); balanceVO.setSendAlerts(userAdminBalance.getSendAlerts()); balanceVO.setSurveys(userAdminBalance.getSurveys()); balanceVO.setUsers(userAdminBalance.getUsers()); vo.setUserBalance(balanceVO); } } else { vo.setRetCode(UserVO.EMAIL_NOT_VALIDATED); throw new UserEmailNotValidatedException(); } } else { vo.setRetCode(UserVO.INVALID_PASSWORD); throw new InvalidPasswordException(); } } catch (NoSuchAlgorithmException e) { throw new InvalidPasswordGenerationException(); } } else { vo.setRetCode(UserVO.INVALID_USERNAME); throw new InvalidUsernameException(); } return vo; }
public QueryInputOutputVO listAllUsers(String userAdmin, QueryInputOutputVO queryIOVO) throws MSMApplicationException { if (queryIOVO == null) { queryIOVO = new QueryInputOutputVO(); } String sqlCommand = "SELECT U FROM NdgUser U WHERE userAdmin like '" + userAdmin + "'"; if ((queryIOVO.getFilterText() != null) && (queryIOVO.getFilterFields() != null)) { sqlCommand += SqlUtil.getFilterCondition(queryIOVO.getFilterText(), queryIOVO.getFilterFields()); } if ((queryIOVO.getSortField() != null) && (queryIOVO.getIsDescending() != null)) { sqlCommand += SqlUtil.getSortCondition(queryIOVO.getSortField(), queryIOVO.getIsDescending()); } Query q = manager.createQuery(sqlCommand); queryIOVO.setRecordCount(q.getResultList().size()); if ((queryIOVO.getPageNumber() != null) && (queryIOVO.getRecordsPerPage() != null)) { q.setFirstResult((queryIOVO.getPageNumber() - 1) * queryIOVO.getRecordsPerPage()); q.setMaxResults(queryIOVO.getRecordsPerPage()); } ArrayList<Object> ret = new ArrayList<Object>(); ArrayList<NdgUser> al = (ArrayList<NdgUser>) q.getResultList(); if (al.isEmpty()) { throw new UserNotFoundException(); } else { Iterator<NdgUser> it = al.iterator(); while (it.hasNext()) { NdgUser user = it.next(); UserVO vo = new UserVO(); RoleVO roleVO = new RoleVO(); roleVO.setName(user.getRole().getRoleName()); vo.setRole(roleVO); CompanyVO companyVO = new CompanyVO(); companyVO.setCompanyName(user.getCompany().getCompanyName()); companyVO.setCompanyCountry(user.getCompany().getCompanyCountry()); companyVO.setCompanyIndustry(user.getCompany().getCompanyIndustry()); companyVO.setCompanySize(user.getCompany().getCompanySize()); companyVO.setCompanyType(user.getCompany().getCompanyType()); companyVO.setIdCompany(user.getCompany().getIdCompany()); vo.setCompany(companyVO); vo.setUsername(user.getUsername()); vo.setEmail(user.getEmail()); vo.setFirstName(user.getFirstName()); vo.setLastName(user.getLastName()); vo.setPassword(user.getPassword()); vo.setCountryCode(user.getCountryCode()); vo.setAreaCode(user.getAreaCode()); vo.setPhoneNumber(user.getPhoneNumber()); vo.setUserAdmin(user.getUserAdmin()); vo.setUserValidated(user.getUserValidated()); ret.add(vo); } queryIOVO.setQueryResult(ret); } return queryIOVO; }