protected void updateActive(ActionRequest actionRequest, String cmd) throws Exception {

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

    long groupId = ParamUtil.getLong(actionRequest, "groupId");

    if ((groupId == themeDisplay.getDoAsGroupId())
        || (groupId == themeDisplay.getScopeGroupId())
        || (groupId == getRefererGroupId(themeDisplay))) {

      throw new RequiredGroupException(
          String.valueOf(groupId), RequiredGroupException.CURRENT_GROUP);
    }

    Group group = GroupServiceUtil.getGroup(groupId);

    boolean active = false;

    if (cmd.equals(Constants.RESTORE)) {
      active = true;
    }

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(Group.class.getName(), actionRequest);

    GroupServiceUtil.updateGroup(
        groupId,
        group.getParentGroupId(),
        group.getName(),
        group.getDescription(),
        group.getType(),
        group.getFriendlyURL(),
        active,
        serviceContext);
  }
  public void editRoleAssignments(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    long roleId = ParamUtil.getLong(actionRequest, "roleId");
    Role role = RoleLocalServiceUtil.getRole(roleId);

    if (role.getName().equals(RoleConstants.OWNER)) {
      throw new RoleAssignmentException(role.getName());
    }

    long[] addUserIds = StringUtil.split(ParamUtil.getString(actionRequest, "addUserIds"), 0L);
    long[] removeUserIds =
        StringUtil.split(ParamUtil.getString(actionRequest, "removeUserIds"), 0L);

    if (!ArrayUtil.isEmpty(addUserIds) || !ArrayUtil.isEmpty(removeUserIds)) {

      UserServiceUtil.addRoleUsers(roleId, addUserIds);
      UserServiceUtil.unsetRoleUsers(roleId, removeUserIds);
    }

    long[] addGroupIds = StringUtil.split(ParamUtil.getString(actionRequest, "addGroupIds"), 0L);
    long[] removeGroupIds =
        StringUtil.split(ParamUtil.getString(actionRequest, "removeGroupIds"), 0L);

    if (!ArrayUtil.isEmpty(addGroupIds) || !ArrayUtil.isEmpty(removeGroupIds)) {

      GroupServiceUtil.addRoleGroups(roleId, addGroupIds);
      GroupServiceUtil.unsetRoleGroups(roleId, removeGroupIds);
    }
  }
  public List<Group> getMySites(String[] classNames, boolean includeControlPanel, int max)
      throws PortalException, SystemException {

    ThreadLocalCache<List<Group>> threadLocalCache =
        ThreadLocalCacheManager.getThreadLocalCache(Lifecycle.REQUEST, UserImpl.class.getName());

    String key = StringUtil.toHexString(max);

    if ((classNames != null) && (classNames.length > 0)) {
      key = StringUtil.merge(classNames).concat(StringPool.POUND).concat(key);
    }

    key = key.concat(StringPool.POUND).concat(String.valueOf(includeControlPanel));

    List<Group> myPlaces = threadLocalCache.get(key);

    if (myPlaces != null) {
      return myPlaces;
    }

    myPlaces = GroupServiceUtil.getUserPlaces(getUserId(), classNames, includeControlPanel, max);

    threadLocalCache.put(key, myPlaces);

    return myPlaces;
  }
  public void updateConfiguration(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException, PortletException {

    try {
      ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

      long scopeGroupId = serviceContext.getScopeGroupId();

      Group scopeGroup = GroupLocalServiceUtil.getGroup(scopeGroupId);

      if (scopeGroup.isStagingGroup()) {
        scopeGroup = scopeGroup.getLiveGroup();
      }

      UnicodeProperties typeSettingsProperties = scopeGroup.getTypeSettingsProperties();

      UnicodeProperties properties = PropertiesParamUtil.getProperties(actionRequest, "settings--");

      typeSettingsProperties.putAll(properties);

      GroupServiceUtil.updateGroup(scopeGroup.getGroupId(), scopeGroup.getTypeSettings());
    } catch (Exception e) {
      SessionErrors.add(actionRequest, e.getClass().getName());
    }
  }
  protected int[] getRoleTypes(long companyId, Group group, String modelResource) {

    int[] types = RoleConstants.TYPES_REGULAR_AND_SITE;

    if (isPortalModelResource(modelResource)) {
      if (modelResource.equals(Organization.class.getName())
          || modelResource.equals(User.class.getName())) {

        types = RoleConstants.TYPES_ORGANIZATION_AND_REGULAR;
      } else {
        types = RoleConstants.TYPES_REGULAR;
      }
    } else {
      if (group != null) {
        if (group.isLayout()) {
          try {
            group = GroupServiceUtil.getGroup(group.getParentGroupId());
          } catch (Exception e) {
          }
        }

        if (group.isOrganization()) {
          types = RoleConstants.TYPES_ORGANIZATION_AND_REGULAR_AND_SITE;
        } else if (group.isUser()) {
          types = RoleConstants.TYPES_REGULAR;
        }
      }
    }

    return types;
  }
  public static void addRoleGroups(long roleId, long[] groupIds) throws RemoteException {
    try {
      GroupServiceUtil.addRoleGroups(roleId, groupIds);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  public static void deleteGroup(long groupId) throws RemoteException {
    try {
      GroupServiceUtil.deleteGroup(groupId);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
Example #8
0
  protected void deleteGroup(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long groupId = ParamUtil.getLong(actionRequest, "groupId");

    GroupServiceUtil.deleteGroup(groupId);

    LiveUsers.deleteGroup(themeDisplay.getCompanyId(), groupId);
  }
  @Test
  public void testVerifyWhenUpdatingGroupTypeSettings() throws Exception {
    Group group = MembershipPolicyTestUtil.addGroup();

    UnicodeProperties unicodeProperties = RandomTestUtil.randomUnicodeProperties(10, 2, 2);

    GroupServiceUtil.updateGroup(group.getGroupId(), unicodeProperties.toString());

    Assert.assertTrue(isVerify());
  }
  public static com.liferay.portal.model.GroupSoap getGroup(long groupId) throws RemoteException {
    try {
      com.liferay.portal.model.Group returnValue = GroupServiceUtil.getGroup(groupId);

      return com.liferay.portal.model.GroupSoap.toSoapModel(returnValue);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  public static boolean hasUserGroup(long userId, long groupId) throws RemoteException {
    try {
      boolean returnValue = GroupServiceUtil.hasUserGroup(userId, groupId);

      return returnValue;
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  /**
   * Returns the guest or current user's layout set group, organization groups, inherited
   * organization groups, and site groups.
   *
   * @return the user's layout set group, organization groups, and inherited organization groups,
   *     and site groups
   * @throws PortalException if a portal exception occurred
   * @throws SystemException if a system exception occurred
   */
  public static com.liferay.portal.model.GroupSoap[] getUserSites() throws RemoteException {
    try {
      java.util.List<com.liferay.portal.model.Group> returnValue = GroupServiceUtil.getUserSites();

      return com.liferay.portal.model.GroupSoap.toSoapModels(returnValue);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  public static com.liferay.portal.model.GroupSoap getGroup(long companyId, java.lang.String name)
      throws RemoteException {
    try {
      com.liferay.portal.model.Group returnValue = GroupServiceUtil.getGroup(companyId, name);

      return com.liferay.portal.model.GroupSoap.toSoapModel(returnValue);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  public static com.liferay.portal.model.GroupSoap updateGroup(
      long groupId, java.lang.String typeSettings) throws RemoteException {
    try {
      com.liferay.portal.model.Group returnValue =
          GroupServiceUtil.updateGroup(groupId, typeSettings);

      return com.liferay.portal.model.GroupSoap.toSoapModel(returnValue);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  @Test
  public void testVerifyWhenUpdatingGroup() throws Exception {
    Group group = MembershipPolicyTestUtil.addGroup();

    GroupServiceUtil.updateGroup(
        group.getGroupId(), group.getParentGroupId(),
        RandomTestUtil.randomString(), group.getDescription(),
        group.getType(), group.isManualMembership(),
        group.getMembershipRestriction(), group.getFriendlyURL(),
        group.isActive(), ServiceContextTestUtil.getServiceContext());

    Assert.assertTrue(isVerify());
  }
  public static com.liferay.portal.model.GroupSoap[] getUserOrganizationsGroups(
      long userId, int start, int end) throws RemoteException {
    try {
      java.util.List<com.liferay.portal.model.Group> returnValue =
          GroupServiceUtil.getUserOrganizationsGroups(userId, start, end);

      return com.liferay.portal.model.GroupSoap.toSoapModels(returnValue);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  public static com.liferay.portal.model.GroupSoap[] getUserPlaces(
      long userId, java.lang.String[] classNames, int max) throws RemoteException {
    try {
      java.util.List<com.liferay.portal.model.Group> returnValue =
          GroupServiceUtil.getUserPlaces(userId, classNames, max);

      return com.liferay.portal.model.GroupSoap.toSoapModels(returnValue);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  public static com.liferay.portal.model.GroupSoap[] getManageableSites(
      java.util.Collection<com.liferay.portal.model.Portlet> portlets, int max)
      throws RemoteException {
    try {
      java.util.List<com.liferay.portal.model.Group> returnValue =
          GroupServiceUtil.getManageableSites(portlets, max);

      return com.liferay.portal.model.GroupSoap.toSoapModels(returnValue);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  public static com.liferay.portal.model.GroupSoap[] getOrganizationsGroups(
      com.liferay.portal.model.OrganizationSoap[] organizations) throws RemoteException {
    try {
      java.util.List<com.liferay.portal.model.Group> returnValue =
          GroupServiceUtil.getOrganizationsGroups(
              com.liferay.portal.model.impl.OrganizationModelImpl.toModels(organizations));

      return com.liferay.portal.model.GroupSoap.toSoapModels(returnValue);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  public static int searchCount(
      long companyId,
      java.lang.String name,
      java.lang.String description,
      java.lang.String[] params)
      throws RemoteException {
    try {
      int returnValue = GroupServiceUtil.searchCount(companyId, name, description, params);

      return returnValue;
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  public static com.liferay.portal.model.GroupSoap[] search(
      long companyId,
      java.lang.String name,
      java.lang.String description,
      java.lang.String[] params,
      int start,
      int end)
      throws RemoteException {
    try {
      java.util.List<com.liferay.portal.model.Group> returnValue =
          GroupServiceUtil.search(companyId, name, description, params, start, end);

      return com.liferay.portal.model.GroupSoap.toSoapModels(returnValue);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  protected void deleteGroups(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long[] deleteGroupIds = null;

    long groupId = ParamUtil.getLong(actionRequest, "groupId");

    if (groupId > 0) {
      deleteGroupIds = new long[] {groupId};
    } else {
      deleteGroupIds = StringUtil.split(ParamUtil.getString(actionRequest, "deleteGroupIds"), 0L);
    }

    for (long deleteGroupId : deleteGroupIds) {
      GroupServiceUtil.deleteGroup(deleteGroupId);

      LiveUsers.deleteGroup(themeDisplay.getCompanyId(), deleteGroupId);
    }
  }
Example #23
0
  public static List<Group> getFavoriteSitesGroups(long userId, String name, int start, int end)
      throws Exception {

    List<Object[]> favoriteSites =
        FavoriteSiteLocalServiceUtil.getFavoriteSites(userId, name, start, end);

    List<Group> groups = new ArrayList<Group>(favoriteSites.size());

    for (Object[] favoriteSite : favoriteSites) {
      long curUserId = (Long) favoriteSite[0];
      long groupId = (Long) favoriteSite[1];

      try {
        groups.add(GroupServiceUtil.getGroup(groupId));
      } catch (Exception e) {
        FavoriteSiteLocalServiceUtil.deleteFavoriteSite(curUserId, groupId);
      }
    }

    return groups;
  }
  public static com.liferay.portal.model.GroupSoap addGroup(
      java.lang.String name,
      java.lang.String description,
      int type,
      java.lang.String friendlyURL,
      boolean site,
      boolean active,
      com.liferay.portal.service.ServiceContext serviceContext)
      throws RemoteException {
    try {
      com.liferay.portal.model.Group returnValue =
          GroupServiceUtil.addGroup(
              name, description, type, friendlyURL, site, active, serviceContext);

      return com.liferay.portal.model.GroupSoap.toSoapModel(returnValue);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  protected String getResults(HttpServletRequest request) throws Exception {

    String xml = StringUtil.read(request.getInputStream());

    String documentName = null;

    int beginPos = xml.lastIndexOf("<document>");
    int endPos = xml.lastIndexOf("</document>");

    if (beginPos != -1) {
      documentName = xml.substring(beginPos + 10, endPos);

      documentName = HttpUtil.decodeURL(documentName);
    }

    String path = documentName;

    int pos = documentName.lastIndexOf("sharepoint/");

    if (pos != -1) {
      path = path.substring(pos + 11);
    }

    Group group = GroupServiceUtil.getGroup(SharepointUtil.getGroupId(path));

    boolean minimal = false;

    beginPos = xml.lastIndexOf("<minimal>");
    endPos = xml.lastIndexOf("</minimal>");

    if (beginPos != -1) {
      minimal = GetterUtil.getBoolean(xml.substring(beginPos + 9, endPos));
    }

    Document doc = SAXReaderUtil.createDocument();

    Element root = doc.addElement("Results");

    String url = "http://" + request.getLocalAddr() + ":" + request.getServerPort() + "/sharepoint";

    root.addElement("SubscribeUrl").setText(url);
    root.addElement("MtgInstance");
    root.addElement("SettingUrl").setText(url);
    root.addElement("PermsUrl").setText(url);
    root.addElement("UserInfoUrl").setText(url);

    Element rolesEl = root.addElement("Roles");

    List<Role> roles = RoleLocalServiceUtil.getRoles(PortalUtil.getCompanyId(request));

    for (Role role : roles) {
      ResponseElement responseElement = new RoleResponseElement(role);

      responseElement.addElement(rolesEl);
    }

    if (!minimal) {
      Element schemaEl = root.addElement("Schema");

      schemaEl.addAttribute("Name", "Documents");
      schemaEl.addAttribute("Url", group.getName());

      Element fieldEl = schemaEl.addElement("Field");

      fieldEl.addAttribute("Name", "FileLeafRef");
      fieldEl.addAttribute("Required", "true");
      fieldEl.addAttribute("Type", "Invalid");

      fieldEl.addElement("Choices");

      fieldEl = schemaEl.addElement("Field");

      fieldEl.addAttribute("Name", "_SourceUrl");
      fieldEl.addAttribute("Required", "false");
      fieldEl.addAttribute("Type", "Text");

      fieldEl.addElement("Choices");

      fieldEl = schemaEl.addElement("Field");

      fieldEl.addAttribute("Name", "_SharedFileIndex");
      fieldEl.addAttribute("Required", "false");
      fieldEl.addAttribute("Type", "Text");

      fieldEl.addElement("Choices");

      fieldEl = schemaEl.addElement("Field");

      fieldEl.addAttribute("Name", "Order");
      fieldEl.addAttribute("Required", "false");
      fieldEl.addAttribute("Type", "Number");

      fieldEl.addElement("Choices");

      fieldEl = schemaEl.addElement("Field");

      fieldEl.addAttribute("Name", "Title");
      fieldEl.addAttribute("Required", "false");
      fieldEl.addAttribute("Type", "Text");

      fieldEl.addElement("Choices");

      Element listInfoEl = root.addElement("ListInfo");

      listInfoEl.addAttribute("Name", "Links");

      listInfoEl.addElement("Moderated").setText(String.valueOf(false));

      Element listPermissionsEl = listInfoEl.addElement("ListPermissions");

      listPermissionsEl.addElement("DeleteListItems");
      listPermissionsEl.addElement("EditListItems");
      listPermissionsEl.addElement("InsertListItems");
      listPermissionsEl.addElement("ManageRoles");
      listPermissionsEl.addElement("ManageWeb");
    }

    Element permissionsEl = root.addElement("Permissions");

    if (!minimal) {
      permissionsEl.addElement("DeleteListItems");
      permissionsEl.addElement("EditListItems");
      permissionsEl.addElement("InsertListItems");
      permissionsEl.addElement("ManageRoles");
      permissionsEl.addElement("ManageWeb");
    }

    root.addElement("HasUniquePerm").setText(String.valueOf(true));
    root.addElement("WorkspaceType").setText("DWS");
    root.addElement("IsADMode").setText(String.valueOf(false));
    root.addElement("DocUrl").setText(documentName);
    root.addElement("Minimal").setText(String.valueOf(true));

    Element resultsEl = root.addElement("Results");

    resultsEl.addElement("Title").setText(group.getName());
    resultsEl.addElement("LastUpdate");

    User user = (User) request.getSession().getAttribute(WebKeys.USER);

    ResponseElement responseElement = new MemberResponseElement(user, false);

    responseElement.addElement(resultsEl);

    Element membersEl = resultsEl.addElement("Members");

    List<User> users = UserLocalServiceUtil.getGroupUsers(group.getGroupId());

    for (User member : users) {
      responseElement = new MemberResponseElement(member, true);

      responseElement.addElement(membersEl);
    }

    if (!minimal) {
      Element assigneesEl = resultsEl.addElement("Assignees");

      for (User member : users) {
        responseElement = new MemberResponseElement(member, true);

        responseElement.addElement(assigneesEl);
      }

      Element listEl = resultsEl.addElement("List");

      listEl.addAttribute("Name", "Documents");

      listEl.addElement("ID");

      String parentFolderPath = path;

      pos = parentFolderPath.lastIndexOf("/");

      if (pos != -1) {
        parentFolderPath = parentFolderPath.substring(0, pos);
      }

      SharepointStorage storage = SharepointUtil.getStorage(parentFolderPath);

      SharepointRequest sharepointRequest = new SharepointRequest(parentFolderPath);

      storage.addDocumentElements(sharepointRequest, listEl);
    }

    return doc.asXML();
  }
  protected Object[] updateGroup(ActionRequest actionRequest) throws Exception {

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

    long userId = PortalUtil.getUserId(actionRequest);

    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");

    long parentGroupId =
        ParamUtil.getLong(
            actionRequest,
            "parentGroupSearchContainerPrimaryKeys",
            GroupConstants.DEFAULT_PARENT_GROUP_ID);
    String name = null;
    String description = null;
    int type = 0;
    String friendlyURL = null;
    boolean active = false;

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(Group.class.getName(), actionRequest);

    Group liveGroup = null;
    String oldFriendlyURL = null;
    String oldStagingFriendlyURL = null;

    if (liveGroupId <= 0) {

      // Add group

      name = ParamUtil.getString(actionRequest, "name");
      description = ParamUtil.getString(actionRequest, "description");
      type = ParamUtil.getInteger(actionRequest, "type");
      friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL");
      active = ParamUtil.getBoolean(actionRequest, "active");

      liveGroup =
          GroupServiceUtil.addGroup(
              parentGroupId,
              GroupConstants.DEFAULT_LIVE_GROUP_ID,
              name,
              description,
              type,
              friendlyURL,
              true,
              active,
              serviceContext);

      LiveUsers.joinGroup(themeDisplay.getCompanyId(), liveGroup.getGroupId(), userId);
    } else {

      // Update group

      liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);

      oldFriendlyURL = liveGroup.getFriendlyURL();

      name = ParamUtil.getString(actionRequest, "name", liveGroup.getName());
      description = ParamUtil.getString(actionRequest, "description", liveGroup.getDescription());
      type = ParamUtil.getInteger(actionRequest, "type", liveGroup.getType());
      friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL", liveGroup.getFriendlyURL());
      active = ParamUtil.getBoolean(actionRequest, "active", liveGroup.getActive());

      liveGroup =
          GroupServiceUtil.updateGroup(
              liveGroupId,
              parentGroupId,
              name,
              description,
              type,
              friendlyURL,
              active,
              serviceContext);

      if (type == GroupConstants.TYPE_SITE_OPEN) {
        List<MembershipRequest> membershipRequests =
            MembershipRequestLocalServiceUtil.search(
                liveGroupId,
                MembershipRequestConstants.STATUS_PENDING,
                QueryUtil.ALL_POS,
                QueryUtil.ALL_POS);

        for (MembershipRequest membershipRequest : membershipRequests) {
          MembershipRequestServiceUtil.updateStatus(
              membershipRequest.getMembershipRequestId(),
              themeDisplay.translate("your-membership-has-been-approved"),
              MembershipRequestConstants.STATUS_APPROVED,
              serviceContext);

          LiveUsers.joinGroup(
              themeDisplay.getCompanyId(),
              membershipRequest.getGroupId(),
              new long[] {membershipRequest.getUserId()});
        }
      }
    }

    // Settings

    UnicodeProperties typeSettingsProperties = liveGroup.getTypeSettingsProperties();

    String customJspServletContextName =
        ParamUtil.getString(
            actionRequest,
            "customJspServletContextName",
            typeSettingsProperties.getProperty("customJspServletContextName"));

    typeSettingsProperties.setProperty("customJspServletContextName", customJspServletContextName);

    typeSettingsProperties.setProperty(
        "defaultSiteRoleIds",
        ListUtil.toString(getRoles(actionRequest), Role.ROLE_ID_ACCESSOR, StringPool.COMMA));
    typeSettingsProperties.setProperty(
        "defaultTeamIds",
        ListUtil.toString(getTeams(actionRequest), Team.TEAM_ID_ACCESSOR, StringPool.COMMA));

    String[] analyticsTypes =
        PrefsPropsUtil.getStringArray(
            themeDisplay.getCompanyId(), PropsKeys.ADMIN_ANALYTICS_TYPES, StringPool.NEW_LINE);

    for (String analyticsType : analyticsTypes) {
      if (analyticsType.equalsIgnoreCase("google")) {
        String googleAnalyticsId =
            ParamUtil.getString(
                actionRequest,
                "googleAnalyticsId",
                typeSettingsProperties.getProperty("googleAnalyticsId"));

        typeSettingsProperties.setProperty("googleAnalyticsId", googleAnalyticsId);
      } else {
        String analyticsScript =
            ParamUtil.getString(
                actionRequest,
                SitesUtil.ANALYTICS_PREFIX + analyticsType,
                typeSettingsProperties.getProperty(analyticsType));

        typeSettingsProperties.setProperty(
            SitesUtil.ANALYTICS_PREFIX + analyticsType, analyticsScript);
      }
    }

    String publicRobots =
        ParamUtil.getString(
            actionRequest, "publicRobots", liveGroup.getTypeSettingsProperty("false-robots.txt"));
    String privateRobots =
        ParamUtil.getString(
            actionRequest, "privateRobots", liveGroup.getTypeSettingsProperty("true-robots.txt"));

    typeSettingsProperties.setProperty("false-robots.txt", publicRobots);
    typeSettingsProperties.setProperty("true-robots.txt", privateRobots);

    int trashEnabled =
        ParamUtil.getInteger(
            actionRequest,
            "trashEnabled",
            GetterUtil.getInteger(typeSettingsProperties.getProperty("trashEnabled")));

    typeSettingsProperties.setProperty("trashEnabled", String.valueOf(trashEnabled));

    int trashEntriesMaxAgeCompany =
        PrefsPropsUtil.getInteger(themeDisplay.getCompanyId(), PropsKeys.TRASH_ENTRIES_MAX_AGE);

    int defaultTrashEntriesMaxAgeGroup =
        GetterUtil.getInteger(
            typeSettingsProperties.getProperty("trashEntriesMaxAge"), trashEntriesMaxAgeCompany);

    int trashEntriesMaxAgeGroup =
        ParamUtil.getInteger(actionRequest, "trashEntriesMaxAge", defaultTrashEntriesMaxAgeGroup);

    if (trashEntriesMaxAgeGroup != trashEntriesMaxAgeCompany) {
      typeSettingsProperties.setProperty(
          "trashEntriesMaxAge", String.valueOf(trashEntriesMaxAgeGroup));
    } else {
      typeSettingsProperties.remove("trashEntriesMaxAge");
    }

    // Virtual hosts

    LayoutSet publicLayoutSet = liveGroup.getPublicLayoutSet();

    String publicVirtualHost =
        ParamUtil.getString(
            actionRequest, "publicVirtualHost", publicLayoutSet.getVirtualHostname());

    LayoutSetServiceUtil.updateVirtualHost(liveGroup.getGroupId(), false, publicVirtualHost);

    LayoutSet privateLayoutSet = liveGroup.getPrivateLayoutSet();

    String privateVirtualHost =
        ParamUtil.getString(
            actionRequest, "privateVirtualHost", privateLayoutSet.getVirtualHostname());

    LayoutSetServiceUtil.updateVirtualHost(liveGroup.getGroupId(), true, privateVirtualHost);

    // Staging

    if (liveGroup.hasStagingGroup()) {
      Group stagingGroup = liveGroup.getStagingGroup();

      oldStagingFriendlyURL = stagingGroup.getFriendlyURL();

      friendlyURL =
          ParamUtil.getString(actionRequest, "stagingFriendlyURL", stagingGroup.getFriendlyURL());

      GroupServiceUtil.updateFriendlyURL(stagingGroup.getGroupId(), friendlyURL);

      LayoutSet stagingPublicLayoutSet = stagingGroup.getPublicLayoutSet();

      publicVirtualHost =
          ParamUtil.getString(
              actionRequest,
              "stagingPublicVirtualHost",
              stagingPublicLayoutSet.getVirtualHostname());

      LayoutSetServiceUtil.updateVirtualHost(stagingGroup.getGroupId(), false, publicVirtualHost);

      LayoutSet stagingPrivateLayoutSet = stagingGroup.getPrivateLayoutSet();

      privateVirtualHost =
          ParamUtil.getString(
              actionRequest,
              "stagingPrivateVirtualHost",
              stagingPrivateLayoutSet.getVirtualHostname());

      LayoutSetServiceUtil.updateVirtualHost(stagingGroup.getGroupId(), true, privateVirtualHost);
    }

    liveGroup =
        GroupServiceUtil.updateGroup(liveGroup.getGroupId(), typeSettingsProperties.toString());

    // Layout set prototypes

    if (!liveGroup.isStaged()) {
      long privateLayoutSetPrototypeId =
          ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId");
      long publicLayoutSetPrototypeId =
          ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId");

      boolean privateLayoutSetPrototypeLinkEnabled =
          ParamUtil.getBoolean(
              actionRequest,
              "privateLayoutSetPrototypeLinkEnabled",
              privateLayoutSet.isLayoutSetPrototypeLinkEnabled());
      boolean publicLayoutSetPrototypeLinkEnabled =
          ParamUtil.getBoolean(
              actionRequest,
              "publicLayoutSetPrototypeLinkEnabled",
              publicLayoutSet.isLayoutSetPrototypeLinkEnabled());

      if ((privateLayoutSetPrototypeId == 0)
          && (publicLayoutSetPrototypeId == 0)
          && !privateLayoutSetPrototypeLinkEnabled
          && !publicLayoutSetPrototypeLinkEnabled) {

        long layoutSetPrototypeId = ParamUtil.getLong(actionRequest, "layoutSetPrototypeId");
        int layoutSetVisibility = ParamUtil.getInteger(actionRequest, "layoutSetVisibility");
        boolean layoutSetPrototypeLinkEnabled =
            ParamUtil.getBoolean(
                actionRequest, "layoutSetPrototypeLinkEnabled", (layoutSetPrototypeId > 0));

        if (layoutSetVisibility == _LAYOUT_SET_VISIBILITY_PRIVATE) {
          privateLayoutSetPrototypeId = layoutSetPrototypeId;

          privateLayoutSetPrototypeLinkEnabled = layoutSetPrototypeLinkEnabled;
        } else {
          publicLayoutSetPrototypeId = layoutSetPrototypeId;

          publicLayoutSetPrototypeLinkEnabled = layoutSetPrototypeLinkEnabled;
        }
      }

      SitesUtil.updateLayoutSetPrototypesLinks(
          liveGroup,
          publicLayoutSetPrototypeId,
          privateLayoutSetPrototypeId,
          publicLayoutSetPrototypeLinkEnabled,
          privateLayoutSetPrototypeLinkEnabled);
    }

    // Staging

    String redirect = ParamUtil.getString(actionRequest, "redirect");

    long refererPlid = GetterUtil.getLong(HttpUtil.getParameter(redirect, "refererPlid", false));

    if (!privateLayoutSet.isLayoutSetPrototypeLinkActive()
        && !publicLayoutSet.isLayoutSetPrototypeLinkActive()) {

      if ((refererPlid > 0)
          && liveGroup.hasStagingGroup()
          && (themeDisplay.getScopeGroupId() != liveGroup.getGroupId())) {

        Layout firstLayout =
            LayoutLocalServiceUtil.fetchFirstLayout(
                liveGroup.getGroupId(), false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

        if (firstLayout == null) {
          firstLayout =
              LayoutLocalServiceUtil.fetchFirstLayout(
                  liveGroup.getGroupId(), true, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
        }

        if (firstLayout != null) {
          refererPlid = firstLayout.getPlid();
        } else {
          refererPlid = 0;
        }
      }

      StagingUtil.updateStaging(actionRequest, liveGroup);
    }

    return new Object[] {liveGroup, oldFriendlyURL, oldStagingFriendlyURL, refererPlid};
  }
  @Override
  public List<Group> getMySiteGroups(String[] classNames, boolean includeControlPanel, int max)
      throws PortalException, SystemException {

    return GroupServiceUtil.getUserSitesGroups(getUserId(), classNames, includeControlPanel, max);
  }