Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
How to get allCurrentSites by API
Hi,
I need to show all current Sites in a portlet.
I've read that sites are Groups in liferay whit type=1 and isSite=true.
After a time searching in Internet how to do this, I found the following solution:
List<Group> listAllCompanies = GroupLocalServiceUtil.search(PortalUtil.getCompanyId(request), null, null,null, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
// define a new list ONLY for sites,
List<Group>
sites = new ArrayList<Group>();
// filter the original
list and populate the new list
for (Group group:
listAllCompanies) {
if (group.getType() == 1 &&
group.isSite()) {
sites.add(group);
}
}
This code works properly and in sites variable I have only the
sites I want to show, the problem is the performance, I have about
55000 groups to loop.
Is there any way to improve this performance or maybe using other API?
Kind regards,
Iñigo
I don't think there is an other way. Could you cache them? Maybe add a model listener that clears the cache?
The following code will narrow down the search query to pull the sites only (tested on 7/DXP):
LinkedHashMap<String, Object> params = new
LinkedHashMap<String, Object>();
params.put("site", new Boolean(true));
List<Group> allGroupsList =
GroupLocalServiceUtil.search(companyId, params , QueryUtil.ALL_POS,
QueryUtil.ALL_POS);
Powered by Liferay™