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