@Test public void test37createUserSearchQuery() { EntityManager entityManager = Mockito.mock(EntityManager.class); String queryString="Select id,loginId,emailAddress,firstName,lastName,statusList,publicScreenName,status from XXPortalUser"; Query query = Mockito.mock(Query.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("asc"); VXPortalUser vXPortalUser=userProfile(); List<String> userRoleList = new ArrayList<String>(); userRoleList.add("ROLE_USER"); List<Integer> statusList = new ArrayList<Integer>(); statusList.add(1); searchCriteria.addParam("roleList", userRoleList); searchCriteria.addParam("userId", vXPortalUser.getId()); searchCriteria.addParam("loginId", vXPortalUser.getLoginId()); searchCriteria.addParam("emailAddress", vXPortalUser.getEmailAddress()); searchCriteria.addParam("firstName", vXPortalUser.getFirstName()); searchCriteria.addParam("lastName", vXPortalUser.getLastName()); searchCriteria.addParam("statusList", statusList); searchCriteria.addParam("publicScreenName", vXPortalUser.getPublicScreenName()); searchCriteria.addParam("status", vXPortalUser.getStatus()); searchCriteria.addParam("familyScreenName", vXPortalUser.getPublicScreenName()); Mockito.when(daoManager.getEntityManager()).thenReturn(entityManager); Mockito.when(entityManager.createQuery(Mockito.anyString())).thenReturn(query); Query newQuery = userMgr.createUserSearchQuery(query.toString(),queryString,searchCriteria); Assert.assertNotNull(newQuery); userRoleList.add("ROLE_SYS_ADMIN"); statusList.add(0); searchCriteria.addParam("statusList", statusList); searchCriteria.addParam("roleList", userRoleList); newQuery = userMgr.createUserSearchQuery(query.toString(),queryString,searchCriteria); }
protected Query createUserSearchQuery(String queryStr, String sortClause, SearchCriteria searchCriteria) { HashMap<String, Object> paramList = searchCriteria.getParamList(); String whereClause = "WHERE 1 = 1 "; @SuppressWarnings("unchecked") List<String> roleList = (List<String>) paramList.get("roleList"); if (roleList != null && roleList.size() > 0) { whereClause = ", XXPortalUserRole ur WHERE u.id = ur.userId"; if (roleList.size() == 1) { whereClause += " and ur.userRole = :role"; } else { whereClause += " and ur.userRole in (:roleList)"; } } Long userId = (Long) paramList.get("userId"); if (userId != null) { whereClause += " and u.id = :userId "; } String loginId = (String) paramList.get("loginId"); if (loginId != null) { whereClause += " and LOWER(u.loginId) = :loginId "; } String emailAddress = (String) paramList.get("emailAddress"); if (emailAddress != null) { whereClause += " and LOWER(u.emailAddress) = :emailAddress "; } String firstName = (String) paramList.get("firstName"); if (firstName != null) { whereClause += " and LOWER(u.firstName) = :firstName "; } String lastName = (String) paramList.get("lastName"); if (lastName != null) { whereClause += " and LOWER(u.lastName) = :lastName "; } Integer status = null; @SuppressWarnings("unchecked") List<Integer> statusList = (List<Integer>) paramList.get("statusList"); if (statusList != null && statusList.size() == 1) { whereClause += " and u.status = :status"; status = statusList.get(0); } else if (statusList != null && statusList.size() > 1) { whereClause += " and u.status in (:statusList) "; } String publicScreenName = (String) paramList.get("publicScreenName"); if (publicScreenName != null) { whereClause += " and LOWER(u.publicScreenName) = :publicScreenName "; } String familyScreenName = (String) paramList.get("familyScreenName"); if (familyScreenName != null) { whereClause += " and LOWER(u.familyScreenName) = :familyScreenName "; } if (sortClause != null) { whereClause += sortClause; } Query query = daoManager.getEntityManager().createQuery( queryStr + whereClause); if (roleList != null && roleList.size() > 0) { if (roleList.size() == 1) { query.setParameter("role", roleList.get(0)); } else { query.setParameter("roleList", roleList); } } if (status != null) { query.setParameter("status", status); } if (statusList != null && statusList.size() > 1) { query.setParameter("statusList", statusList); } if (emailAddress != null) { query.setParameter("emailAddress", emailAddress.toLowerCase()); } if (userId != null) { query.setParameter("userId", userId); } if (firstName != null) { query.setParameter("firstName", firstName.toLowerCase()); } if (lastName != null) { query.setParameter("lastName", lastName.toLowerCase()); } if (loginId != null) { query.setParameter("loginId", loginId.toLowerCase()); } if (publicScreenName != null) { query.setParameter("publicScreenName", publicScreenName.toLowerCase()); } if (familyScreenName != null) { query.setParameter("familyScreenName", familyScreenName.toLowerCase()); } return query; }
UserMgr { protected Query createUserSearchQuery(String queryStr, String sortClause, SearchCriteria searchCriteria) { HashMap<String, Object> paramList = searchCriteria.getParamList(); String whereClause = "WHERE 1 = 1 "; @SuppressWarnings("unchecked") List<String> roleList = (List<String>) paramList.get("roleList"); if (roleList != null && roleList.size() > 0) { whereClause = ", XXPortalUserRole ur WHERE u.id = ur.userId"; if (roleList.size() == 1) { whereClause += " and ur.userRole = :role"; } else { whereClause += " and ur.userRole in (:roleList)"; } } Long userId = (Long) paramList.get("userId"); if (userId != null) { whereClause += " and u.id = :userId "; } String loginId = (String) paramList.get("loginId"); if (loginId != null) { whereClause += " and LOWER(u.loginId) = :loginId "; } String emailAddress = (String) paramList.get("emailAddress"); if (emailAddress != null) { whereClause += " and LOWER(u.emailAddress) = :emailAddress "; } String firstName = (String) paramList.get("firstName"); if (firstName != null) { whereClause += " and LOWER(u.firstName) = :firstName "; } String lastName = (String) paramList.get("lastName"); if (lastName != null) { whereClause += " and LOWER(u.lastName) = :lastName "; } Integer status = null; @SuppressWarnings("unchecked") List<Integer> statusList = (List<Integer>) paramList.get("statusList"); if (statusList != null && statusList.size() == 1) { whereClause += " and u.status = :status"; status = statusList.get(0); } else if (statusList != null && statusList.size() > 1) { whereClause += " and u.status in (:statusList) "; } String publicScreenName = (String) paramList.get("publicScreenName"); if (publicScreenName != null) { whereClause += " and LOWER(u.publicScreenName) = :publicScreenName "; } String familyScreenName = (String) paramList.get("familyScreenName"); if (familyScreenName != null) { whereClause += " and LOWER(u.familyScreenName) = :familyScreenName "; } if (sortClause != null) { whereClause += sortClause; } Query query = daoManager.getEntityManager().createQuery( queryStr + whereClause); if (roleList != null && roleList.size() > 0) { if (roleList.size() == 1) { query.setParameter("role", roleList.get(0)); } else { query.setParameter("roleList", roleList); } } if (status != null) { query.setParameter("status", status); } if (statusList != null && statusList.size() > 1) { query.setParameter("statusList", statusList); } if (emailAddress != null) { query.setParameter("emailAddress", emailAddress.toLowerCase()); } if (userId != null) { query.setParameter("userId", userId); } if (firstName != null) { query.setParameter("firstName", firstName.toLowerCase()); } if (lastName != null) { query.setParameter("lastName", lastName.toLowerCase()); } if (loginId != null) { query.setParameter("loginId", loginId.toLowerCase()); } if (publicScreenName != null) { query.setParameter("publicScreenName", publicScreenName.toLowerCase()); } if (familyScreenName != null) { query.setParameter("familyScreenName", familyScreenName.toLowerCase()); } return query; } }
UserMgr { protected Query createUserSearchQuery(String queryStr, String sortClause, SearchCriteria searchCriteria) { HashMap<String, Object> paramList = searchCriteria.getParamList(); String whereClause = "WHERE 1 = 1 "; @SuppressWarnings("unchecked") List<String> roleList = (List<String>) paramList.get("roleList"); if (roleList != null && roleList.size() > 0) { whereClause = ", XXPortalUserRole ur WHERE u.id = ur.userId"; if (roleList.size() == 1) { whereClause += " and ur.userRole = :role"; } else { whereClause += " and ur.userRole in (:roleList)"; } } Long userId = (Long) paramList.get("userId"); if (userId != null) { whereClause += " and u.id = :userId "; } String loginId = (String) paramList.get("loginId"); if (loginId != null) { whereClause += " and LOWER(u.loginId) = :loginId "; } String emailAddress = (String) paramList.get("emailAddress"); if (emailAddress != null) { whereClause += " and LOWER(u.emailAddress) = :emailAddress "; } String firstName = (String) paramList.get("firstName"); if (firstName != null) { whereClause += " and LOWER(u.firstName) = :firstName "; } String lastName = (String) paramList.get("lastName"); if (lastName != null) { whereClause += " and LOWER(u.lastName) = :lastName "; } Integer status = null; @SuppressWarnings("unchecked") List<Integer> statusList = (List<Integer>) paramList.get("statusList"); if (statusList != null && statusList.size() == 1) { whereClause += " and u.status = :status"; status = statusList.get(0); } else if (statusList != null && statusList.size() > 1) { whereClause += " and u.status in (:statusList) "; } String publicScreenName = (String) paramList.get("publicScreenName"); if (publicScreenName != null) { whereClause += " and LOWER(u.publicScreenName) = :publicScreenName "; } String familyScreenName = (String) paramList.get("familyScreenName"); if (familyScreenName != null) { whereClause += " and LOWER(u.familyScreenName) = :familyScreenName "; } if (sortClause != null) { whereClause += sortClause; } Query query = daoManager.getEntityManager().createQuery( queryStr + whereClause); if (roleList != null && roleList.size() > 0) { if (roleList.size() == 1) { query.setParameter("role", roleList.get(0)); } else { query.setParameter("roleList", roleList); } } if (status != null) { query.setParameter("status", status); } if (statusList != null && statusList.size() > 1) { query.setParameter("statusList", statusList); } if (emailAddress != null) { query.setParameter("emailAddress", emailAddress.toLowerCase()); } if (userId != null) { query.setParameter("userId", userId); } if (firstName != null) { query.setParameter("firstName", firstName.toLowerCase()); } if (lastName != null) { query.setParameter("lastName", lastName.toLowerCase()); } if (loginId != null) { query.setParameter("loginId", loginId.toLowerCase()); } if (publicScreenName != null) { query.setParameter("publicScreenName", publicScreenName.toLowerCase()); } if (familyScreenName != null) { query.setParameter("familyScreenName", familyScreenName.toLowerCase()); } return query; } UserMgr(); }
UserMgr { protected Query createUserSearchQuery(String queryStr, String sortClause, SearchCriteria searchCriteria) { HashMap<String, Object> paramList = searchCriteria.getParamList(); String whereClause = "WHERE 1 = 1 "; @SuppressWarnings("unchecked") List<String> roleList = (List<String>) paramList.get("roleList"); if (roleList != null && roleList.size() > 0) { whereClause = ", XXPortalUserRole ur WHERE u.id = ur.userId"; if (roleList.size() == 1) { whereClause += " and ur.userRole = :role"; } else { whereClause += " and ur.userRole in (:roleList)"; } } Long userId = (Long) paramList.get("userId"); if (userId != null) { whereClause += " and u.id = :userId "; } String loginId = (String) paramList.get("loginId"); if (loginId != null) { whereClause += " and LOWER(u.loginId) = :loginId "; } String emailAddress = (String) paramList.get("emailAddress"); if (emailAddress != null) { whereClause += " and LOWER(u.emailAddress) = :emailAddress "; } String firstName = (String) paramList.get("firstName"); if (firstName != null) { whereClause += " and LOWER(u.firstName) = :firstName "; } String lastName = (String) paramList.get("lastName"); if (lastName != null) { whereClause += " and LOWER(u.lastName) = :lastName "; } Integer status = null; @SuppressWarnings("unchecked") List<Integer> statusList = (List<Integer>) paramList.get("statusList"); if (statusList != null && statusList.size() == 1) { whereClause += " and u.status = :status"; status = statusList.get(0); } else if (statusList != null && statusList.size() > 1) { whereClause += " and u.status in (:statusList) "; } String publicScreenName = (String) paramList.get("publicScreenName"); if (publicScreenName != null) { whereClause += " and LOWER(u.publicScreenName) = :publicScreenName "; } String familyScreenName = (String) paramList.get("familyScreenName"); if (familyScreenName != null) { whereClause += " and LOWER(u.familyScreenName) = :familyScreenName "; } if (sortClause != null) { whereClause += sortClause; } Query query = daoManager.getEntityManager().createQuery( queryStr + whereClause); if (roleList != null && roleList.size() > 0) { if (roleList.size() == 1) { query.setParameter("role", roleList.get(0)); } else { query.setParameter("roleList", roleList); } } if (status != null) { query.setParameter("status", status); } if (statusList != null && statusList.size() > 1) { query.setParameter("statusList", statusList); } if (emailAddress != null) { query.setParameter("emailAddress", emailAddress.toLowerCase()); } if (userId != null) { query.setParameter("userId", userId); } if (firstName != null) { query.setParameter("firstName", firstName.toLowerCase()); } if (lastName != null) { query.setParameter("lastName", lastName.toLowerCase()); } if (loginId != null) { query.setParameter("loginId", loginId.toLowerCase()); } if (publicScreenName != null) { query.setParameter("publicScreenName", publicScreenName.toLowerCase()); } if (familyScreenName != null) { query.setParameter("familyScreenName", familyScreenName.toLowerCase()); } return query; } 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 { protected Query createUserSearchQuery(String queryStr, String sortClause, SearchCriteria searchCriteria) { HashMap<String, Object> paramList = searchCriteria.getParamList(); String whereClause = "WHERE 1 = 1 "; @SuppressWarnings("unchecked") List<String> roleList = (List<String>) paramList.get("roleList"); if (roleList != null && roleList.size() > 0) { whereClause = ", XXPortalUserRole ur WHERE u.id = ur.userId"; if (roleList.size() == 1) { whereClause += " and ur.userRole = :role"; } else { whereClause += " and ur.userRole in (:roleList)"; } } Long userId = (Long) paramList.get("userId"); if (userId != null) { whereClause += " and u.id = :userId "; } String loginId = (String) paramList.get("loginId"); if (loginId != null) { whereClause += " and LOWER(u.loginId) = :loginId "; } String emailAddress = (String) paramList.get("emailAddress"); if (emailAddress != null) { whereClause += " and LOWER(u.emailAddress) = :emailAddress "; } String firstName = (String) paramList.get("firstName"); if (firstName != null) { whereClause += " and LOWER(u.firstName) = :firstName "; } String lastName = (String) paramList.get("lastName"); if (lastName != null) { whereClause += " and LOWER(u.lastName) = :lastName "; } Integer status = null; @SuppressWarnings("unchecked") List<Integer> statusList = (List<Integer>) paramList.get("statusList"); if (statusList != null && statusList.size() == 1) { whereClause += " and u.status = :status"; status = statusList.get(0); } else if (statusList != null && statusList.size() > 1) { whereClause += " and u.status in (:statusList) "; } String publicScreenName = (String) paramList.get("publicScreenName"); if (publicScreenName != null) { whereClause += " and LOWER(u.publicScreenName) = :publicScreenName "; } String familyScreenName = (String) paramList.get("familyScreenName"); if (familyScreenName != null) { whereClause += " and LOWER(u.familyScreenName) = :familyScreenName "; } if (sortClause != null) { whereClause += sortClause; } Query query = daoManager.getEntityManager().createQuery( queryStr + whereClause); if (roleList != null && roleList.size() > 0) { if (roleList.size() == 1) { query.setParameter("role", roleList.get(0)); } else { query.setParameter("roleList", roleList); } } if (status != null) { query.setParameter("status", status); } if (statusList != null && statusList.size() > 1) { query.setParameter("statusList", statusList); } if (emailAddress != null) { query.setParameter("emailAddress", emailAddress.toLowerCase()); } if (userId != null) { query.setParameter("userId", userId); } if (firstName != null) { query.setParameter("firstName", firstName.toLowerCase()); } if (lastName != null) { query.setParameter("lastName", lastName.toLowerCase()); } if (loginId != null) { query.setParameter("loginId", loginId.toLowerCase()); } if (publicScreenName != null) { query.setParameter("publicScreenName", publicScreenName.toLowerCase()); } if (familyScreenName != null) { query.setParameter("familyScreenName", familyScreenName.toLowerCase()); } return query; } 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);  }