Nicolas Raoul
Nicolas Raoul

Reputation: 60213

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.

Upvotes: 1

Views: 2145

Answers (1)

Andre Albert
Andre Albert

Reputation: 1394

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.

Upvotes: 1

Related Questions