@Test public void test15searchUsers() { Query query = Mockito.mock(Query.class); EntityManager entityManager = Mockito.mock(EntityManager.class); SearchCriteria searchCriteria = new SearchCriteria(); searchCriteria.setDistinct(true); searchCriteria.setGetChildren(true); searchCriteria.setGetCount(true); searchCriteria.setMaxRows(12); searchCriteria.setOwnerId(userId); searchCriteria.setStartIndex(1); searchCriteria.setSortBy("userId"); searchCriteria.setSortType("asc"); Long count = 1l; Mockito.when(daoManager.getEntityManager()).thenReturn(entityManager); Mockito.when(entityManager.createQuery(Mockito.anyString())).thenReturn(query); Mockito.when(query.getSingleResult()).thenReturn(count); VXPortalUserList dbVXPortalUserList = userMgr.searchUsers(searchCriteria); Assert.assertNotNull(dbVXPortalUserList); searchCriteria.setSortBy("loginId"); dbVXPortalUserList = userMgr.searchUsers(searchCriteria); Assert.assertNotNull(dbVXPortalUserList); searchCriteria.setSortBy("emailAddress"); dbVXPortalUserList = userMgr.searchUsers(searchCriteria); Assert.assertNotNull(dbVXPortalUserList); searchCriteria.setSortBy("firstName"); dbVXPortalUserList = userMgr.searchUsers(searchCriteria); Assert.assertNotNull(dbVXPortalUserList); searchCriteria.setSortBy("lastName"); dbVXPortalUserList = userMgr.searchUsers(searchCriteria); Assert.assertNotNull(dbVXPortalUserList); searchCriteria.setSortBy("source"); searchCriteria.setSortType(""); dbVXPortalUserList = userMgr.searchUsers(searchCriteria); Assert.assertNotNull(dbVXPortalUserList); searchCriteria.setSortBy(""); searchCriteria.setSortType("desc"); dbVXPortalUserList = userMgr.searchUsers(searchCriteria); Assert.assertNotNull(dbVXPortalUserList); }
public VXPortalUserList searchUsers(SearchCriteria searchCriteria) { VXPortalUserList returnList = new VXPortalUserList(); ArrayList<VXPortalUser> objectList = new ArrayList<VXPortalUser>(); String queryStr = "SELECT u FROM XXPortalUser u "; String countQueryStr = "SELECT COUNT(u) FROM XXPortalUser u "; Query query = createUserSearchQuery(countQueryStr, null, searchCriteria); Long count = (Long) query.getSingleResult(); int resultSize = count!=null ? count.intValue() :0; if (resultSize == 0) { return returnList; } String sortBy = searchCriteria.getSortBy(); String querySortBy = "u.loginId"; if (!stringUtil.isEmpty(sortBy)) { sortBy = sortBy.trim(); if (sortBy.equalsIgnoreCase("userId")) { querySortBy = "u.id"; } else if (sortBy.equalsIgnoreCase("loginId")) { querySortBy = "ua.loginId"; } else if (sortBy.equalsIgnoreCase("emailAddress")) { querySortBy = "u.emailAddress"; } else if (sortBy.equalsIgnoreCase("firstName")) { querySortBy = "u.firstName"; } else if (sortBy.equalsIgnoreCase("lastName")) { querySortBy = "u.lastName"; } else { sortBy = "loginId"; logger.error("Invalid sortBy provided. sortBy=" + sortBy); } } else { sortBy = "loginId"; } String sortClause = " order by " + querySortBy + " "; String sortType = searchCriteria.getSortType(); String querySortType = "asc"; if (sortType != null) { if (sortType.equalsIgnoreCase("asc") || sortType.equalsIgnoreCase("desc")) { querySortType = sortType; } else { logger.error("Invalid sortType. sortType=" + sortType); } } sortClause += querySortType; query = createUserSearchQuery(queryStr, sortClause, searchCriteria); query.setFirstResult(searchCriteria.getStartIndex()); searchUtil.updateQueryPageSize(query, searchCriteria); @SuppressWarnings("rawtypes") List resultList = query.getResultList(); for (Object object : resultList) { XXPortalUser gjUser = (XXPortalUser) object; VXPortalUser userProfile = new VXPortalUser(); gjUserToUserProfile(gjUser, userProfile); objectList.add(userProfile); } returnList.setResultSize(resultSize); returnList.setPageSize(query.getMaxResults()); returnList.setSortBy(sortBy); returnList.setSortType(querySortType); returnList.setStartIndex(query.getFirstResult()); returnList.setTotalCount(count.longValue()); returnList.setVXPortalUsers(objectList); return returnList; }
UserMgr { public VXPortalUserList searchUsers(SearchCriteria searchCriteria) { VXPortalUserList returnList = new VXPortalUserList(); ArrayList<VXPortalUser> objectList = new ArrayList<VXPortalUser>(); String queryStr = "SELECT u FROM XXPortalUser u "; String countQueryStr = "SELECT COUNT(u) FROM XXPortalUser u "; Query query = createUserSearchQuery(countQueryStr, null, searchCriteria); Long count = (Long) query.getSingleResult(); int resultSize = count!=null ? count.intValue() :0; if (resultSize == 0) { return returnList; } String sortBy = searchCriteria.getSortBy(); String querySortBy = "u.loginId"; if (!stringUtil.isEmpty(sortBy)) { sortBy = sortBy.trim(); if (sortBy.equalsIgnoreCase("userId")) { querySortBy = "u.id"; } else if (sortBy.equalsIgnoreCase("loginId")) { querySortBy = "ua.loginId"; } else if (sortBy.equalsIgnoreCase("emailAddress")) { querySortBy = "u.emailAddress"; } else if (sortBy.equalsIgnoreCase("firstName")) { querySortBy = "u.firstName"; } else if (sortBy.equalsIgnoreCase("lastName")) { querySortBy = "u.lastName"; } else { sortBy = "loginId"; logger.error("Invalid sortBy provided. sortBy=" + sortBy); } } else { sortBy = "loginId"; } String sortClause = " order by " + querySortBy + " "; String sortType = searchCriteria.getSortType(); String querySortType = "asc"; if (sortType != null) { if (sortType.equalsIgnoreCase("asc") || sortType.equalsIgnoreCase("desc")) { querySortType = sortType; } else { logger.error("Invalid sortType. sortType=" + sortType); } } sortClause += querySortType; query = createUserSearchQuery(queryStr, sortClause, searchCriteria); query.setFirstResult(searchCriteria.getStartIndex()); searchUtil.updateQueryPageSize(query, searchCriteria); @SuppressWarnings("rawtypes") List resultList = query.getResultList(); for (Object object : resultList) { XXPortalUser gjUser = (XXPortalUser) object; VXPortalUser userProfile = new VXPortalUser(); gjUserToUserProfile(gjUser, userProfile); objectList.add(userProfile); } returnList.setResultSize(resultSize); returnList.setPageSize(query.getMaxResults()); returnList.setSortBy(sortBy); returnList.setSortType(querySortType); returnList.setStartIndex(query.getFirstResult()); returnList.setTotalCount(count.longValue()); returnList.setVXPortalUsers(objectList); return returnList; } }
UserMgr { public VXPortalUserList searchUsers(SearchCriteria searchCriteria) { VXPortalUserList returnList = new VXPortalUserList(); ArrayList<VXPortalUser> objectList = new ArrayList<VXPortalUser>(); String queryStr = "SELECT u FROM XXPortalUser u "; String countQueryStr = "SELECT COUNT(u) FROM XXPortalUser u "; Query query = createUserSearchQuery(countQueryStr, null, searchCriteria); Long count = (Long) query.getSingleResult(); int resultSize = count!=null ? count.intValue() :0; if (resultSize == 0) { return returnList; } String sortBy = searchCriteria.getSortBy(); String querySortBy = "u.loginId"; if (!stringUtil.isEmpty(sortBy)) { sortBy = sortBy.trim(); if (sortBy.equalsIgnoreCase("userId")) { querySortBy = "u.id"; } else if (sortBy.equalsIgnoreCase("loginId")) { querySortBy = "ua.loginId"; } else if (sortBy.equalsIgnoreCase("emailAddress")) { querySortBy = "u.emailAddress"; } else if (sortBy.equalsIgnoreCase("firstName")) { querySortBy = "u.firstName"; } else if (sortBy.equalsIgnoreCase("lastName")) { querySortBy = "u.lastName"; } else { sortBy = "loginId"; logger.error("Invalid sortBy provided. sortBy=" + sortBy); } } else { sortBy = "loginId"; } String sortClause = " order by " + querySortBy + " "; String sortType = searchCriteria.getSortType(); String querySortType = "asc"; if (sortType != null) { if (sortType.equalsIgnoreCase("asc") || sortType.equalsIgnoreCase("desc")) { querySortType = sortType; } else { logger.error("Invalid sortType. sortType=" + sortType); } } sortClause += querySortType; query = createUserSearchQuery(queryStr, sortClause, searchCriteria); query.setFirstResult(searchCriteria.getStartIndex()); searchUtil.updateQueryPageSize(query, searchCriteria); @SuppressWarnings("rawtypes") List resultList = query.getResultList(); for (Object object : resultList) { XXPortalUser gjUser = (XXPortalUser) object; VXPortalUser userProfile = new VXPortalUser(); gjUserToUserProfile(gjUser, userProfile); objectList.add(userProfile); } returnList.setResultSize(resultSize); returnList.setPageSize(query.getMaxResults()); returnList.setSortBy(sortBy); returnList.setSortType(querySortType); returnList.setStartIndex(query.getFirstResult()); returnList.setTotalCount(count.longValue()); returnList.setVXPortalUsers(objectList); return returnList; } UserMgr(); }
UserMgr { public VXPortalUserList searchUsers(SearchCriteria searchCriteria) { VXPortalUserList returnList = new VXPortalUserList(); ArrayList<VXPortalUser> objectList = new ArrayList<VXPortalUser>(); String queryStr = "SELECT u FROM XXPortalUser u "; String countQueryStr = "SELECT COUNT(u) FROM XXPortalUser u "; Query query = createUserSearchQuery(countQueryStr, null, searchCriteria); Long count = (Long) query.getSingleResult(); int resultSize = count!=null ? count.intValue() :0; if (resultSize == 0) { return returnList; } String sortBy = searchCriteria.getSortBy(); String querySortBy = "u.loginId"; if (!stringUtil.isEmpty(sortBy)) { sortBy = sortBy.trim(); if (sortBy.equalsIgnoreCase("userId")) { querySortBy = "u.id"; } else if (sortBy.equalsIgnoreCase("loginId")) { querySortBy = "ua.loginId"; } else if (sortBy.equalsIgnoreCase("emailAddress")) { querySortBy = "u.emailAddress"; } else if (sortBy.equalsIgnoreCase("firstName")) { querySortBy = "u.firstName"; } else if (sortBy.equalsIgnoreCase("lastName")) { querySortBy = "u.lastName"; } else { sortBy = "loginId"; logger.error("Invalid sortBy provided. sortBy=" + sortBy); } } else { sortBy = "loginId"; } String sortClause = " order by " + querySortBy + " "; String sortType = searchCriteria.getSortType(); String querySortType = "asc"; if (sortType != null) { if (sortType.equalsIgnoreCase("asc") || sortType.equalsIgnoreCase("desc")) { querySortType = sortType; } else { logger.error("Invalid sortType. sortType=" + sortType); } } sortClause += querySortType; query = createUserSearchQuery(queryStr, sortClause, searchCriteria); query.setFirstResult(searchCriteria.getStartIndex()); searchUtil.updateQueryPageSize(query, searchCriteria); @SuppressWarnings("rawtypes") List resultList = query.getResultList(); for (Object object : resultList) { XXPortalUser gjUser = (XXPortalUser) object; VXPortalUser userProfile = new VXPortalUser(); gjUserToUserProfile(gjUser, userProfile); objectList.add(userProfile); } returnList.setResultSize(resultSize); returnList.setPageSize(query.getMaxResults()); returnList.setSortBy(sortBy); returnList.setSortType(querySortType); returnList.setStartIndex(query.getFirstResult()); returnList.setTotalCount(count.longValue()); returnList.setVXPortalUsers(objectList); return returnList; } UserMgr(); XXPortalUser createUser(VXPortalUser userProfile, int userStatus,
			Collection<String> userRoleList); XXPortalUser createUser(XXPortalUser user, int userStatus,
			Collection<String> userRoleList); XXPortalUser createUser(VXPortalUser userProfile, int userStatus); XXPortalUser updateUser(VXPortalUser userProfile); boolean updateRoles(Long userId, Collection<String> rolesList); void setUserRoles(Long userId, List<VXString> vStringRolesList); VXResponse changePassword(VXPasswordChange pwdChange); VXPortalUser changeEmailAddress(XXPortalUser gjUser,
			VXPasswordChange changeEmail); VXPortalUser deactivateUser(XXPortalUser gjUser); VXPortalUser getUserProfile(Long id); VXPortalUser getUserProfileByLoginId(); VXPortalUser getUserProfileByLoginId(String loginId); XXPortalUser mapVXPortalUserToXXPortalUser(VXPortalUser userProfile); VXPortalUser mapXXPortalUserToVXPortalUser(XXPortalUser user,
			Collection<String> userRoleList); VXPortalUser mapXXPortalUserVXPortalUser(XXPortalUser user); XXPortalUser findByEmailAddress(String emailId); XXPortalUser findByLoginId(String loginId); @Transactional(readOnly = true, propagation = Propagation.REQUIRED) Collection<String> getRolesForUser(XXPortalUser user); VXPortalUserList searchUsers(SearchCriteria searchCriteria); boolean deleteUserRole(Long userId, String userRole); boolean deleteUserRole(Long userId, XXPortalUserRole gjUserRole); XXPortalUserRole addUserRole(Long userId, String userRole); void checkAccess(Long userId); void checkAccess(XXPortalUser gjUser); void checkAccessForUpdate(XXPortalUser gjUser); String encrypt(String loginId, String password); String encryptWithOlderAlgo(String loginId, String password); VXPortalUser createUser(VXPortalUser userProfile); VXPortalUser createDefaultAccountUser(VXPortalUser userProfile); boolean isUserInRole(Long userId, String role); XXPortalUser updateUserWithPass(VXPortalUser userProfile); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) XXPortalUser updatePasswordInSHA256(String userName,String userPassword,boolean logAudits); void checkAdminAccess(); Collection<String> getRolesByLoginId(String loginId); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) XXPortalUser updateOldUserName(String userLoginId,String newUserName, String currentPassword); }
