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

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

Introduction

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

Prototype

public static int searchCount(long companyId, long[] classNameIds, String keywords,
        java.util.LinkedHashMap<String, Object> params) 

Source Link

Document

Returns the number of groups that match the class name IDs, and keywords, optionally including the user's inherited organization groups and user groups.

Usage

From source file:com.liferay.item.selector.taglib.servlet.taglib.GroupSelectorTag.java

License:Open Source License

protected int getGroupsCount(HttpServletRequest request) {
    if ((_groups != null) || (_groupsCount > 0)) {
        return _groupsCount;
    }/*from ww  w .j a  v a 2 s  .co  m*/

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

    String keywords = ParamUtil.getString(request, "keywords");

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

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

    return GroupLocalServiceUtil.searchCount(themeDisplay.getCompanyId(), _CLASS_NAME_IDS, keywords,
            groupParams);
}

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));
    }/* www .  java 2s  . c  o 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;
}

From source file:com.liferay.site.service.persistence.test.GroupServiceTest.java

License:Open Source License

@Test
public void testFindGroupByDescription() throws Exception {
    Group group = GroupTestUtil.addGroup(GroupConstants.DEFAULT_PARENT_GROUP_ID);

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

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

    Assert.assertEquals(1, GroupLocalServiceUtil.searchCount(TestPropsValues.getCompanyId(), null,
            group.getDescription(getLocale()), groupParams));

    GroupLocalServiceUtil.deleteGroup(group);
}

From source file:com.liferay.site.service.persistence.test.GroupServiceTest.java

License:Open Source License

@Test
public void testFindGroupByDescriptionWithSpaces() throws Exception {
    Group group = GroupTestUtil.addGroup(GroupConstants.DEFAULT_PARENT_GROUP_ID);

    group.setDescription(RandomTestUtil.randomString() + StringPool.SPACE + RandomTestUtil.randomString());

    GroupLocalServiceUtil.updateGroup(group);

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

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

    Assert.assertEquals(1, GroupLocalServiceUtil.searchCount(TestPropsValues.getCompanyId(), null,
            group.getDescription(getLocale()), groupParams));

    GroupLocalServiceUtil.deleteGroup(group);
}

From source file:com.liferay.site.service.persistence.test.GroupServiceTest.java

License:Open Source License

@Test
public void testFindGroupByName() throws Exception {
    Group group = GroupTestUtil.addGroup(GroupConstants.DEFAULT_PARENT_GROUP_ID);

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

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

    Assert.assertEquals(1, GroupLocalServiceUtil.searchCount(TestPropsValues.getCompanyId(), null,
            group.getName(getLocale()), groupParams));

    GroupLocalServiceUtil.deleteGroup(group);
}

From source file:com.liferay.site.service.persistence.test.GroupServiceTest.java

License:Open Source License

@Test
public void testFindGroupByNameWithSpaces() throws Exception {
    Group group = GroupTestUtil.addGroup(GroupConstants.DEFAULT_PARENT_GROUP_ID);

    group.setName(RandomTestUtil.randomString() + StringPool.SPACE + RandomTestUtil.randomString());

    GroupLocalServiceUtil.updateGroup(group);

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

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

    Assert.assertEquals(1, GroupLocalServiceUtil.searchCount(TestPropsValues.getCompanyId(), null,
            group.getName(getLocale()), groupParams));

    GroupLocalServiceUtil.deleteGroup(group);
}

From source file:com.liferay.site.service.persistence.test.GroupServiceTest.java

License:Open Source License

@Test
public void testFindGuestGroupByCompanyName() throws Exception {
    LinkedHashMap<String, Object> groupParams = new LinkedHashMap<>();

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

    Assert.assertEquals(1,//from   ww w. j a v a 2 s.co m
            GroupLocalServiceUtil.searchCount(TestPropsValues.getCompanyId(), null, "liferay%", groupParams));
}

From source file:com.liferay.site.service.persistence.test.GroupServiceTest.java

License:Open Source License

@Test
public void testFindGuestGroupByCompanyNameCapitalized() throws Exception {
    LinkedHashMap<String, Object> groupParams = new LinkedHashMap<>();

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

    Assert.assertEquals(1,/*from   www.j  ava 2 s  .  c o  m*/
            GroupLocalServiceUtil.searchCount(TestPropsValues.getCompanyId(), null, "Liferay%", groupParams));
}

From source file:com.liferay.site.service.persistence.test.GroupServiceTest.java

License:Open Source License

@Test
public void testFindNonexistentGroup() throws Exception {
    LinkedHashMap<String, Object> groupParams = new LinkedHashMap<>();

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

    Assert.assertEquals(0,/*w w w .j a  v  a 2s  .com*/
            GroupLocalServiceUtil.searchCount(TestPropsValues.getCompanyId(), null, "cabina14", groupParams));
}