List of usage examples for com.liferay.portal.kernel.search SortFactoryUtil getSort
public static Sort getSort(Class<?> clazz, String orderByCol, String orderByType)
From source file:com.liferay.faces.demos.list.UserLazyDataModel.java
License:Open Source License
public int countRows() { int totalCount = 0; try {//from w w w . j a va2 s .c o m LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>(); params.put("expandoAttributes", null); Sort sort = SortFactoryUtil.getSort(User.class, DEFAULT_SORT_CRITERIA, "asc"); boolean andSearch = true; int status = WorkflowConstants.STATUS_ANY; String firstName = null; String middleName = null; String lastName = null; String screenName = null; String emailAddress = null; Hits hits = UserLocalServiceUtil.search(companyId, firstName, middleName, lastName, screenName, emailAddress, status, params, andSearch, QueryUtil.ALL_POS, QueryUtil.ALL_POS, sort); totalCount = hits.getLength(); } catch (Exception e) { logger.error(e.getMessage(), e); } return totalCount; }
From source file:com.liferay.faces.demos.list.UserLazyDataModel.java
License:Open Source License
/** * This method is called by the PrimeFaces {@link DataTable} according to the rows specified in the currently * displayed page of data.//from ww w . jav a2s. co m * * @param first The zero-relative first row index. * @param pageSize The number of rows to fetch. * @param sortField The name of the field which the table is sorted by. * @param sortOrder The sort order, which can be either ascending (default) or descending. * @param filters The query criteria. Note that in order for the filtering to work with the Liferay API, the * end-user must specify complete, matching words. Wildcards and partial matches are not * supported. */ @Override public List<User> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) { List<User> users = null; Sort sort; // sort if (sortField != null) { if (sortOrder.equals(SortOrder.DESCENDING)) { sort = SortFactoryUtil.getSort(User.class, sortField, "desc"); } else { sort = SortFactoryUtil.getSort(User.class, sortField, "asc"); } } else { sort = SortFactoryUtil.getSort(User.class, DEFAULT_SORT_CRITERIA, "asc"); } try { LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>(); int liferayOneRelativeFinishRow = first + pageSize + 1; boolean andSearch = true; int status = WorkflowConstants.STATUS_ANY; String firstName = trimExpresssion((String) filters.get("firstName")); String middleName = trimExpresssion((String) filters.get("middleName")); String lastName = trimExpresssion((String) filters.get("lastName")); String screenName = trimExpresssion((String) filters.get("screenName")); String emailAddress = trimExpresssion((String) filters.get("emailAddress")); // For the sake of speed, search for users in the index rather than // querying the database directly. Hits hits = UserLocalServiceUtil.search(companyId, firstName, middleName, lastName, screenName, emailAddress, status, params, andSearch, first, liferayOneRelativeFinishRow, sort); List<Document> documentHits = hits.toList(); logger.debug( ("filters firstName=[{0}] middleName=[{1}] lastName=[{2}] screenName=[{3}] emailAddress=[{4}] active=[{5}] andSearch=[{6}] startRow=[{7}] liferayOneRelativeFinishRow=[{8}] sortColumn=[{9}] reverseOrder=[{10}] hitCount=[{11}]"), firstName, middleName, lastName, screenName, emailAddress, status, andSearch, first, liferayOneRelativeFinishRow, sortField, sort.isReverse(), documentHits.size()); // Convert the results from the search index into a list of user // objects. users = new ArrayList<User>(documentHits.size()); for (Document document : documentHits) { long userId = GetterUtil.getLong(document.get(Field.USER_ID)); try { User user = UserLocalServiceUtil.getUserById(userId); users.add(user); } catch (NoSuchUserException nsue) { logger.error("User with userId=[{0}] does not exist in the search index. Please reindex."); } } } catch (Exception e) { logger.error(e.getMessage(), e); } return users; }
From source file:com.liferay.privatemessaging.util.PrivateMessagingUtil.java
License:Open Source License
public static JSONObject getJSONRecipients(long userId, String type, String keywords, int start, int end) throws PortalException { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); User user = UserLocalServiceUtil.getUser(userId); LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>(); if (type.equals("site")) { params.put("inherit", Boolean.TRUE); LinkedHashMap<String, Object> groupParams = new LinkedHashMap<String, Object>(); groupParams.put("inherit", Boolean.FALSE); groupParams.put("site", Boolean.TRUE); groupParams.put("usersGroups", userId); List<Group> groups = GroupLocalServiceUtil.search(user.getCompanyId(), groupParams, QueryUtil.ALL_POS, QueryUtil.ALL_POS);/*from w ww . j a v a2 s.c o m*/ params.put("usersGroups", SitesUtil.filterGroups(groups, PortletPropsValues.AUTOCOMPLETE_RECIPIENT_SITE_EXCLUDES)); } else if (!type.equals("all")) { params.put("socialRelationType", new Long[] { userId, new Long(SocialRelationConstants.TYPE_BI_CONNECTION) }); } try { Role role = RoleLocalServiceUtil.getRole(user.getCompanyId(), RoleConstants.SOCIAL_OFFICE_USER); if (role != null) { params.put("inherit", Boolean.TRUE); params.put("usersRoles", new Long(role.getRoleId())); } } catch (NoSuchRoleException nsre) { } List<User> users = new ArrayList<User>(); if (_USERS_INDEXER_ENABLED && _USERS_SEARCH_WITH_INDEX) { Sort sort = SortFactoryUtil.getSort(User.class, "firstName", "asc"); BaseModelSearchResult<User> baseModelSearchResult = UserLocalServiceUtil.searchUsers( user.getCompanyId(), keywords, keywords, keywords, keywords, keywords, WorkflowConstants.STATUS_APPROVED, params, false, start, end, sort); jsonObject.put("total", baseModelSearchResult.getLength()); users = baseModelSearchResult.getBaseModels(); } else { int total = UserLocalServiceUtil.searchCount(user.getCompanyId(), keywords, WorkflowConstants.STATUS_APPROVED, params); jsonObject.put("total", total); users = UserLocalServiceUtil.search(user.getCompanyId(), keywords, WorkflowConstants.STATUS_APPROVED, params, start, end, new UserFirstNameComparator(true)); } JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); for (User curUser : users) { JSONObject userJSONObject = JSONFactoryUtil.createJSONObject(); StringBundler sb = new StringBundler(5); sb.append(curUser.getFullName()); sb.append(CharPool.SPACE); sb.append(CharPool.LESS_THAN); sb.append(curUser.getScreenName()); sb.append(CharPool.GREATER_THAN); userJSONObject.put("name", sb.toString()); jsonArray.put(userJSONObject); } jsonObject.put("users", jsonArray); return jsonObject; }