コード例 #1
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);
    }
  }
コード例 #2
0
  @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
  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);
    }
  }