public LayoutSet updateVirtualHost(long groupId, boolean privateLayout, String virtualHost)
      throws PortalException, SystemException {

    GroupPermissionUtil.check(getPermissionChecker(), groupId, ActionKeys.UPDATE);

    return layoutSetLocalService.updateVirtualHost(groupId, privateLayout, virtualHost);
  }
  /**
   * Updates the group's type settings.
   *
   * @param groupId the primary key of the group
   * @param typeSettings the group's new type settings (optionally <code>null</code>)
   * @return the group
   * @throws PortalException if a portal exception occurred
   */
  @Override
  public Group updateGroup(long groupId, String typeSettings) throws PortalException {

    Group group = groupPersistence.findByPrimaryKey(groupId);

    GroupPermissionUtil.check(getPermissionChecker(), group, ActionKeys.UPDATE);

    if (group.isSite()) {
      Group oldGroup = group;

      UnicodeProperties oldTypeSettingsProperties = oldGroup.getTypeSettingsProperties();

      group = groupLocalService.updateGroup(groupId, typeSettings);

      RatingsDataTransformerUtil.transformGroupRatingsData(
          groupId, oldTypeSettingsProperties, group.getTypeSettingsProperties());

      SiteMembershipPolicyUtil.verifyPolicy(
          group, oldGroup, null, null, null, oldTypeSettingsProperties);

      return group;
    } else {
      return groupLocalService.updateGroup(groupId, typeSettings);
    }
  }
  /**
   * Updates the group's friendly URL.
   *
   * @param groupId the primary key of the group
   * @param friendlyURL the group's new friendlyURL (optionally <code>null</code>)
   * @return the group
   * @throws PortalException if a portal exception occurred
   */
  @Override
  public Group updateFriendlyURL(long groupId, String friendlyURL) throws PortalException {

    GroupPermissionUtil.check(getPermissionChecker(), groupId, ActionKeys.UPDATE);

    return groupLocalService.updateFriendlyURL(groupId, friendlyURL);
  }
  public void updateLogo(long groupId, boolean privateLayout, boolean logo, InputStream inputStream)
      throws PortalException, SystemException {

    GroupPermissionUtil.check(getPermissionChecker(), groupId, ActionKeys.UPDATE);

    layoutSetLocalService.updateLogo(groupId, privateLayout, logo, inputStream);
  }
  /**
   * Returns the group with the primary key.
   *
   * @param groupId the primary key of the group
   * @return the group with the primary key
   * @throws PortalException if a portal exception occurred
   */
  @Override
  public Group getGroup(long groupId) throws PortalException {
    Group group = groupLocalService.getGroup(groupId);

    GroupPermissionUtil.check(getPermissionChecker(), group, ActionKeys.VIEW);

    return group;
  }
  @Override
  public void enableStaging(long groupId) throws PortalException {
    Group group = groupLocalService.getGroup(groupId);

    GroupPermissionUtil.check(getPermissionChecker(), group, ActionKeys.UPDATE);

    groupLocalService.enableStaging(groupId);
  }
  /**
   * Returns the group directly associated with the user.
   *
   * @param companyId the primary key of the company
   * @param userId the primary key of the user
   * @return the group directly associated with the user
   * @throws PortalException if a portal exception occurred
   */
  @Override
  public Group getUserGroup(long companyId, long userId) throws PortalException {

    Group group = groupLocalService.getUserGroup(companyId, userId);

    GroupPermissionUtil.check(getPermissionChecker(), group, ActionKeys.VIEW);

    return group;
  }
  /**
   * Returns the group's display URL.
   *
   * @param groupId the primary key of the group
   * @param privateLayout whether the layout set is private to the group
   * @param secureConnection whether the generated URL uses a secure connection
   * @return the group's display URL
   * @throws PortalException if a group with the primary key could not be found or if a portal
   *     exception occurred
   */
  @Override
  public String getGroupDisplayURL(long groupId, boolean privateLayout, boolean secureConnection)
      throws PortalException {

    Group group = groupLocalService.getGroup(groupId);

    GroupPermissionUtil.check(getPermissionChecker(), group, ActionKeys.VIEW);

    if (!privateLayout && (group.getPublicLayoutsPageCount() > 0)) {
      return PortalUtil.getLayoutSetDisplayURL(group.getPublicLayoutSet(), secureConnection);
    } else if (privateLayout && (group.getPrivateLayoutsPageCount() > 0)) {
      return PortalUtil.getLayoutSetDisplayURL(group.getPrivateLayoutSet(), secureConnection);
    }

    GroupPermissionUtil.check(getPermissionChecker(), group, ActionKeys.UPDATE);

    return PortalUtil.getControlPanelFullURL(groupId, PortletKeys.LAYOUTS_ADMIN, null);
  }
  /**
   * Returns <code>true</code> if the user is associated with the group, including the user's
   * inherited organizations and user groups. System and staged groups are not included.
   *
   * @param userId the primary key of the user
   * @param groupId the primary key of the group
   * @return <code>true</code> if the user is associated with the group; <code>false</code>
   *     otherwise
   * @throws PortalException if a portal exception occurred
   */
  @Override
  public boolean hasUserGroup(long userId, long groupId) throws PortalException {

    try {
      UserPermissionUtil.check(getPermissionChecker(), userId, ActionKeys.VIEW);
    } catch (PrincipalException pe) {
      GroupPermissionUtil.check(getPermissionChecker(), groupId, ActionKeys.VIEW_MEMBERS);
    }

    return groupLocalService.hasUserGroup(userId, groupId);
  }
  public LayoutSet updateLookAndFeel(
      long groupId,
      boolean privateLayout,
      String themeId,
      String colorSchemeId,
      String css,
      boolean wapTheme)
      throws PortalException, SystemException {

    GroupPermissionUtil.check(getPermissionChecker(), groupId, ActionKeys.UPDATE);

    pluginSettingLocalService.checkPermission(getUserId(), themeId, Plugin.TYPE_THEME);

    return layoutSetLocalService.updateLookAndFeel(
        groupId, privateLayout, themeId, colorSchemeId, css, wapTheme);
  }
  public void deleteArchivedPreferences(long portletItemId)
      throws PortalException, SystemException {

    PortletItem portletItem = portletItemLocalService.getPortletItem(portletItemId);

    GroupPermissionUtil.check(
        getPermissionChecker(), portletItem.getGroupId(), ActionKeys.MANAGE_ARCHIVED_SETUPS);

    long ownerId = portletItemId;
    int ownerType = PortletKeys.PREFS_OWNER_TYPE_ARCHIVED;
    long plid = 0;
    String portletId = portletItem.getPortletId();

    portletPreferencesLocalService.deletePortletPreferences(ownerId, ownerType, plid, portletId);

    portletItemLocalService.deletePortletItem(portletItemId);
  }
  @Override
  public void updateStagedPortlets(long groupId, Map<String, String> stagedPortletIds)
      throws PortalException {

    Group group = groupPersistence.findByPrimaryKey(groupId);

    GroupPermissionUtil.check(getPermissionChecker(), group, ActionKeys.UPDATE);

    UnicodeProperties typeSettingsProperties = group.getTypeSettingsProperties();

    for (String stagedPortletId : stagedPortletIds.keySet()) {
      typeSettingsProperties.setProperty(
          StagingUtil.getStagedPortletId(stagedPortletId), stagedPortletIds.get(stagedPortletId));
    }

    groupLocalService.updateGroup(group);
  }
  @Override
  public Group addGroup(
      long parentGroupId,
      long liveGroupId,
      Map<Locale, String> nameMap,
      Map<Locale, String> descriptionMap,
      int type,
      boolean manualMembership,
      int membershipRestriction,
      String friendlyURL,
      boolean site,
      boolean inheritContent,
      boolean active,
      ServiceContext serviceContext)
      throws PortalException {

    if (parentGroupId == GroupConstants.DEFAULT_PARENT_GROUP_ID) {
      PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_COMMUNITY);
    } else {
      GroupPermissionUtil.check(getPermissionChecker(), parentGroupId, ActionKeys.ADD_COMMUNITY);
    }

    Group group =
        groupLocalService.addGroup(
            getUserId(),
            parentGroupId,
            null,
            0,
            liveGroupId,
            nameMap,
            descriptionMap,
            type,
            manualMembership,
            membershipRestriction,
            friendlyURL,
            site,
            inheritContent,
            active,
            serviceContext);

    if (site) {
      SiteMembershipPolicyUtil.verifyPolicy(group);
    }

    return group;
  }
  public void restoreArchivedPreferences(
      long groupId, String name, String portletId, javax.portlet.PortletPreferences preferences)
      throws PortalException, SystemException {

    GroupPermissionUtil.check(getPermissionChecker(), groupId, ActionKeys.MANAGE_ARCHIVED_SETUPS);

    PortletItem portletItem =
        portletItemLocalService.getPortletItem(
            groupId, name, portletId, PortletPreferences.class.getName());

    long ownerId = portletItem.getPortletItemId();
    int ownerType = PortletKeys.PREFS_OWNER_TYPE_ARCHIVED;
    long plid = 0;

    javax.portlet.PortletPreferences archivedPrefs =
        portletPreferencesLocalService.getPreferences(
            portletItem.getCompanyId(), ownerId, ownerType, plid, portletId);

    copyPreferences(archivedPrefs, preferences);
  }
  @Override
  public Group updateGroup(
      long groupId,
      long parentGroupId,
      Map<Locale, String> nameMap,
      Map<Locale, String> descriptionMap,
      int type,
      boolean manualMembership,
      int membershipRestriction,
      String friendlyURL,
      boolean inheritContent,
      boolean active,
      ServiceContext serviceContext)
      throws PortalException {

    Group group = groupPersistence.findByPrimaryKey(groupId);

    GroupPermissionUtil.check(getPermissionChecker(), group, ActionKeys.UPDATE);

    if (group.getParentGroupId() != parentGroupId) {
      if (parentGroupId == GroupConstants.DEFAULT_PARENT_GROUP_ID) {
        PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_COMMUNITY);
      } else {
        GroupPermissionUtil.check(getPermissionChecker(), parentGroupId, ActionKeys.ADD_COMMUNITY);
      }
    }

    if (group.isSite()) {
      Group oldGroup = group;

      List<AssetCategory> oldAssetCategories =
          assetCategoryLocalService.getCategories(Group.class.getName(), groupId);

      List<AssetTag> oldAssetTags = assetTagLocalService.getTags(Group.class.getName(), groupId);

      ExpandoBridge oldExpandoBridge = oldGroup.getExpandoBridge();

      Map<String, Serializable> oldExpandoAttributes = oldExpandoBridge.getAttributes();

      group =
          groupLocalService.updateGroup(
              groupId,
              parentGroupId,
              nameMap,
              descriptionMap,
              type,
              manualMembership,
              membershipRestriction,
              friendlyURL,
              inheritContent,
              active,
              serviceContext);

      SiteMembershipPolicyUtil.verifyPolicy(
          group, oldGroup, oldAssetCategories, oldAssetTags, oldExpandoAttributes, null);

      return group;
    } else {
      return groupLocalService.updateGroup(
          groupId,
          parentGroupId,
          nameMap,
          descriptionMap,
          type,
          manualMembership,
          membershipRestriction,
          friendlyURL,
          inheritContent,
          active,
          serviceContext);
    }
  }
  /**
   * Deletes the group.
   *
   * <p>The group is unstaged and its assets and resources including layouts, membership requests,
   * subscriptions, teams, blogs, bookmarks, calendar events, image gallery, journals, message
   * boards, polls, shopping related entities, and wikis are also deleted.
   *
   * @param groupId the primary key of the group
   * @throws PortalException if a portal exception occurred
   */
  @Override
  public void deleteGroup(long groupId) throws PortalException {
    GroupPermissionUtil.check(getPermissionChecker(), groupId, ActionKeys.DELETE);

    groupLocalService.deleteGroup(groupId);
  }