Skip to content

Instantly share code, notes, and snippets.

@kimakunc
Created May 28, 2013 09:36
Show Gist options
  • Save kimakunc/5661627 to your computer and use it in GitHub Desktop.
Save kimakunc/5661627 to your computer and use it in GitHub Desktop.
Liferay 6.1 create a regular role
public static void createRegularRole(String roleName, Map<Locale, String> title, Map<Locale, String> description) {
long companyId = PortalUtil.getDefaultCompanyId();
int type = RoleConstants.TYPE_REGULAR;
try {
Role newRole = RoleLocalServiceUtil.addRole(LiferayUtil.getDefaultUserId(companyId), companyId, roleName,
title, description, type);
LOGGER.info("Added new role with id [" + newRole.getRoleId() + "] and name [" + newRole.getName() + "].");
} catch (Exception e) {
if (e instanceof DuplicateRoleException) {
LOGGER.debug("Role [" + roleName + "] already exists.");
} else {
LOGGER.error("Error on creating role with name [" + roleName + "]
and title [" + title.get(LocaleUtil.getDefault()) + "].", e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment