Sites

Necessary Liferay-Service:

com.liferay.portal.service.GroupLocalServiceUtil
com.liferay.portal.service.MembershipRequestLocalServiceUtil
Add Site programmatically:
ServiceContext serviceContext = 
ServiceContextFactory.getInstance(ActionRequest request);

GroupLocalServiceUtil.
addGroup(userId, className, classPK, name, description, type, 
friendlyURL, site, active, serviceContext);
You can use the serviceContext to set more properties like:
serviceContext.
setAddGroupPermissions(boolean addGroupPermissions);
serviceContext.
setAddGuestPermissions(boolean addGuestPermissions);
The possible types can be found in com.liferay.portal.model.GroupConstants. Often used values are:
GroupConstants.TYPE_SITE_RESTRICTED
GroupConstants.TYPE_SITE_PRIVATE
GroupConstants.TYPE_SITE_OPEN
For Sites with restricted access you can add a Site-Membership request programmatically:
ServiceContext serviceContext = ServiceContextFactory.getInstance(Group.class.getName(), ActionRequest request);
MembershipRequestLocalServiceUtil.addMembershipRequest(userId, groupId, comments, serviceContext);

Leave a Reply