Create a gist now

Instantly share code, notes, and snippets.

list open and accessible sites
* Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
package com.liferay.portal.service;
import com.liferay.portal.kernel.dao.orm.DynamicQuery;
import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
import com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.GroupConstants;
import com.liferay.portal.util.PortalUtil;
import java.util.List;
* @author Raymond Augé
public class Test {
public List<Group> getOpenSitesUserIsNotIn(
long companyId, Object[] usersGroupIds, int start, int end)
throws SystemException {
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
Group.class, PortalClassLoaderUtil.getClassLoader());
dynamicQuery.add(RestrictionsFactoryUtil.eq("companyId", companyId));
"classNameId", PortalUtil.getClassNameId(Group.class)));
"type", GroupConstants.TYPE_COMMUNITY_OPEN));
dynamicQuery.add(RestrictionsFactoryUtil.not("groupId", usersGroupIds)));
"name", GroupConstants.GUEST));
return GroupLocalServiceUtil.dynamicQuery(
dynamicQuery, start, end);
LinkedHashMap groupParams = new LinkedHashMap();
long[] classNameIds = new long[] {
, PortalUtil.getClassNameId(Organization.class) // take this out of you don't want orgs listed
groupParams.put("site", Boolean.TRUE);
List types = new ArrayList();
types.add(new Integer(GroupConstants.TYPE_SITE_OPEN));
types.add(new Integer(GroupConstants.TYPE_SITE_RESTRICTED));
groupParams.put("types", types);
groupParams.put("active", Boolean.TRUE);
int total = GroupLocalServiceUtil.searchCount(company.getCompanyId(), classNameIds, name, description, groupParams);
List results =, classNameIds, name, description, groupParams, -1, -1, null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment