/**
   * Checks to ensure that the system roles map has appropriate default roles in the company.
   *
   * @param companyId the primary key of the company
   * @throws PortalException if the current user did not have permission to set applicable
   *     permissions on a role
   * @throws SystemException if a system exception occurred
   */
  @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
  public void checkSystemRoles(long companyId) throws PortalException, SystemException {

    String companyIdHexString = StringUtil.toHexString(companyId);

    for (Role role : roleFinder.findBySystem(companyId)) {
      _systemRolesMap.put(companyIdHexString.concat(role.getName()), role);
    }

    // Regular roles

    String[] systemRoles = PortalUtil.getSystemRoles();

    for (String name : systemRoles) {
      String key =
          "system.role."
              + StringUtil.replace(name, CharPool.SPACE, CharPool.PERIOD)
              + ".description";

      Map<Locale, String> descriptionMap = new HashMap<Locale, String>();

      descriptionMap.put(LocaleUtil.getDefault(), PropsUtil.get(key));

      int type = RoleConstants.TYPE_REGULAR;

      checkSystemRole(companyId, name, descriptionMap, type);
    }

    // Organization roles

    String[] systemOrganizationRoles = PortalUtil.getSystemOrganizationRoles();

    for (String name : systemOrganizationRoles) {
      String key =
          "system.organization.role."
              + StringUtil.replace(name, CharPool.SPACE, CharPool.PERIOD)
              + ".description";

      Map<Locale, String> descriptionMap = new HashMap<Locale, String>();

      descriptionMap.put(LocaleUtil.getDefault(), PropsUtil.get(key));

      int type = RoleConstants.TYPE_ORGANIZATION;

      checkSystemRole(companyId, name, descriptionMap, type);
    }

    // Site roles

    String[] systemSiteRoles = PortalUtil.getSystemSiteRoles();

    for (String name : systemSiteRoles) {
      String key =
          "system.site.role."
              + StringUtil.replace(name, CharPool.SPACE, CharPool.PERIOD)
              + ".description";

      Map<Locale, String> descriptionMap = new HashMap<Locale, String>();

      descriptionMap.put(LocaleUtil.getDefault(), PropsUtil.get(key));

      int type = RoleConstants.TYPE_SITE;

      checkSystemRole(companyId, name, descriptionMap, type);
    }
  }
Example #2
0
  private static void _localizeRoleNames(long companyId, String languageId) throws Exception {

    ServiceContext serviceContext = new ServiceContext();

    // Regular roles

    for (String name : PortalUtil.getSystemRoles()) {
      Role role = RoleLocalServiceUtil.loadGetRole(companyId, name);

      Map<Locale, String> descriptionMap = role.getDescriptionMap();
      Map<Locale, String> titleMap = role.getTitleMap();

      if (name.equals(RoleConstants.ADMINISTRATOR)) {
        _putMap(descriptionMap, languageId, ROLE_ADMINISTRATOR_DESCRIPTION);
        _putMap(titleMap, languageId, ROLE_ADMINISTRATOR_NAME);
      } else if (name.equals(RoleConstants.GUEST)) {
        _putMap(descriptionMap, languageId, ROLE_GUEST_DESCRIPTION);
        _putMap(titleMap, languageId, ROLE_GUEST_NAME);
      } else if (name.equals(RoleConstants.OWNER)) {
        _putMap(descriptionMap, languageId, ROLE_OWNER_DESCRIPTION);
        _putMap(titleMap, languageId, ROLE_OWNER_NAME);
      } else if (name.equals(RoleConstants.POWER_USER)) {
        _putMap(descriptionMap, languageId, ROLE_POWER_USER_DESCRIPTION);
        _putMap(titleMap, languageId, ROLE_POWER_USER_NAME);
      } else if (name.equals(RoleConstants.USER)) {
        _putMap(descriptionMap, languageId, ROLE_USER_DESCRIPTION);
        _putMap(titleMap, languageId, ROLE_USER_NAME);
      }

      RoleLocalServiceUtil.updateRole(
          role.getRoleId(),
          name,
          titleMap,
          descriptionMap,
          RoleConstants.TYPE_REGULAR_LABEL,
          serviceContext);
    }

    // Organization roles

    for (String name : PortalUtil.getSystemOrganizationRoles()) {
      Role role = RoleLocalServiceUtil.loadGetRole(companyId, name);

      Map<Locale, String> descriptionMap = role.getDescriptionMap();
      Map<Locale, String> titleMap = role.getTitleMap();

      if (name.equals(RoleConstants.ORGANIZATION_ADMINISTRATOR)) {
        _putMap(descriptionMap, languageId, ROLE_ORGANIZATION_ADMINISTRATOR_DESCRIPTION);
        _putMap(titleMap, languageId, ROLE_ORGANIZATION_ADMINISTRATOR_NAME);
      } else if (name.equals(RoleConstants.ORGANIZATION_OWNER)) {
        _putMap(descriptionMap, languageId, ROLE_ORGANIZATION_OWNER_DESCRIPTION);
        _putMap(titleMap, languageId, ROLE_ORGANIZATION_OWNER_NAME);
      } else if (name.equals(RoleConstants.ORGANIZATION_USER)) {
        _putMap(descriptionMap, languageId, ROLE_ORGANIZATION_USER_DESCRIPTION);
        _putMap(titleMap, languageId, ROLE_ORGANIZATION_USER_NAME);
      }

      RoleLocalServiceUtil.updateRole(
          role.getRoleId(),
          name,
          titleMap,
          descriptionMap,
          RoleConstants.TYPE_ORGANIZATION_LABEL,
          serviceContext);
    }

    // Site roles

    for (String name : PortalUtil.getSystemSiteRoles()) {
      Role role = RoleLocalServiceUtil.loadGetRole(companyId, name);

      Map<Locale, String> descriptionMap = role.getDescriptionMap();
      Map<Locale, String> titleMap = role.getTitleMap();

      if (name.equals(RoleConstants.SITE_ADMINISTRATOR)) {
        _putMap(descriptionMap, languageId, ROLE_SITE_ADMINISTRATOR_DESCRIPTION);
        _putMap(titleMap, languageId, ROLE_SITE_ADMINISTRATOR_NAME);
      } else if (name.equals(RoleConstants.SITE_MEMBER)) {
        _putMap(descriptionMap, languageId, ROLE_SITE_MEMBER_DESCRIPTION);
        _putMap(titleMap, languageId, ROLE_SITE_MEMBER_NAME);
      } else if (name.equals(RoleConstants.SITE_OWNER)) {
        _putMap(descriptionMap, languageId, ROLE_SITE_OWNER_DESCRIPTION);
        _putMap(titleMap, languageId, ROLE_SITE_OWNER_NAME);
      }

      RoleLocalServiceUtil.updateRole(
          role.getRoleId(),
          name,
          titleMap,
          descriptionMap,
          RoleConstants.TYPE_SITE_LABEL,
          serviceContext);
    }
  }
  public static void localizeRoleNames(long companyId) throws Exception {

    // Regular roles

    for (String name : PortalUtil.getSystemRoles()) {
      Role role = RoleLocalServiceUtil.getRole(companyId, name);

      Map<Locale, String> descriptionMap = role.getDescriptionMap();
      Map<Locale, String> titleMap = role.getTitleMap();

      if (name.equals(RoleConstants.ADMINISTRATOR)) {
        descriptionMap.put(_getLocale(), PortletPropsValues.ROLE_ADMINISTRATOR_DESCRIPTION);
        titleMap.put(_getLocale(), PortletPropsValues.ROLE_ADMINISTRATOR_NAME);
      } else if (name.equals(RoleConstants.GUEST)) {
        descriptionMap.put(_getLocale(), PortletPropsValues.ROLE_GUEST_DESCRIPTION);
        titleMap.put(_getLocale(), PortletPropsValues.ROLE_GUEST_NAME);
      } else if (name.equals(RoleConstants.OWNER)) {
        descriptionMap.put(_getLocale(), PortletPropsValues.ROLE_OWNER_DESCRIPTION);
        titleMap.put(_getLocale(), PortletPropsValues.ROLE_OWNER_NAME);
      } else if (name.equals(RoleConstants.POWER_USER)) {
        descriptionMap.put(_getLocale(), PortletPropsValues.ROLE_POWER_USER_DESCRIPTION);
        titleMap.put(_getLocale(), PortletPropsValues.ROLE_POWER_USER_NAME);
      } else if (name.equals(RoleConstants.USER)) {
        descriptionMap.put(_getLocale(), PortletPropsValues.ROLE_USER_DESCRIPTION);
        titleMap.put(_getLocale(), PortletPropsValues.ROLE_USER_NAME);
      }

      RoleLocalServiceUtil.updateRole(
          role.getRoleId(), name, titleMap, descriptionMap, RoleConstants.TYPE_REGULAR_LABEL);
    }

    // Organization roles

    for (String name : PortalUtil.getSystemOrganizationRoles()) {
      Role role = RoleLocalServiceUtil.getRole(companyId, name);

      Map<Locale, String> descriptionMap = role.getDescriptionMap();
      Map<Locale, String> titleMap = role.getTitleMap();

      if (name.equals(RoleConstants.ORGANIZATION_ADMINISTRATOR)) {
        descriptionMap.put(
            _getLocale(), PortletPropsValues.ROLE_ORGANIZATION_ADMINISTRATOR_DESCRIPTION);
        titleMap.put(_getLocale(), PortletPropsValues.ROLE_ORGANIZATION_ADMINISTRATOR_NAME);
      } else if (name.equals(RoleConstants.ORGANIZATION_OWNER)) {
        descriptionMap.put(_getLocale(), PortletPropsValues.ROLE_ORGANIZATION_OWNER_DESCRIPTION);
        titleMap.put(_getLocale(), PortletPropsValues.ROLE_ORGANIZATION_OWNER_NAME);
      } else if (name.equals(RoleConstants.ORGANIZATION_USER)) {
        descriptionMap.put(_getLocale(), PortletPropsValues.ROLE_ORGANIZATION_USER_DESCRIPTION);
        titleMap.put(_getLocale(), PortletPropsValues.ROLE_ORGANIZATION_USER_NAME);
      }

      RoleLocalServiceUtil.updateRole(
          role.getRoleId(), name, titleMap, descriptionMap, RoleConstants.TYPE_ORGANIZATION_LABEL);
    }

    // Site roles

    for (String name : PortalUtil.getSystemSiteRoles()) {
      Role role = RoleLocalServiceUtil.getRole(companyId, name);

      Map<Locale, String> descriptionMap = role.getDescriptionMap();
      Map<Locale, String> titleMap = role.getTitleMap();

      if (name.equals(RoleConstants.SITE_ADMINISTRATOR)) {
        descriptionMap.put(_getLocale(), PortletPropsValues.ROLE_SITE_ADMINISTRATOR_DESCRIPTION);
        titleMap.put(_getLocale(), PortletPropsValues.ROLE_SITE_ADMINISTRATOR_NAME);
      } else if (name.equals(RoleConstants.SITE_MEMBER)) {
        descriptionMap.put(_getLocale(), PortletPropsValues.ROLE_SITE_MEMBER_DESCRIPTION);
        titleMap.put(_getLocale(), PortletPropsValues.ROLE_SITE_MEMBER_NAME);
      } else if (name.equals(RoleConstants.SITE_OWNER)) {
        descriptionMap.put(_getLocale(), PortletPropsValues.ROLE_SITE_OWNER_DESCRIPTION);
        titleMap.put(_getLocale(), PortletPropsValues.ROLE_SITE_OWNER_NAME);
      }

      RoleLocalServiceUtil.updateRole(
          role.getRoleId(), name, titleMap, descriptionMap, RoleConstants.TYPE_SITE_LABEL);
    }
  }