Example usage for com.liferay.portal.kernel.service GroupLocalServiceUtil getGroups

List of usage examples for com.liferay.portal.kernel.service GroupLocalServiceUtil getGroups

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service GroupLocalServiceUtil getGroups.

Prototype

public static java.util.List<com.liferay.portal.kernel.model.Group> getGroups(long companyId, String className,
        long parentGroupId, int start, int end) 

Source Link

Document

Returns a range of all the groups that are direct children of the parent group with the matching className.

Usage

From source file:com.liferay.asset.publisher.web.display.context.LayoutScopesItemSelectorViewDisplayContext.java

License:Open Source License

@Override
public GroupSearch getGroupSearch() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    GroupSearch groupSearch = new GroupSearch(getPortletRequest(), getPortletURL());

    int total = GroupLocalServiceUtil.getGroupsCount(themeDisplay.getCompanyId(), Layout.class.getName(),
            getGroupId());//from  w ww .  ja v  a  2s  .  c o m

    groupSearch.setTotal(total);

    List<Group> groups = GroupLocalServiceUtil.getGroups(themeDisplay.getCompanyId(), Layout.class.getName(),
            getGroupId(), groupSearch.getStart(), groupSearch.getEnd());

    groups = _filterLayoutGroups(groups, _isPrivateLayout());

    groupSearch.setResults(groups);

    return groupSearch;
}

From source file:com.liferay.site.browser.web.internal.display.context.SiteBrowserDisplayContext.java

License:Open Source License

public GroupSearch getGroupSearch() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    Company company = themeDisplay.getCompany();

    GroupSearch groupSearch = new GroupSearch(_liferayPortletRequest, getPortletURL());

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

    List<Group> results = new ArrayList<>();

    int additionalSites = 0;
    int total = 0;

    boolean includeCompany = ParamUtil.getBoolean(_request, "includeCompany");
    boolean includeUserPersonalSite = ParamUtil.getBoolean(_request, "includeUserPersonalSite");

    long[] classNameIds = _CLASS_NAME_IDS;

    if (includeCompany) {
        classNameIds = ArrayUtil.append(classNameIds, PortalUtil.getClassNameId(Company.class));
    }//  w  w  w .j  a  v a  2s  . c om

    if (includeUserPersonalSite) {
        if (groupSearch.getStart() == 0) {
            Group userPersonalSite = GroupLocalServiceUtil.getGroup(company.getCompanyId(),
                    GroupConstants.USER_PERSONAL_SITE);

            results.add(userPersonalSite);
        }

        additionalSites++;
    }

    String type = getType();

    if (type.equals("layoutScopes")) {
        total = GroupLocalServiceUtil.getGroupsCount(themeDisplay.getCompanyId(), Layout.class.getName(),
                getGroupId());
    } else if (type.equals("parent-sites")) {
    } else {
        total = GroupLocalServiceUtil.searchCount(themeDisplay.getCompanyId(), classNameIds,
                groupSearchTerms.getKeywords(), getGroupParams());
    }

    total += additionalSites;

    groupSearch.setTotal(total);

    int start = groupSearch.getStart();

    if (groupSearch.getStart() > additionalSites) {
        start = groupSearch.getStart() - additionalSites;
    }

    List<Group> groups = null;

    if (type.equals("layoutScopes")) {
        groups = GroupLocalServiceUtil.getGroups(company.getCompanyId(), Layout.class.getName(), getGroupId(),
                start, groupSearch.getResultEnd() - additionalSites);

        groups = _filterLayoutGroups(groups, isPrivateLayout());
    } else if (type.equals("parent-sites")) {
        Group group = GroupLocalServiceUtil.getGroup(getGroupId());

        groups = group.getAncestors();

        String filter = getFilter();

        if (Validator.isNotNull(filter)) {
            groups = _filterGroups(groups, filter);
        }

        total = groups.size();

        total += additionalSites;

        groupSearch.setTotal(total);
    } else {
        groups = GroupLocalServiceUtil.search(company.getCompanyId(), classNameIds,
                groupSearchTerms.getKeywords(), getGroupParams(), QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                groupSearch.getOrderByComparator());

        groups = _filterGroups(groups, themeDisplay.getPermissionChecker());

        total = groups.size();

        total += additionalSites;

        groupSearch.setTotal(total);

        groups = groups.subList(start, groupSearch.getResultEnd() - additionalSites);
    }

    results.addAll(groups);

    groupSearch.setResults(results);

    return groupSearch;
}