Search code examples
javaliferayliferay-7

Programmatically get list of sites in Liferay


I want to get the list of sites in Liferay, the same that appears at http://localhost:8080/group/control_panel/manage/-/sites/sites :

Liferay sites

In SQL I would run select * from Group_ WHERE site=1.

How to get the same thing in Java?

GroupServiceUtil does not seem to have such a method.

Note: My Java code is in a module running within Liferay, but not a portlet.


Solution

  • You could use public List<Group> getGroups(long companyId, long parentGroupId, boolean site) of GroupLocalServiceUtil (https://docs.liferay.com/dxp/digital-enterprise/7.0-sp1/javadocs/portal-kernel/com/liferay/portal/kernel/service/GroupLocalServiceUtil.html#getGroups-long-long-boolean-). It should be callable when you are not inside a OSGi based portlet. If you inside of a OSGi Component, you could inject GroupLocalService. If you do not care about parentGroup, you could use GroupConstants.ANY_PARENT_GROUP_ID as parentGroupId instead.