Skip to content

Instantly share code, notes, and snippets.

@martinlau
Last active May 23, 2017 08:02
Show Gist options
  • Save martinlau/4491042 to your computer and use it in GitHub Desktop.
Save martinlau/4491042 to your computer and use it in GitHub Desktop.
Sample code to create a site in liferay (don't do this)
public class SiteCreator {
public static void createGroup() throws Exception {
// Don't do this!
long groupId = CounterLocalServiceUtil.increment(Group.class.getName());
Group group = GroupLocalServiceUtil.createGroup(groupId);
group.setName("Test Site");
group.setDescription("This is a test site");
group.setFriendlyURL("/test-site");
// Set a bunch of other properties
GroupLocalServiceUtil.addGroup(group);
long layoutSetId = CounterLocalServiceUtil.increment(LayoutSet.class.getName());
LayoutSet layoutSet = LayoutSetLocalServiceUtil.createLayoutSet(layoutSetId);
layoutSet.setGroupId(groupId);
layoutSet.setPrivateLayout(false);
layoutSet.setThemeId("classic");
layoutSet.setColorSchemeId("01");
// Set a bunch of other properties
LayoutSetLocalServiceUtil.addLayoutSet(layoutSet);
long resourcePermissionId = CounterLocalServiceUtil.increment(ResourcePermission.class.getName());
ResourcePermission resourcePermission = ResourcePermissionLocalServiceUtil.createResourcePermission(resourcePermissionId);
resourcePermission.setName(Group.class.getName());
resourcePermission.setPrimaryKey(groupId);
// Set a bunch of other properties
ResourcePermissionLocalServiceUtil.addResourcePermission(resourcePermission);
// Continue on with other objects, properties as needed until you get the job done...
}
}
@nicolas-raoul
Copy link

nicolas-raoul commented May 23, 2017

Why did you write "don't do this"?
Is there a better way to create a site/group programmatically?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment