protected void checkSystemRole(
      long companyId, String name, Map<Locale, String> descriptionMap, int type)
      throws PortalException, SystemException {

    String companyIdHexString = StringUtil.toHexString(companyId);

    String key = companyIdHexString.concat(name);

    Role role = _systemRolesMap.get(key);

    try {
      if (role == null) {
        role = rolePersistence.findByC_N(companyId, name);
      }

      if (!descriptionMap.equals(role.getDescriptionMap())) {
        role.setDescriptionMap(descriptionMap);

        roleLocalService.updateRole(role, false);
      }
    } catch (NoSuchRoleException nsre) {
      role = roleLocalService.addRole(0, companyId, name, null, descriptionMap, type);

      if (name.equals(RoleConstants.USER)) {
        initPersonalControlPanelPortletsPermissions(role);
      }
    }

    _systemRolesMap.put(key, role);
  }
  @Override
  protected void doImportStagedModel(PortletDataContext portletDataContext, Role role)
      throws Exception {

    long userId = portletDataContext.getUserId(role.getUserUuid());

    ServiceContext serviceContext = portletDataContext.createServiceContext(role);

    Role existingRole =
        RoleLocalServiceUtil.fetchRoleByUuidAndCompanyId(
            role.getUuid(), portletDataContext.getCompanyId());

    if (existingRole == null) {
      existingRole =
          RoleLocalServiceUtil.fetchRole(portletDataContext.getCompanyId(), role.getName());
    }

    Role importedRole = null;

    if (existingRole == null) {
      serviceContext.setUuid(role.getUuid());

      importedRole =
          RoleLocalServiceUtil.addRole(
              userId,
              null,
              0,
              role.getName(),
              role.getTitleMap(),
              role.getDescriptionMap(),
              role.getType(),
              role.getSubtype(),
              serviceContext);
    } else {
      importedRole =
          RoleLocalServiceUtil.updateRole(
              existingRole.getRoleId(),
              role.getName(),
              role.getTitleMap(),
              role.getDescriptionMap(),
              role.getSubtype(),
              serviceContext);

      deleteRolePermissions(portletDataContext, importedRole);
    }

    String permissionsPath = ExportImportPathUtil.getModelPath(role, "permissions.xml");

    List<Permission> permissions =
        (List<Permission>) portletDataContext.getZipEntryAsObject(permissionsPath);

    for (Permission permission : permissions) {
      if (ResourceBlockLocalServiceUtil.isSupported(permission.getName())) {

        importResourceBlock(portletDataContext, importedRole, permission);
      } else {
        importResourcePermissions(portletDataContext, importedRole, permission);
      }
    }

    portletDataContext.importClassedModel(role, importedRole);
  }
Пример #3
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);
    }
  }
Пример #4
0
  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);
    }
  }