Example usage for com.liferay.portal.kernel.model Group getAncestors

List of usage examples for com.liferay.portal.kernel.model Group getAncestors

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model Group getAncestors.

Prototype

public java.util.List<Group> getAncestors();

Source Link

Usage

From source file:com.liferay.asset.publisher.web.display.context.ParentSitesItemSelectorViewDisplayContext.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());

    Group group = themeDisplay.getSiteGroup();

    List<Group> groups = group.getAncestors();

    groups = _filterParentSitesGroups(groups);

    groupSearch.setTotal(groups.size());

    groupSearch.setResults(groups);//from www  .  ja  va  2  s. c o  m

    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));
    }//from ww  w .  j  a  v a2  s  .co m

    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;
}