001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.sites.action;
016    
017    import com.liferay.portal.DuplicateGroupException;
018    import com.liferay.portal.GroupFriendlyURLException;
019    import com.liferay.portal.GroupNameException;
020    import com.liferay.portal.GroupParentException;
021    import com.liferay.portal.LayoutSetVirtualHostException;
022    import com.liferay.portal.LocaleException;
023    import com.liferay.portal.NoSuchGroupException;
024    import com.liferay.portal.NoSuchLayoutException;
025    import com.liferay.portal.PendingBackgroundTaskException;
026    import com.liferay.portal.RemoteExportException;
027    import com.liferay.portal.RemoteOptionsException;
028    import com.liferay.portal.RequiredGroupException;
029    import com.liferay.portal.kernel.dao.orm.QueryUtil;
030    import com.liferay.portal.kernel.exception.PortalException;
031    import com.liferay.portal.kernel.exception.SystemException;
032    import com.liferay.portal.kernel.servlet.SessionErrors;
033    import com.liferay.portal.kernel.staging.StagingUtil;
034    import com.liferay.portal.kernel.util.Constants;
035    import com.liferay.portal.kernel.util.GetterUtil;
036    import com.liferay.portal.kernel.util.HttpUtil;
037    import com.liferay.portal.kernel.util.ListUtil;
038    import com.liferay.portal.kernel.util.ParamUtil;
039    import com.liferay.portal.kernel.util.PrefsPropsUtil;
040    import com.liferay.portal.kernel.util.PropertiesParamUtil;
041    import com.liferay.portal.kernel.util.PropsKeys;
042    import com.liferay.portal.kernel.util.StringPool;
043    import com.liferay.portal.kernel.util.StringUtil;
044    import com.liferay.portal.kernel.util.UnicodeProperties;
045    import com.liferay.portal.kernel.util.UniqueList;
046    import com.liferay.portal.kernel.util.Validator;
047    import com.liferay.portal.liveusers.LiveUsers;
048    import com.liferay.portal.model.Group;
049    import com.liferay.portal.model.GroupConstants;
050    import com.liferay.portal.model.Layout;
051    import com.liferay.portal.model.LayoutConstants;
052    import com.liferay.portal.model.LayoutSet;
053    import com.liferay.portal.model.LayoutSetPrototype;
054    import com.liferay.portal.model.MembershipRequest;
055    import com.liferay.portal.model.MembershipRequestConstants;
056    import com.liferay.portal.model.Role;
057    import com.liferay.portal.model.Team;
058    import com.liferay.portal.security.auth.PrincipalException;
059    import com.liferay.portal.service.GroupLocalServiceUtil;
060    import com.liferay.portal.service.GroupServiceUtil;
061    import com.liferay.portal.service.LayoutLocalServiceUtil;
062    import com.liferay.portal.service.LayoutSetLocalServiceUtil;
063    import com.liferay.portal.service.LayoutSetPrototypeServiceUtil;
064    import com.liferay.portal.service.LayoutSetServiceUtil;
065    import com.liferay.portal.service.MembershipRequestLocalServiceUtil;
066    import com.liferay.portal.service.MembershipRequestServiceUtil;
067    import com.liferay.portal.service.RoleLocalServiceUtil;
068    import com.liferay.portal.service.ServiceContext;
069    import com.liferay.portal.service.ServiceContextFactory;
070    import com.liferay.portal.service.TeamLocalServiceUtil;
071    import com.liferay.portal.struts.PortletAction;
072    import com.liferay.portal.theme.ThemeDisplay;
073    import com.liferay.portal.util.PortalUtil;
074    import com.liferay.portal.util.PortletKeys;
075    import com.liferay.portal.util.WebKeys;
076    import com.liferay.portlet.asset.AssetCategoryException;
077    import com.liferay.portlet.asset.AssetTagException;
078    import com.liferay.portlet.sites.util.Sites;
079    import com.liferay.portlet.sites.util.SitesUtil;
080    
081    import java.util.ArrayList;
082    import java.util.List;
083    
084    import javax.portlet.ActionRequest;
085    import javax.portlet.ActionResponse;
086    import javax.portlet.PortletConfig;
087    import javax.portlet.PortletRequest;
088    import javax.portlet.PortletURL;
089    import javax.portlet.RenderRequest;
090    import javax.portlet.RenderResponse;
091    
092    import org.apache.struts.action.ActionForm;
093    import org.apache.struts.action.ActionForward;
094    import org.apache.struts.action.ActionMapping;
095    
096    /**
097     * @author Brian Wing Shun Chan
098     * @author Zsolt Berentey
099     * @author Josef Sustacek
100     */
101    public class EditGroupAction extends PortletAction {
102    
103            @Override
104            public void processAction(
105                            ActionMapping actionMapping, ActionForm actionForm,
106                            PortletConfig portletConfig, ActionRequest actionRequest,
107                            ActionResponse actionResponse)
108                    throws Exception {
109    
110                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
111                            WebKeys.THEME_DISPLAY);
112    
113                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
114    
115                    String redirect = ParamUtil.getString(actionRequest, "redirect");
116                    String closeRedirect = ParamUtil.getString(
117                            actionRequest, "closeRedirect");
118    
119                    try {
120                            if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
121                                    Object[] returnValue = updateGroup(actionRequest);
122    
123                                    Group group = (Group)returnValue[0];
124    
125                                    Layout layout = themeDisplay.getLayout();
126    
127                                    Group layoutGroup = layout.getGroup();
128    
129                                    if (cmd.equals(Constants.ADD) && layoutGroup.isControlPanel()) {
130                                            themeDisplay.setScopeGroupId(group.getGroupId());
131    
132                                            PortletURL siteAdministrationURL =
133                                                    PortalUtil.getSiteAdministrationURL(
134                                                            actionResponse, themeDisplay,
135                                                            PortletKeys.SITE_SETTINGS);
136    
137                                            redirect = siteAdministrationURL.toString();
138    
139                                            hideDefaultSuccessMessage(portletConfig, actionRequest);
140                                    }
141                                    else {
142                                            String oldFriendlyURL = (String)returnValue[1];
143                                            String oldStagingFriendlyURL = (String)returnValue[2];
144                                            long newRefererPlid = (Long)returnValue[3];
145    
146                                            redirect = HttpUtil.setParameter(
147                                                    redirect, "doAsGroupId", group.getGroupId());
148                                            redirect = HttpUtil.setParameter(
149                                                    redirect, "refererPlid", newRefererPlid);
150    
151                                            closeRedirect = updateCloseRedirect(
152                                                    closeRedirect, group, themeDisplay, oldFriendlyURL,
153                                                    oldStagingFriendlyURL);
154                                    }
155                            }
156                            else if (cmd.equals(Constants.DEACTIVATE) ||
157                                             cmd.equals(Constants.RESTORE)) {
158    
159                                    updateActive(actionRequest, cmd);
160                            }
161                            else if (cmd.equals(Constants.DELETE)) {
162                                    deleteGroups(actionRequest);
163                            }
164                            else if (cmd.equals("reset_merge_fail_count_and_merge")) {
165                                    resetMergeFailCountAndMerge(actionRequest);
166                            }
167    
168                            sendRedirect(
169                                    portletConfig, actionRequest, actionResponse, redirect,
170                                    closeRedirect);
171                    }
172                    catch (Exception e) {
173                            if (e instanceof NoSuchGroupException ||
174                                    e instanceof PrincipalException) {
175    
176                                    SessionErrors.add(actionRequest, e.getClass());
177    
178                                    setForward(actionRequest, "portlet.sites_admin.error");
179                            }
180                            else if (e instanceof AssetCategoryException ||
181                                             e instanceof AssetTagException ||
182                                             e instanceof DuplicateGroupException ||
183                                             e instanceof GroupFriendlyURLException ||
184                                             e instanceof GroupNameException ||
185                                             e instanceof GroupParentException ||
186                                             e instanceof LayoutSetVirtualHostException ||
187                                             e instanceof LocaleException ||
188                                             e instanceof PendingBackgroundTaskException ||
189                                             e instanceof RemoteExportException ||
190                                             e instanceof RemoteOptionsException ||
191                                             e instanceof RequiredGroupException ||
192                                             e instanceof SystemException) {
193    
194                                    SessionErrors.add(actionRequest, e.getClass(), e);
195    
196                                    sendRedirect(
197                                            portletConfig, actionRequest, actionResponse, redirect,
198                                            closeRedirect);
199                            }
200                            else {
201                                    throw e;
202                            }
203                    }
204            }
205    
206            @Override
207            public ActionForward render(
208                            ActionMapping actionMapping, ActionForm actionForm,
209                            PortletConfig portletConfig, RenderRequest renderRequest,
210                            RenderResponse renderResponse)
211                    throws Exception {
212    
213                    try {
214                            ActionUtil.getGroup(renderRequest);
215                    }
216                    catch (Exception e) {
217                            if (e instanceof NoSuchGroupException ||
218                                    e instanceof PrincipalException) {
219    
220                                    SessionErrors.add(renderRequest, e.getClass());
221    
222                                    return actionMapping.findForward("portlet.sites_admin.error");
223                            }
224                            else {
225                                    throw e;
226                            }
227                    }
228    
229                    return actionMapping.findForward(
230                            getForward(renderRequest, "portlet.sites_admin.edit_site"));
231            }
232    
233            protected void deleteGroups(ActionRequest actionRequest) throws Exception {
234                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
235                            WebKeys.THEME_DISPLAY);
236    
237                    long[] deleteGroupIds = null;
238    
239                    long groupId = ParamUtil.getLong(actionRequest, "groupId");
240    
241                    if (groupId > 0) {
242                            deleteGroupIds = new long[] {groupId};
243                    }
244                    else {
245                            deleteGroupIds = StringUtil.split(
246                                    ParamUtil.getString(actionRequest, "deleteGroupIds"), 0L);
247                    }
248    
249                    for (long deleteGroupId : deleteGroupIds) {
250                            GroupServiceUtil.deleteGroup(deleteGroupId);
251    
252                            LiveUsers.deleteGroup(themeDisplay.getCompanyId(), deleteGroupId);
253                    }
254            }
255    
256            protected long getRefererGroupId(ThemeDisplay themeDisplay)
257                    throws Exception {
258    
259                    long refererGroupId = 0;
260    
261                    try {
262                            Layout refererLayout = LayoutLocalServiceUtil.getLayout(
263                                    themeDisplay.getRefererPlid());
264    
265                            refererGroupId = refererLayout.getGroupId();
266                    }
267                    catch (NoSuchLayoutException nsle) {
268                    }
269    
270                    return refererGroupId;
271            }
272    
273            protected List<Role> getRoles(PortletRequest portletRequest)
274                    throws Exception {
275    
276                    List<Role> roles = new ArrayList<Role>();
277    
278                    long[] siteRolesRoleIds = StringUtil.split(
279                            ParamUtil.getString(portletRequest, "siteRolesRoleIds"), 0L);
280    
281                    for (long siteRolesRoleId : siteRolesRoleIds) {
282                            if (siteRolesRoleId == 0) {
283                                    continue;
284                            }
285    
286                            Role role = RoleLocalServiceUtil.getRole(siteRolesRoleId);
287    
288                            roles.add(role);
289                    }
290    
291                    return roles;
292            }
293    
294            protected List<Team> getTeams(PortletRequest portletRequest)
295                    throws Exception {
296    
297                    List<Team> teams = new UniqueList<Team>();
298    
299                    long[] teamsTeamIds= StringUtil.split(
300                            ParamUtil.getString(portletRequest, "teamsTeamIds"), 0L);
301    
302                    for (long teamsTeamId : teamsTeamIds) {
303                            if (teamsTeamId == 0) {
304                                    continue;
305                            }
306    
307                            Team team = TeamLocalServiceUtil.getTeam(teamsTeamId);
308    
309                            teams.add(team);
310                    }
311    
312                    return teams;
313            }
314    
315            /**
316             * Resets the number of failed merge attempts for the site template, which
317             * is accessed by retrieving the layout set prototype ID. Once the counter
318             * is reset, the modified site template is merged back into its linked site,
319             * which is accessed by retrieving the group ID and private layout set.
320             *
321             * <p>
322             * If the number of failed merge attempts is not equal to zero after the
323             * merge, an error key is submitted to {@link SessionErrors}.
324             * </p>
325             *
326             * @param  actionRequest the portlet request used to retrieve parameters
327             * @throws Exception if an exception occurred
328             */
329            protected void resetMergeFailCountAndMerge(ActionRequest actionRequest)
330                    throws Exception {
331    
332                    long layoutSetPrototypeId = ParamUtil.getLong(
333                            actionRequest, "layoutSetPrototypeId");
334    
335                    LayoutSetPrototype layoutSetPrototype =
336                            LayoutSetPrototypeServiceUtil.getLayoutSetPrototype(
337                                    layoutSetPrototypeId);
338    
339                    SitesUtil.setMergeFailCount(layoutSetPrototype, 0);
340    
341                    long groupId = ParamUtil.getLong(actionRequest, "groupId");
342                    boolean privateLayoutSet = ParamUtil.getBoolean(
343                            actionRequest, "privateLayoutSet");
344    
345                    LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
346                            groupId, privateLayoutSet);
347    
348                    SitesUtil.resetPrototype(layoutSet);
349    
350                    Group group = GroupLocalServiceUtil.getGroup(groupId);
351    
352                    SitesUtil.mergeLayoutSetPrototypeLayouts(group, layoutSet);
353    
354                    layoutSetPrototype =
355                            LayoutSetPrototypeServiceUtil.getLayoutSetPrototype(
356                                    layoutSetPrototypeId);
357    
358                    if (SitesUtil.getMergeFailCount(layoutSetPrototype) > 0) {
359                            SessionErrors.add(actionRequest, "resetMergeFailCountAndMerge");
360                    }
361            }
362    
363            protected void updateActive(ActionRequest actionRequest, String cmd)
364                    throws Exception {
365    
366                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
367                            WebKeys.THEME_DISPLAY);
368    
369                    long groupId = ParamUtil.getLong(actionRequest, "groupId");
370    
371                    if ((groupId == themeDisplay.getDoAsGroupId()) ||
372                            (groupId == themeDisplay.getScopeGroupId()) ||
373                            (groupId == getRefererGroupId(themeDisplay))) {
374    
375                            throw new RequiredGroupException(
376                                    String.valueOf(groupId), RequiredGroupException.CURRENT_GROUP);
377                    }
378    
379                    Group group = GroupServiceUtil.getGroup(groupId);
380    
381                    boolean active = false;
382    
383                    if (cmd.equals(Constants.RESTORE)) {
384                            active = true;
385                    }
386    
387                    ServiceContext serviceContext = ServiceContextFactory.getInstance(
388                            Group.class.getName(), actionRequest);
389    
390                    GroupServiceUtil.updateGroup(
391                            groupId, group.getParentGroupId(), group.getName(),
392                            group.getDescription(), group.getType(), group.isManualMembership(),
393                            group.getMembershipRestriction(), group.getFriendlyURL(), active,
394                            serviceContext);
395            }
396    
397            protected String updateCloseRedirect(
398                            String closeRedirect, Group group, ThemeDisplay themeDisplay,
399                            String oldFriendlyURL, String oldStagingFriendlyURL)
400                    throws PortalException, SystemException {
401    
402                    if (Validator.isNull(closeRedirect) || (group == null)) {
403                            return closeRedirect;
404                    }
405    
406                    String oldPath = null;
407                    String newPath = null;
408    
409                    if (Validator.isNotNull(oldFriendlyURL)) {
410                            oldPath = oldFriendlyURL;
411                            newPath = group.getFriendlyURL();
412    
413                            if (closeRedirect.contains(oldPath)) {
414                                    closeRedirect = PortalUtil.updateRedirect(
415                                            closeRedirect, oldPath, newPath);
416                            }
417                            else {
418                                    closeRedirect = PortalUtil.getGroupFriendlyURL(
419                                            group, false, themeDisplay);
420                            }
421                    }
422    
423                    if (Validator.isNotNull(oldStagingFriendlyURL)) {
424                            Group stagingGroup = group.getStagingGroup();
425    
426                            if (GroupLocalServiceUtil.fetchGroup(
427                                            stagingGroup.getGroupId()) == null) {
428    
429                                    oldPath = oldStagingFriendlyURL;
430                                    newPath = group.getFriendlyURL();
431                            }
432                            else {
433                                    oldPath = oldStagingFriendlyURL;
434                                    newPath = stagingGroup.getFriendlyURL();
435                            }
436    
437                            if (closeRedirect.contains(oldPath)) {
438                                    closeRedirect = PortalUtil.updateRedirect(
439                                            closeRedirect, oldPath, newPath);
440                            }
441                            else {
442                                    closeRedirect = PortalUtil.getGroupFriendlyURL(
443                                            group, false, themeDisplay);
444                            }
445                    }
446    
447                    return closeRedirect;
448            }
449    
450            protected Object[] updateGroup(ActionRequest actionRequest)
451                    throws Exception {
452    
453                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
454                            WebKeys.THEME_DISPLAY);
455    
456                    long userId = PortalUtil.getUserId(actionRequest);
457    
458                    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
459    
460                    long parentGroupId = ParamUtil.getLong(
461                            actionRequest, "parentGroupSearchContainerPrimaryKeys",
462                            GroupConstants.DEFAULT_PARENT_GROUP_ID);
463                    String name = null;
464                    String description = null;
465                    int type = 0;
466                    String friendlyURL = null;
467                    boolean active = false;
468                    boolean manualMembership = true;
469    
470                    int membershipRestriction =
471                            GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION;
472    
473                    boolean actionRequestMembershipRestriction = ParamUtil.getBoolean(
474                            actionRequest, "membershipRestriction");
475    
476                    if (actionRequestMembershipRestriction &&
477                            (parentGroupId != GroupConstants.DEFAULT_PARENT_GROUP_ID)) {
478    
479                            membershipRestriction =
480                                    GroupConstants.MEMBERSHIP_RESTRICTION_TO_PARENT_SITE_MEMBERS;
481                    }
482    
483                    ServiceContext serviceContext = ServiceContextFactory.getInstance(
484                            Group.class.getName(), actionRequest);
485    
486                    Group liveGroup = null;
487                    String oldFriendlyURL = null;
488                    String oldStagingFriendlyURL = null;
489    
490                    if (liveGroupId <= 0) {
491    
492                            // Add group
493    
494                            name = ParamUtil.getString(actionRequest, "name");
495                            description = ParamUtil.getString(actionRequest, "description");
496                            type = ParamUtil.getInteger(actionRequest, "type");
497                            friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL");
498                            active = ParamUtil.getBoolean(actionRequest, "active");
499                            manualMembership = ParamUtil.getBoolean(
500                                    actionRequest, "manualMembership");
501    
502                            liveGroup = GroupServiceUtil.addGroup(
503                                    parentGroupId, GroupConstants.DEFAULT_LIVE_GROUP_ID, name,
504                                    description, type, manualMembership, membershipRestriction,
505                                    friendlyURL, true, active, serviceContext);
506    
507                            LiveUsers.joinGroup(
508                                    themeDisplay.getCompanyId(), liveGroup.getGroupId(), userId);
509                    }
510                    else {
511    
512                            // Update group
513    
514                            liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);
515    
516                            oldFriendlyURL = liveGroup.getFriendlyURL();
517    
518                            name = ParamUtil.getString(
519                                    actionRequest, "name", liveGroup.getName());
520                            description = ParamUtil.getString(
521                                    actionRequest, "description", liveGroup.getDescription());
522                            type = ParamUtil.getInteger(
523                                    actionRequest, "type", liveGroup.getType());
524                            friendlyURL = ParamUtil.getString(
525                                    actionRequest, "friendlyURL", liveGroup.getFriendlyURL());
526                            active = ParamUtil.getBoolean(
527                                    actionRequest, "active", liveGroup.getActive());
528                            manualMembership = ParamUtil.getBoolean(
529                                    actionRequest, "manualMembership",
530                                    liveGroup.isManualMembership());
531    
532                            liveGroup = GroupServiceUtil.updateGroup(
533                                    liveGroupId, parentGroupId, name, description, type,
534                                    manualMembership, membershipRestriction, friendlyURL, active,
535                                    serviceContext);
536    
537                            if (type == GroupConstants.TYPE_SITE_OPEN) {
538                                    List<MembershipRequest> membershipRequests =
539                                            MembershipRequestLocalServiceUtil.search(
540                                                    liveGroupId, MembershipRequestConstants.STATUS_PENDING,
541                                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS);
542    
543                                    for (MembershipRequest membershipRequest : membershipRequests) {
544                                            MembershipRequestServiceUtil.updateStatus(
545                                                    membershipRequest.getMembershipRequestId(),
546                                                    themeDisplay.translate(
547                                                            "your-membership-has-been-approved"),
548                                                    MembershipRequestConstants.STATUS_APPROVED,
549                                                    serviceContext);
550    
551                                            LiveUsers.joinGroup(
552                                                    themeDisplay.getCompanyId(),
553                                                    membershipRequest.getGroupId(),
554                                                    new long[] {membershipRequest.getUserId()});
555                                    }
556                            }
557                    }
558    
559                    // Settings
560    
561                    UnicodeProperties typeSettingsProperties =
562                            liveGroup.getTypeSettingsProperties();
563    
564                    String customJspServletContextName = ParamUtil.getString(
565                            actionRequest, "customJspServletContextName",
566                            typeSettingsProperties.getProperty("customJspServletContextName"));
567    
568                    typeSettingsProperties.setProperty(
569                            "customJspServletContextName", customJspServletContextName);
570    
571                    typeSettingsProperties.setProperty(
572                            "defaultSiteRoleIds",
573                            ListUtil.toString(
574                                    getRoles(actionRequest), Role.ROLE_ID_ACCESSOR,
575                                    StringPool.COMMA));
576                    typeSettingsProperties.setProperty(
577                            "defaultTeamIds",
578                            ListUtil.toString(
579                                    getTeams(actionRequest), Team.TEAM_ID_ACCESSOR,
580                                    StringPool.COMMA));
581    
582                    String[] analyticsTypes = PrefsPropsUtil.getStringArray(
583                            themeDisplay.getCompanyId(), PropsKeys.ADMIN_ANALYTICS_TYPES,
584                            StringPool.NEW_LINE);
585    
586                    for (String analyticsType : analyticsTypes) {
587                            if (analyticsType.equalsIgnoreCase("google")) {
588                                    String googleAnalyticsId = ParamUtil.getString(
589                                            actionRequest, "googleAnalyticsId",
590                                            typeSettingsProperties.getProperty("googleAnalyticsId"));
591    
592                                    typeSettingsProperties.setProperty(
593                                            "googleAnalyticsId", googleAnalyticsId);
594                            }
595                            else {
596                                    String analyticsScript = ParamUtil.getString(
597                                            actionRequest, Sites.ANALYTICS_PREFIX + analyticsType,
598                                            typeSettingsProperties.getProperty(analyticsType));
599    
600                                    typeSettingsProperties.setProperty(
601                                            Sites.ANALYTICS_PREFIX + analyticsType, analyticsScript);
602                            }
603                    }
604    
605                    String publicRobots = ParamUtil.getString(
606                            actionRequest, "publicRobots",
607                            liveGroup.getTypeSettingsProperty("false-robots.txt"));
608                    String privateRobots = ParamUtil.getString(
609                            actionRequest, "privateRobots",
610                            liveGroup.getTypeSettingsProperty("true-robots.txt"));
611    
612                    typeSettingsProperties.setProperty("false-robots.txt", publicRobots);
613                    typeSettingsProperties.setProperty("true-robots.txt", privateRobots);
614    
615                    boolean trashEnabled = ParamUtil.getBoolean(
616                            actionRequest, "trashEnabled",
617                            GetterUtil.getBoolean(
618                                    typeSettingsProperties.getProperty("trashEnabled"), true));
619    
620                    typeSettingsProperties.setProperty(
621                            "trashEnabled", String.valueOf(trashEnabled));
622    
623                    int trashEntriesMaxAgeCompany = PrefsPropsUtil.getInteger(
624                            themeDisplay.getCompanyId(), PropsKeys.TRASH_ENTRIES_MAX_AGE);
625    
626                    double trashEntriesMaxAgeGroup = ParamUtil.getDouble(
627                            actionRequest, "trashEntriesMaxAge");
628    
629                    if (trashEntriesMaxAgeGroup > 0) {
630                            trashEntriesMaxAgeGroup *= 1440;
631                    }
632                    else {
633                            trashEntriesMaxAgeGroup = GetterUtil.getInteger(
634                                    typeSettingsProperties.getProperty("trashEntriesMaxAge"),
635                                    trashEntriesMaxAgeCompany);
636                    }
637    
638                    if (trashEntriesMaxAgeGroup != trashEntriesMaxAgeCompany) {
639                            typeSettingsProperties.setProperty(
640                                    "trashEntriesMaxAge",
641                                    String.valueOf(GetterUtil.getInteger(trashEntriesMaxAgeGroup)));
642                    }
643                    else {
644                            typeSettingsProperties.remove("trashEntriesMaxAge");
645                    }
646    
647                    int contentSharingWithChildrenEnabled = ParamUtil.getInteger(
648                            actionRequest, "contentSharingWithChildrenEnabled",
649                            GetterUtil.getInteger(
650                                    typeSettingsProperties.getProperty(
651                                            "contentSharingWithChildrenEnabled"),
652                                    Sites.CONTENT_SHARING_WITH_CHILDREN_DEFAULT_VALUE));
653    
654                    typeSettingsProperties.setProperty(
655                            "contentSharingWithChildrenEnabled",
656                            String.valueOf(contentSharingWithChildrenEnabled));
657    
658                    UnicodeProperties formTypeSettingsProperties =
659                            PropertiesParamUtil.getProperties(
660                                    actionRequest, "TypeSettingsProperties--");
661    
662                    typeSettingsProperties.putAll(formTypeSettingsProperties);
663    
664                    // Virtual hosts
665    
666                    LayoutSet publicLayoutSet = liveGroup.getPublicLayoutSet();
667    
668                    String publicVirtualHost = ParamUtil.getString(
669                            actionRequest, "publicVirtualHost",
670                            publicLayoutSet.getVirtualHostname());
671    
672                    LayoutSetServiceUtil.updateVirtualHost(
673                            liveGroup.getGroupId(), false, publicVirtualHost);
674    
675                    LayoutSet privateLayoutSet = liveGroup.getPrivateLayoutSet();
676    
677                    String privateVirtualHost = ParamUtil.getString(
678                            actionRequest, "privateVirtualHost",
679                            privateLayoutSet.getVirtualHostname());
680    
681                    LayoutSetServiceUtil.updateVirtualHost(
682                            liveGroup.getGroupId(), true, privateVirtualHost);
683    
684                    // Staging
685    
686                    if (liveGroup.hasStagingGroup()) {
687                            Group stagingGroup = liveGroup.getStagingGroup();
688    
689                            oldStagingFriendlyURL = stagingGroup.getFriendlyURL();
690    
691                            friendlyURL = ParamUtil.getString(
692                                    actionRequest, "stagingFriendlyURL",
693                                    stagingGroup.getFriendlyURL());
694    
695                            GroupServiceUtil.updateFriendlyURL(
696                                    stagingGroup.getGroupId(), friendlyURL);
697    
698                            LayoutSet stagingPublicLayoutSet =
699                                    stagingGroup.getPublicLayoutSet();
700    
701                            publicVirtualHost = ParamUtil.getString(
702                                    actionRequest, "stagingPublicVirtualHost",
703                                    stagingPublicLayoutSet.getVirtualHostname());
704    
705                            LayoutSetServiceUtil.updateVirtualHost(
706                                    stagingGroup.getGroupId(), false, publicVirtualHost);
707    
708                            LayoutSet stagingPrivateLayoutSet =
709                                    stagingGroup.getPrivateLayoutSet();
710    
711                            privateVirtualHost = ParamUtil.getString(
712                                    actionRequest, "stagingPrivateVirtualHost",
713                                    stagingPrivateLayoutSet.getVirtualHostname());
714    
715                            LayoutSetServiceUtil.updateVirtualHost(
716                                    stagingGroup.getGroupId(), true, privateVirtualHost);
717                    }
718    
719                    liveGroup = GroupServiceUtil.updateGroup(
720                            liveGroup.getGroupId(), typeSettingsProperties.toString());
721    
722                    // Layout set prototypes
723    
724                    if (!liveGroup.isStaged()) {
725                            long privateLayoutSetPrototypeId = ParamUtil.getLong(
726                                    actionRequest, "privateLayoutSetPrototypeId");
727                            long publicLayoutSetPrototypeId = ParamUtil.getLong(
728                                    actionRequest, "publicLayoutSetPrototypeId");
729    
730                            boolean privateLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(
731                                    actionRequest, "privateLayoutSetPrototypeLinkEnabled",
732                                    privateLayoutSet.isLayoutSetPrototypeLinkEnabled());
733                            boolean publicLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(
734                                    actionRequest, "publicLayoutSetPrototypeLinkEnabled",
735                                    publicLayoutSet.isLayoutSetPrototypeLinkEnabled());
736    
737                            if ((privateLayoutSetPrototypeId == 0) &&
738                                    (publicLayoutSetPrototypeId == 0) &&
739                                    !privateLayoutSetPrototypeLinkEnabled &&
740                                    !publicLayoutSetPrototypeLinkEnabled) {
741    
742                                    long layoutSetPrototypeId = ParamUtil.getLong(
743                                            actionRequest, "layoutSetPrototypeId");
744                                    int layoutSetVisibility = ParamUtil.getInteger(
745                                            actionRequest, "layoutSetVisibility");
746                                    boolean layoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(
747                                            actionRequest, "layoutSetPrototypeLinkEnabled",
748                                            (layoutSetPrototypeId > 0));
749    
750                                    if (layoutSetVisibility == _LAYOUT_SET_VISIBILITY_PRIVATE) {
751                                            privateLayoutSetPrototypeId = layoutSetPrototypeId;
752    
753                                            privateLayoutSetPrototypeLinkEnabled =
754                                                    layoutSetPrototypeLinkEnabled;
755                                    }
756                                    else {
757                                            publicLayoutSetPrototypeId = layoutSetPrototypeId;
758    
759                                            publicLayoutSetPrototypeLinkEnabled =
760                                                    layoutSetPrototypeLinkEnabled;
761                                    }
762                            }
763    
764                            SitesUtil.updateLayoutSetPrototypesLinks(
765                                    liveGroup, publicLayoutSetPrototypeId,
766                                    privateLayoutSetPrototypeId,
767                                    publicLayoutSetPrototypeLinkEnabled,
768                                    privateLayoutSetPrototypeLinkEnabled);
769                    }
770    
771                    // Staging
772    
773                    String redirect = ParamUtil.getString(actionRequest, "redirect");
774    
775                    long refererPlid = GetterUtil.getLong(
776                            HttpUtil.getParameter(redirect, "refererPlid", false));
777    
778                    if (!privateLayoutSet.isLayoutSetPrototypeLinkActive() &&
779                            !publicLayoutSet.isLayoutSetPrototypeLinkActive()) {
780    
781                            if ((refererPlid > 0) && liveGroup.hasStagingGroup() &&
782                                    (themeDisplay.getScopeGroupId() != liveGroup.getGroupId())) {
783    
784                                    Layout firstLayout = LayoutLocalServiceUtil.fetchFirstLayout(
785                                            liveGroup.getGroupId(), false,
786                                            LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
787    
788                                    if (firstLayout == null) {
789                                            firstLayout = LayoutLocalServiceUtil.fetchFirstLayout(
790                                                    liveGroup.getGroupId(), true,
791                                                    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
792                                    }
793    
794                                    if (firstLayout != null) {
795                                            refererPlid = firstLayout.getPlid();
796                                    }
797                                    else {
798                                            refererPlid = 0;
799                                    }
800                            }
801    
802                            StagingUtil.updateStaging(actionRequest, liveGroup);
803                    }
804    
805                    return new Object[] {
806                            liveGroup, oldFriendlyURL, oldStagingFriendlyURL, refererPlid};
807            }
808    
809            private static final int _LAYOUT_SET_VISIBILITY_PRIVATE = 1;
810    
811    }