Example usage for com.liferay.portal.kernel.model Role getDescriptiveName

List of usage examples for com.liferay.portal.kernel.model Role getDescriptiveName

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model Role getDescriptiveName.

Prototype

public String getDescriptiveName() throws com.liferay.portal.kernel.exception.PortalException;

Source Link

Usage

From source file:com.liferay.announcements.web.internal.display.context.DefaultAnnouncementsAdminViewDisplayContext.java

License:Open Source License

@Override
public Map<String, String> getDistributionScopes() throws Exception {
    Map<String, String> distributionScopes = new LinkedHashMap<>();

    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (PortalPermissionUtil.contains(permissionChecker, ActionKeys.ADD_GENERAL_ANNOUNCEMENTS)) {

        distributionScopes.put("general", "0,0");
    }//  w w w. ja va 2 s.c  o  m

    List<Group> groups = AnnouncementsUtil.getGroups(themeDisplay);

    for (Group group : groups) {
        distributionScopes.put(
                StringBundler.concat(group.getDescriptiveName(themeDisplay.getLocale()), " (",
                        LanguageUtil.get(_request, "site"), ")"),
                PortalUtil.getClassNameId(Group.class) + StringPool.COMMA + group.getGroupId());
    }

    List<Organization> organizations = AnnouncementsUtil.getOrganizations(themeDisplay);

    for (Organization organization : organizations) {
        String name = StringBundler.concat(organization.getName(), " (",
                LanguageUtil.get(_request, "organization"), ")");

        distributionScopes.put(name, PortalUtil.getClassNameId(Organization.class) + StringPool.COMMA
                + organization.getOrganizationId());
    }

    List<Role> roles = AnnouncementsUtil.getRoles(themeDisplay);

    for (Role role : roles) {
        distributionScopes.put(
                StringBundler.concat(role.getDescriptiveName(), " (", LanguageUtil.get(_request, "role"), ")"),
                PortalUtil.getClassNameId(Role.class) + StringPool.COMMA + role.getRoleId());
    }

    List<UserGroup> userGroups = AnnouncementsUtil.getUserGroups(themeDisplay);

    for (UserGroup userGroup : userGroups) {
        distributionScopes.put(
                StringBundler.concat(userGroup.getName(), " (", LanguageUtil.get(_request, "user-group"), ")"),
                PortalUtil.getClassNameId(UserGroup.class) + StringPool.COMMA + userGroup.getUserGroupId());
    }

    return distributionScopes;
}

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

License:Open Source License

protected void exportPermissions(PortletDataContext portletDataContext, String resourceName,
        String resourcePrimKey, Element permissionsElement) throws Exception {

    List<String> actionIds = ResourceActionsUtil.getPortletResourceActions(resourceName);

    Map<Long, Set<String>> roleToActionIds = ExportImportPermissionUtil
            .getRoleIdsToActionIds(portletDataContext.getCompanyId(), resourceName, resourcePrimKey, actionIds);

    for (Map.Entry<Long, Set<String>> entry : roleToActionIds.entrySet()) {
        long roleId = entry.getKey();

        Role role = RoleLocalServiceUtil.fetchRole(roleId);

        String roleName = role.getName();

        if (role.isTeam()) {
            try {
                roleName = ExportImportPermissionUtil.getTeamRoleName(role.getDescriptiveName());
            } catch (PortalException pe) {

                // LPS-52675

                if (_log.isDebugEnabled()) {
                    _log.debug(pe, pe);//  ww  w . j  a v  a 2s.c om
                }
            }
        }

        Element roleElement = permissionsElement.addElement("role");

        roleElement.addAttribute("uuid", role.getUuid());
        roleElement.addAttribute("name", roleName);
        roleElement.addAttribute("title", role.getTitle());
        roleElement.addAttribute("description", role.getDescription());
        roleElement.addAttribute("type", String.valueOf(role.getType()));
        roleElement.addAttribute("subtype", role.getSubtype());

        Set<String> availableActionIds = entry.getValue();

        for (String actionId : availableActionIds) {
            Element actionKeyElement = roleElement.addElement("action-key");

            actionKeyElement.addText(actionId);
        }
    }
}

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

License:Open Source License

@Override
public void addPermissions(String resourceName, long resourcePK) {
    if (!MapUtil.getBoolean(_parameterMap, PortletDataHandlerKeys.PERMISSIONS)) {

        return;//from   w  w  w.  j a va 2  s. c  o  m
    }

    Map<Long, Set<String>> roleIdsToActionIds = ExportImportPermissionUtil.getRoleIdsToActionIds(_companyId,
            resourceName, resourcePK);

    List<KeyValuePair> permissions = new ArrayList<>();

    for (Map.Entry<Long, Set<String>> entry : roleIdsToActionIds.entrySet()) {

        long roleId = entry.getKey();
        Set<String> availableActionIds = entry.getValue();

        Role role = RoleLocalServiceUtil.fetchRole(roleId);

        if (role == null) {
            continue;
        }

        String roleName = role.getName();

        if (role.isTeam()) {
            try {
                roleName = ExportImportPermissionUtil.getTeamRoleName(role.getDescriptiveName());
            } catch (PortalException pe) {
                _log.error(pe, pe);
            }
        }

        KeyValuePair permission = new KeyValuePair(roleName, StringUtil.merge(availableActionIds));

        permissions.add(permission);
    }

    if (permissions.isEmpty()) {
        return;
    }

    _permissionsMap.put(getPrimaryKeyString(resourceName, resourcePK), permissions);
}