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