public
Created

list open and accessible sites

  • Download Gist
dynamicQuery_way.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/**
* 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);
}
}
list-sites.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
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);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.