Example usage for com.liferay.portal.kernel.service RoleLocalServiceUtil addRole

List of usage examples for com.liferay.portal.kernel.service RoleLocalServiceUtil addRole

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service RoleLocalServiceUtil addRole.

Prototype

public static com.liferay.portal.kernel.model.Role addRole(long userId, String className, long classPK,
        String name, java.util.Map<java.util.Locale, String> titleMap,
        java.util.Map<java.util.Locale, String> descriptionMap, int type, String subtype,
        ServiceContext serviceContext) throws com.liferay.portal.kernel.exception.PortalException 

Source Link

Document

Adds a role with additional parameters.

Usage

From source file:com.liferay.bookmarks.service.test.BookmarksFolderLocalServiceTest.java

License:Open Source License

@Test
public void testAddSubfolderPermission() throws Exception {
    BookmarksFolder folder = BookmarksTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString());

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    Role role = RoleLocalServiceUtil.addRole(TestPropsValues.getUserId(), null, 0, StringUtil.randomString(),
            null, null, RoleConstants.TYPE_SITE, null, serviceContext);

    ResourceBlockServiceUtil.addCompanyScopePermission(_group.getGroupId(), _group.getCompanyId(),
            BookmarksFolder.class.getName(), role.getRoleId(), ActionKeys.ADD_SUBFOLDER);

    User user = UserTestUtil.addGroupUser(_group, role.getName());

    PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user);

    Assert.assertTrue(BookmarksFolderPermissionChecker.contains(permissionChecker, _group.getGroupId(),
            folder.getFolderId(), ActionKeys.ADD_FOLDER));
}

From source file:com.liferay.exportimport.lar.PermissionImporter.java

License:Open Source License

protected Role checkRole(LayoutCache layoutCache, long companyId, long groupId, long userId,
        Element roleElement) throws Exception {

    String name = roleElement.attributeValue("name");

    Role role = null;//from  w ww.jav  a 2s  .  com

    if (ExportImportPermissionUtil.isTeamRoleName(name)) {
        name = name.substring(ExportImportPermissionUtil.ROLE_TEAM_PREFIX.length());

        String description = roleElement.attributeValue("description");

        Team team = null;

        try {
            team = TeamLocalServiceUtil.getTeam(groupId, name);
        } catch (NoSuchTeamException nste) {

            // LPS-52675

            if (_log.isDebugEnabled()) {
                _log.debug(nste, nste);
            }

            team = TeamLocalServiceUtil.addTeam(userId, groupId, name, description, new ServiceContext());
        }

        role = RoleLocalServiceUtil.getTeamRole(companyId, team.getTeamId());

        return role;
    }

    String uuid = roleElement.attributeValue("uuid");

    role = layoutCache.getUuidRole(companyId, uuid);

    if (role == null) {
        role = layoutCache.getNameRole(companyId, name);
    }

    if ((role != null) || MergeLayoutPrototypesThreadLocal.isInProgress()) {
        return role;
    }

    String title = roleElement.attributeValue("title");

    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(title);

    String description = roleElement.attributeValue("description");

    Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(description);

    int type = GetterUtil.getInteger(roleElement.attributeValue("type"));
    String subtype = roleElement.attributeValue("subtype");

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setUuid(uuid);

    role = RoleLocalServiceUtil.addRole(userId, null, 0, name, titleMap, descriptionMap, type, subtype,
            serviceContext);

    return role;
}

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularRoleServiceImpl.java

License:Open Source License

@Override
public Role createRole(String name, int type, String className, Map<Locale, String> titleMap,
        Map<Locale, String> descriptionMap, String subType) throws PortalException {
    _log.info("Creating role ... ");

    _log.debug("    security check ... ");

    PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_ROLE);

    _log.debug("    writing information ... ");

    return RoleLocalServiceUtil.addRole(this.getUserId(), className, 0, name, titleMap, descriptionMap, type,
            subType, null);/*from w w w .  j ava 2 s.c om*/
}