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