public void updateUserAdminBalance(Integer balanceItem, String loggedUser) { String ndgMode = null; if (properties.containsKey("NDG_MODE")) { ndgMode = properties.getProperty("NDG_MODE"); } char userAdminHasFullPermission = 'N'; try { userAdminHasFullPermission = findNdgUserByName(findNdgUserByName(loggedUser).getUserAdmin()).getHasFullPermissions(); } catch (MSMApplicationException e) { e.printStackTrace(); } try { if ("hosted".equals(ndgMode)) { if (!((userAdminHasFullPermission == 'y') || (userAdminHasFullPermission == 'Y'))) { NdgUser onlineUser = findNdgUserByName(loggedUser); Query query = manager.createNamedQuery("userbalance.findByUserAdmin"); query.setParameter("useradmin", onlineUser.getUserAdmin()); UserBalance userBalance = (UserBalance) query.getSingleResult(); if (balanceItem.intValue() == UserVO.USER_LIMIT.intValue()) { userBalance.setUsers(userBalance.getUsers() - 1); } else if (balanceItem.intValue() == UserVO.IMEI_LIMIT.intValue()) { userBalance.setImeis(userBalance.getImeis() - 1); } else if (balanceItem.intValue() == UserVO.ALERT_LIMIT.intValue()) { userBalance.setSendAlerts(userBalance.getSendAlerts() - 1); } else if (balanceItem.intValue() == UserVO.RESULT_LIMIT.intValue()) { userBalance.setResults(userBalance.getResults() - 1); } else if (balanceItem.intValue() == UserVO.SURVEY_LIMIT.intValue()) { userBalance.setSurveys(userBalance.getSurveys() - 1); } manager.persist(userBalance); } } } catch (MSMApplicationException e) { e.printStackTrace(); } }
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; }