Skip to content

Instantly share code, notes, and snippets.

@rotty3000
Created October 12, 2011 13:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rotty3000/1281235 to your computer and use it in GitHub Desktop.
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));
dynamicQuery.add(RestrictionsFactoryUtil.eq(
"classNameId", PortalUtil.getClassNameId(Group.class)));
dynamicQuery.add(RestrictionsFactoryUtil.eq(
"type", GroupConstants.TYPE_COMMUNITY_OPEN));
dynamicQuery.add(RestrictionsFactoryUtil.not(
RestrictionsFactoryUtil.in("groupId", usersGroupIds)));
dynamicQuery.add(RestrictionsFactoryUtil.ne(
"name", GroupConstants.GUEST));
return GroupLocalServiceUtil.dynamicQuery(
dynamicQuery, start, end);
}
}
LinkedHashMap groupParams = new LinkedHashMap();
long[] classNameIds = new long[] {
PortalUtil.getClassNameId(Group.class)
, 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 = GroupLocalServiceUtil.search(company.getCompanyId(), 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