List of usage examples for com.liferay.portal.kernel.util.comparator UserFirstNameComparator UserFirstNameComparator
public UserFirstNameComparator()
From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java
License:Open Source License
protected void serveCalendarResources(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); String keywords = ParamUtil.getString(resourceRequest, "keywords"); Set<Calendar> calendarsSet = new LinkedHashSet<>(); Hits hits = search(themeDisplay, keywords); for (Document document : hits.getDocs()) { long calendarId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); Calendar calendar = _calendarService.getCalendar(calendarId); CalendarResource calendarResource = calendar.getCalendarResource(); if (calendarResource.isActive()) { Group group = _groupLocalService.getGroup(calendar.getGroupId()); if (group.hasStagingGroup()) { Group stagingGroup = group.getStagingGroup(); long stagingGroupId = stagingGroup.getGroupId(); if (stagingGroupId == themeDisplay.getScopeGroupId()) { calendar = _calendarLocalService.fetchCalendarByUuidAndGroupId(calendar.getUuid(), stagingGroupId); }/*from w w w . jav a 2 s . c om*/ } calendarsSet.add(calendar); } } String name = StringUtil.merge(CustomSQLUtil.keywords(keywords), StringPool.BLANK); LinkedHashMap<String, Object> params = new LinkedHashMap<>(); params.put("usersGroups", themeDisplay.getUserId()); List<Group> groups = _groupLocalService.search(themeDisplay.getCompanyId(), name, null, params, true, 0, SearchContainer.DEFAULT_DELTA); for (Group group : groups) { long groupClassNameId = _portal.getClassNameId(Group.class); addCalendar(resourceRequest, calendarsSet, groupClassNameId, group.getGroupId()); } long userClassNameId = _portal.getClassNameId(User.class); List<User> users = _userLocalService.search(themeDisplay.getCompanyId(), keywords, 0, null, 0, SearchContainer.DEFAULT_DELTA, new UserFirstNameComparator()); for (User user : users) { addCalendar(resourceRequest, calendarsSet, userClassNameId, user.getUserId()); } JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); for (Calendar calendar : calendarsSet) { JSONObject jsonObject = CalendarUtil.toCalendarJSONObject(themeDisplay, calendar); jsonArray.put(jsonObject); } writeJSON(resourceRequest, resourceResponse, jsonArray); }