UserMgr { public VXPortalUserList searchUsers(SearchCriteria searchCriteria) { VXPortalUserList returnList = new VXPortalUserList(); ArrayList<VXPortalUser> objectList = new ArrayList<VXPortalUser>(); String queryStr = "SELECT u FROM XXPortalUser u "; String countQueryStr = "SELECT COUNT(u) FROM XXPortalUser u "; Query query = createUserSearchQuery(countQueryStr, null, searchCriteria); Long count = (Long) query.getSingleResult(); int resultSize = count!=null ? count.intValue() :0; if (resultSize == 0) { return returnList; } String sortBy = searchCriteria.getSortBy(); String querySortBy = "u.loginId"; if (!stringUtil.isEmpty(sortBy)) { sortBy = sortBy.trim(); if (sortBy.equalsIgnoreCase("userId")) { querySortBy = "u.id"; } else if (sortBy.equalsIgnoreCase("loginId")) { querySortBy = "ua.loginId"; } else if (sortBy.equalsIgnoreCase("emailAddress")) { querySortBy = "u.emailAddress"; } else if (sortBy.equalsIgnoreCase("firstName")) { querySortBy = "u.firstName"; } else if (sortBy.equalsIgnoreCase("lastName")) { querySortBy = "u.lastName"; } else { sortBy = "loginId"; logger.error("Invalid sortBy provided. sortBy=" + sortBy); } } else { sortBy = "loginId"; } String sortClause = " order by " + querySortBy + " "; String sortType = searchCriteria.getSortType(); String querySortType = "asc"; if (sortType != null) { if (sortType.equalsIgnoreCase("asc") || sortType.equalsIgnoreCase("desc")) { querySortType = sortType; } else { logger.error("Invalid sortType. sortType=" + sortType); } } sortClause += querySortType; query = createUserSearchQuery(queryStr, sortClause, searchCriteria); query.setFirstResult(searchCriteria.getStartIndex()); searchUtil.updateQueryPageSize(query, searchCriteria); @SuppressWarnings("rawtypes") List resultList = query.getResultList(); for (Object object : resultList) { XXPortalUser gjUser = (XXPortalUser) object; VXPortalUser userProfile = new VXPortalUser(); gjUserToUserProfile(gjUser, userProfile); objectList.add(userProfile); } returnList.setResultSize(resultSize); returnList.setPageSize(query.getMaxResults()); returnList.setSortBy(sortBy); returnList.setSortType(querySortType); returnList.setStartIndex(query.getFirstResult()); returnList.setTotalCount(count.longValue()); returnList.setVXPortalUsers(objectList); return returnList; } UserMgr(); XXPortalUser createUser(VXPortalUser userProfile, int userStatus,
			Collection<String> userRoleList); XXPortalUser createUser(XXPortalUser user, int userStatus,
			Collection<String> userRoleList); XXPortalUser createUser(VXPortalUser userProfile, int userStatus); XXPortalUser updateUser(VXPortalUser userProfile); boolean updateRoles(Long userId, Collection<String> rolesList); void setUserRoles(Long userId, List<VXString> vStringRolesList); VXResponse changePassword(VXPasswordChange pwdChange); VXPortalUser changeEmailAddress(XXPortalUser gjUser,
			VXPasswordChange changeEmail); VXPortalUser deactivateUser(XXPortalUser gjUser); VXPortalUser getUserProfile(Long id); VXPortalUser getUserProfileByLoginId(); VXPortalUser getUserProfileByLoginId(String loginId); XXPortalUser mapVXPortalUserToXXPortalUser(VXPortalUser userProfile); VXPortalUser mapXXPortalUserToVXPortalUser(XXPortalUser user,
			Collection<String> userRoleList); VXPortalUser mapXXPortalUserVXPortalUser(XXPortalUser user); XXPortalUser findByEmailAddress(String emailId); XXPortalUser findByLoginId(String loginId); @Transactional(readOnly = true, propagation = Propagation.REQUIRED) Collection<String> getRolesForUser(XXPortalUser user); VXPortalUserList searchUsers(SearchCriteria searchCriteria); boolean deleteUserRole(Long userId, String userRole); boolean deleteUserRole(Long userId, XXPortalUserRole gjUserRole); XXPortalUserRole addUserRole(Long userId, String userRole); void checkAccess(Long userId); void checkAccess(XXPortalUser gjUser); void checkAccessForUpdate(XXPortalUser gjUser); String encrypt(String loginId, String password); String encryptWithOlderAlgo(String loginId, String password); VXPortalUser createUser(VXPortalUser userProfile); VXPortalUser createDefaultAccountUser(VXPortalUser userProfile); boolean isUserInRole(Long userId, String role); XXPortalUser updateUserWithPass(VXPortalUser userProfile); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) XXPortalUser updatePasswordInSHA256(String userName,String userPassword,boolean logAudits); void checkAdminAccess(); Collection<String> getRolesByLoginId(String loginId); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) XXPortalUser updateOldUserName(String userLoginId,String newUserName, String currentPassword);  }