protected LinkedHashMap<String, Object> getGroupParams(
      PortletRequest portletRequest, GroupSearchTerms searchTerms, long parentGroupId)
      throws PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    LinkedHashMap<String, Object> groupParams = new LinkedHashMap<>();

    groupParams.put("site", Boolean.TRUE);

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    User user = themeDisplay.getUser();

    if (searchTerms.hasSearchTerms()) {
      if (isFilterManageableGroups(portletRequest)) {
        groupParams.put("groupsTree", getAllGroups(portletRequest));
      } else if (parentGroupId > 0) {
        List<Group> groupsTree = new ArrayList<>();

        Group parentGroup = _groupLocalService.getGroup(parentGroupId);

        groupsTree.add(parentGroup);

        groupParams.put("groupsTree", groupsTree);
      }

      if (!permissionChecker.isCompanyAdmin()
          && !GroupPermissionUtil.contains(permissionChecker, ActionKeys.VIEW)) {

        groupParams.put("usersGroups", Long.valueOf(user.getUserId()));
      }
    }

    return groupParams;
  }
  public GroupSearch getGroupSearch(PortletRequest portletRequest, PortletURL portletURL)
      throws PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    GroupSearch groupSearch = new GroupSearch(portletRequest, portletURL);

    GroupSearchTerms searchTerms = (GroupSearchTerms) groupSearch.getSearchTerms();

    if (!searchTerms.isSearch()) {
      groupSearch.setEmptyResultsMessageCssClass("taglib-empty-result-message-header-has-plus-btn");
    } else {
      groupSearch.setSearch(true);
    }

    long parentGroupId = getParentGroupId(portletRequest);

    Company company = themeDisplay.getCompany();

    List results = null;

    if (!searchTerms.hasSearchTerms()
        && isFilterManageableGroups(portletRequest)
        && (parentGroupId <= 0)) {

      List<Group> groups = getAllGroups(portletRequest);

      groupSearch.setTotal(groups.size());

      results = ListUtil.subList(groups, groupSearch.getStart(), groupSearch.getEnd());
    } else if (searchTerms.hasSearchTerms()) {
      int total =
          _groupLocalService.searchCount(
              company.getCompanyId(),
              _classNameIds,
              searchTerms.getKeywords(),
              getGroupParams(portletRequest, searchTerms, parentGroupId));

      groupSearch.setTotal(total);

      results =
          _groupLocalService.search(
              company.getCompanyId(),
              _classNameIds,
              searchTerms.getKeywords(),
              getGroupParams(portletRequest, searchTerms, parentGroupId),
              groupSearch.getStart(),
              groupSearch.getEnd(),
              groupSearch.getOrderByComparator());
    } else {
      long groupId =
          ParamUtil.getLong(portletRequest, "groupId", GroupConstants.DEFAULT_PARENT_GROUP_ID);

      int total =
          _groupLocalService.searchCount(
              company.getCompanyId(),
              _classNameIds,
              groupId,
              searchTerms.getKeywords(),
              getGroupParams(portletRequest, searchTerms, parentGroupId));

      groupSearch.setTotal(total);

      results =
          _groupLocalService.search(
              company.getCompanyId(),
              _classNameIds,
              groupId,
              searchTerms.getKeywords(),
              getGroupParams(portletRequest, searchTerms, parentGroupId),
              groupSearch.getStart(),
              groupSearch.getEnd(),
              groupSearch.getOrderByComparator());
    }

    groupSearch.setResults(results);

    return groupSearch;
  }