public QueryInputOutputVO listAllImeis( String username, QueryInputOutputVO queryIOVO, boolean withFakeImeis) throws MSMApplicationException { NdgUser userLogged = findNdgUserByName(username); QueryInputOutputVO queryIOVOOutput = imeiManager.listAllImeis(userLogged.getUserAdmin(), queryIOVO, withFakeImeis); return queryIOVOOutput; }
public SurveyXML loadSurveyAndResultsDB(String username, String idSurvey) throws MSMApplicationException, MSMSystemException { NdgUser userLogged = findNdgUserByName(username); SurveyXML surveyXML = surveyHandler.loadSurveyAndResultsDB(userLogged.getUserAdmin(), idSurvey); return surveyXML; }
public void saveSettingsFromEditorToServer(String userName, String settingsContent) throws MSMApplicationException { NdgUser user = findNdgUserByName(userName); if (user != null) { user.setEditorSettings(settingsContent); manager.persist(user); } }
public void createIMEI(ImeiVO imeiVO) throws MSMApplicationException { NdgUser userLogged = findNdgUserByName(imeiVO.getUserName()); if (userManager.userAdminHasPositiveBalance(UserVO.IMEI_LIMIT, userLogged.getUserAdmin())) { imeiManager.createIMEI(imeiVO); sendDynamicJad(imeiVO.getMsisdn(), imeiVO.getImei()); } else { throw new ImeiLimitReachedException(); } userManager.updateUserAdminBalance(UserVO.IMEI_LIMIT, userLogged.getUserAdmin()); }
public void updateUserPassword(UserVO userToUpdate) throws MSMApplicationException { NdgUser user = findNdgUserByName(userToUpdate.getUsername()); if (userToUpdate.getPassword() != null) { try { user.setPassword(MD5.createMD5(userToUpdate.getPassword())); user.setUserValidated('Y'); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } } }
public boolean userAdminHasPositiveBalance(Integer balanceItem, String loggedUser) { boolean hasPositiveBalance = false; 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(); } if (!("hosted".equals(ndgMode)) || (userAdminHasFullPermission == 'Y') || (userAdminHasFullPermission == 'y')) { hasPositiveBalance = true; } else { NdgUser onlineUser = null; try { onlineUser = findNdgUserByName(loggedUser); } catch (MSMApplicationException e) { e.printStackTrace(); } Query query = manager.createNamedQuery("userbalance.findByUserAdmin"); query.setParameter("useradmin", onlineUser.getUserAdmin()); try { UserBalance userBalance = (UserBalance) query.getSingleResult(); if (balanceItem.intValue() == UserVO.USER_LIMIT.intValue()) { hasPositiveBalance = (userBalance.getUsers() > 0); } else if (balanceItem.intValue() == UserVO.IMEI_LIMIT.intValue()) { hasPositiveBalance = (userBalance.getImeis() > 0); } else if (balanceItem.intValue() == UserVO.ALERT_LIMIT.intValue()) { hasPositiveBalance = (userBalance.getSendAlerts() > 0); } else if (balanceItem.intValue() == UserVO.RESULT_LIMIT.intValue()) { hasPositiveBalance = (userBalance.getResults() > 0); } else if (balanceItem.intValue() == UserVO.SURVEY_LIMIT.intValue()) { hasPositiveBalance = (userBalance.getSurveys() > 0); } } catch (Exception e) { hasPositiveBalance = false; } } return hasPositiveBalance; }
public void updateUser(UserVO userToUpdate) throws MSMApplicationException { NdgUser user = findNdgUserByName(userToUpdate.getUsername()); if (user != null) { if (userToUpdate.getFirstName() != null) { user.setFirstName(userToUpdate.getFirstName()); } if (userToUpdate.getLastName() != null) { user.setLastName(userToUpdate.getLastName()); } if (userToUpdate.getEmail() != null) { user.setEmail(userToUpdate.getEmail()); } if (userToUpdate.getCountryCode() != null) { user.setCountryCode(userToUpdate.getCountryCode()); } if (userToUpdate.getAreaCode() != null) { user.setAreaCode(userToUpdate.getAreaCode()); } if (userToUpdate.getPhoneNumber() != null) { user.setPhoneNumber(userToUpdate.getPhoneNumber()); } if (userToUpdate.getRole() != null) { NdgRole role = findNdgRoleByName(userToUpdate.getRole().getName()); if (role != null) { user.setRole(role); } } if (userToUpdate.getPassword() != null) { try { user.setPassword(MD5.createMD5(userToUpdate.getPassword())); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } } user.setFirstTimeUse(userToUpdate.getFirstTimeUse()); // if (userToUpdate.getHasFullPermissions() == 'y' || // userToUpdate.getHasFullPermissions() == 'Y') { // user.setHasFullPermissions(userToUpdate.getHasFullPermissions()); // } // user.setFirstTimeUse(userToUpdate.getFirstTimeUse()); manager.merge(user); } else { throw new UserNotFoundException(); } }
public QueryInputOutputVO listAllUsers(String username, QueryInputOutputVO queryIOVO) throws MSMApplicationException { QueryInputOutputVO queryIOVOOutput = new QueryInputOutputVO(); if (username != null) { NdgUser userLogged = findNdgUserByName(username); if (userLogged != null) { queryIOVOOutput = userManager.listAllUsers(userLogged.getUserAdmin(), queryIOVO); } } else { throw new UserUnknownException(); } return queryIOVOOutput; }
public UserVO checkValidationKey(String validationKey) throws MSMApplicationException { Query query = manager.createNamedQuery("user.findByvalidationKey"); query.setParameter("userValidationKey", validationKey); NdgUser user = null; UserVO vo = null; try { user = (NdgUser) query.getSingleResult(); if (user.getUserValidated() == 'n' || user.getUserValidated() == 'N') { user.setUserValidated('Y'); manager.merge(user); } vo = userPojoToVo(user); } catch (NoResultException e) { throw new UserNotFoundException(); } return vo; }
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 void postSurvey( String user, StringBuffer surveyBuffered, TransactionLogVO postSurveyTransaction, Boolean isValidateLogin) throws MSMApplicationException, MSMSystemException, SurveyFileAlreadyExistsException { NdgUser userLogged = findNdgUserByName(user); if (!isValidateLogin) { if (userManager.userAdminHasPositiveBalance(UserVO.SURVEY_LIMIT, userLogged.getUserAdmin())) { surveyHandler.postSurvey(userLogged, surveyBuffered, postSurveyTransaction); } else { throw new UserLimitReachedException(); } userManager.updateUserAdminBalance(UserVO.SURVEY_LIMIT, userLogged.getUserAdmin()); } else { surveyHandler.postSurvey(userLogged, surveyBuffered, postSurveyTransaction); } }
@SuppressWarnings("finally") @Override public UserVO validateLoginByEmail(String email) throws MSMApplicationException { Query query = manager.createNamedQuery("user.findByEmail"); query.setParameter("email", email); NdgUser user = null; UserVO vo = new UserVO(); try { user = (NdgUser) query.getSingleResult(); vo = userPojoToVo(user); // vo.setValidationKey(generateValidationKey(email)); // user.setValidationKey(vo.getValidationKey()); // manager.merge(user); vo.setValidationKey(user.getValidationKey()); } catch (NoResultException e) { vo.setRetCode(UserVO.INVALID_USERNAME); } finally { return vo; } }
public String loadSettingsFromServerToEditor(String userName) throws MSMApplicationException { String settingsContent = ""; NdgUser user = null; try { try { user = findNdgUserByName(userName); } catch (MSMApplicationException e) { e.printStackTrace(); } } catch (NoResultException e) { // empty } if (user != null) { settingsContent = user.getEditorSettings(); } return settingsContent; }
public void createUser(String username, UserVO vo) throws MSMApplicationException, MSMSystemException { NdgUser userLogged = findNdgUserByName(username); if (userManager.userAdminHasPositiveBalance(UserVO.USER_LIMIT, userLogged.getUserAdmin())) { vo.setUserAdmin(userLogged.getUserAdmin()); log.info("createUser(String username, UserVO vo): " + username + " / " + vo.getUsername()); userManager.createUser(vo); userManager.updateUserAdminBalance(UserVO.USER_LIMIT, userLogged.getUserAdmin()); } else { log.info( "UserLimitReachedException: createUser(String username, UserVO vo): " + username + " / " + vo.getUsername()); throw new UserLimitReachedException(); } }
public void postResult(StringBuffer resultBuffered, TransactionLogVO postResultTransaction) throws MSMApplicationException, MSMSystemException { ResultParser parser = new ResultParser(); ResultXml resultBean = null; NdgUser userLogged = null; try { resultBean = parser.parseResult(resultBuffered, "UTF-8"); } catch (Exception e) { throw new ResultNotParsedException(); } if (resultBean != null) { ImeiVO imei = imeiManager.getIMEI(resultBean.getImei()); userLogged = findNdgUserByName(imei.getUserName()); if (userManager.userAdminHasPositiveBalance(UserVO.RESULT_LIMIT, userLogged.getUserAdmin())) { resultHandler.postResult(resultBuffered, postResultTransaction); userManager.updateUserAdminBalance(UserVO.RESULT_LIMIT, userLogged.getUserAdmin()); } else { throw new UserLimitReachedException(); } } }
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; }
@Override public UserVO requestAccess(UserVO vo) throws MSMApplicationException, MSMSystemException { idSimpleSurvey = MD5.createIdSurvey(); userDirectories = properties.getProperty(PropertiesUtil.SURVEY_ROOT) + SystemUtils.FILE_SEP + vo.getUsername() + SystemUtils.FILE_SEP + "survey" + idSimpleSurvey; UserVO newUser = null; NdgUser userPending = findNdgUserByName(vo.getUsername()); if (userPending != null) { throw new UserAlreadyExistException(); } UserVO userByEmail = getUserByEmail(vo.getEmail()); if (userByEmail != null) { throw new EmailAlreadyExistException(); } userPending = new NdgUser(); userPending.setUsername(vo.getUsername()); try { userPending.setPassword(MD5.createMD5(vo.getPassword())); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); userPending.setPassword(vo.getPassword()); } userPending.setFirstName(vo.getFirstName()); userPending.setLastName(vo.getLastName()); userPending.setEmail(vo.getEmail()); userPending.setWhoUseIt(vo.getWhoUseIt()); userPending.setPhoneNumber(vo.getPhoneNumber()); NdgRole role = findNdgRoleByName(vo.getRole().getName()); if (role != null) { userPending.setRole(role); } Company company = findCompanyByName(vo.getCompany().getCompanyName()); if (company != null) { userPending.setCompany(company); } else { Company newCompany = new Company(); newCompany.setCompanyName(vo.getCompany().getCompanyName()); newCompany.setCompanyType(vo.getCompany().getCompanyType()); newCompany.setCompanyCountry(vo.getCompany().getCompanyCountry()); newCompany.setCompanyIndustry(vo.getCompany().getCompanyIndustry()); newCompany.setCompanySize(vo.getCompany().getCompanySize()); userPending.setCompany(newCompany); } userPending.setAreaCode(vo.getAreaCode()); userPending.setCountryCode(vo.getCountryCode()); userPending.setEmailPreferences(vo.getEmailPreferences()); userPending.setHowDoYouPlanUseNdg(vo.getHowDoYouPlanUseNdg()); userPending.setValidationKey(generateValidationKey(vo.getEmail())); userPending.setUserValidated(vo.getUserValidated()); userPending.setUserAdmin(userPending.getUsername()); userPending.setFirstTimeUse(vo.getFirstTimeUse()); userPending.setHasFullPermissions(vo.getHasFullPermissions()); manager.persist(userPending); createUserFile(vo.getUsername()); newUser = userPojoToVo(userPending); return newUser; }
public UserVO createUser(UserVO vo) throws MSMApplicationException { UserVO newUser = null; NdgUser userPending = findNdgUserByName(vo.getUsername()); UserVO userByEmail = getUserByEmail(vo.getEmail()); if (userPending != null) { throw new UserAlreadyExistException(); } else if (userByEmail != null) { throw new EmailAlreadyExistException(); } else { userPending = new NdgUser(); try { userPending.setPassword(MD5.createMD5(vo.getPassword())); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } userPending.setUsername(vo.getUsername()); userPending.setFirstName(vo.getFirstName()); userPending.setLastName(vo.getLastName()); userPending.setEmail(vo.getEmail()); userPending.setPhoneNumber(vo.getPhoneNumber()); userPending.setAreaCode(vo.getAreaCode()); userPending.setCountryCode(vo.getCountryCode()); NdgRole role = findNdgRoleByName(vo.getRole().getName()); if (role != null) { userPending.setRole(role); } NdgUser userAdmin = findNdgUserByName(vo.getUserAdmin()); if (userPending != null) { userPending.setUserAdmin(userAdmin.getUsername()); userPending.setCompany(userAdmin.getCompany()); userPending.setEmailPreferences(userAdmin.getEmailPreferences()); userPending.setWhoUseIt(userAdmin.getWhoUseIt()); } userPending.setValidationKey(generateValidationKey(vo.getEmail())); userPending.setHasFullPermissions(vo.getHasFullPermissions()); userPending.setUserValidated('Y'); userPending.setHowDoYouPlanUseNdg(""); userPending.setFirstTimeUse('Y'); manager.persist(userPending); newUser = userPojoToVo(userPending); } return newUser; }
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; }
@Override public NdgUser getUserAdmin(String username) throws MSMApplicationException { NdgUser user = findNdgUserByName(username); NdgUser userAdmin = findNdgUserByName(user.getUserAdmin()); return userAdmin; }
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; }