1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.communities.action;
24  
25  import com.liferay.portal.LayoutFriendlyURLException;
26  import com.liferay.portal.LayoutHiddenException;
27  import com.liferay.portal.LayoutNameException;
28  import com.liferay.portal.LayoutParentLayoutIdException;
29  import com.liferay.portal.LayoutSetVirtualHostException;
30  import com.liferay.portal.LayoutTypeException;
31  import com.liferay.portal.NoSuchGroupException;
32  import com.liferay.portal.NoSuchLayoutException;
33  import com.liferay.portal.RemoteExportException;
34  import com.liferay.portal.RequiredLayoutException;
35  import com.liferay.portal.events.EventsProcessor;
36  import com.liferay.portal.kernel.configuration.Filter;
37  import com.liferay.portal.kernel.servlet.SessionErrors;
38  import com.liferay.portal.kernel.upload.UploadPortletRequest;
39  import com.liferay.portal.kernel.util.Constants;
40  import com.liferay.portal.kernel.util.FileUtil;
41  import com.liferay.portal.kernel.util.ParamUtil;
42  import com.liferay.portal.kernel.util.StringUtil;
43  import com.liferay.portal.kernel.util.UnicodeProperties;
44  import com.liferay.portal.kernel.util.Validator;
45  import com.liferay.portal.model.ColorScheme;
46  import com.liferay.portal.model.Group;
47  import com.liferay.portal.model.Layout;
48  import com.liferay.portal.model.LayoutConstants;
49  import com.liferay.portal.model.LayoutTypePortlet;
50  import com.liferay.portal.model.PortletPreferencesIds;
51  import com.liferay.portal.model.User;
52  import com.liferay.portal.security.auth.PrincipalException;
53  import com.liferay.portal.security.permission.ActionKeys;
54  import com.liferay.portal.security.permission.PermissionChecker;
55  import com.liferay.portal.service.GroupLocalServiceUtil;
56  import com.liferay.portal.service.GroupServiceUtil;
57  import com.liferay.portal.service.LayoutLocalServiceUtil;
58  import com.liferay.portal.service.LayoutServiceUtil;
59  import com.liferay.portal.service.LayoutSetServiceUtil;
60  import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
61  import com.liferay.portal.service.ThemeLocalServiceUtil;
62  import com.liferay.portal.service.UserLocalServiceUtil;
63  import com.liferay.portal.service.permission.GroupPermissionUtil;
64  import com.liferay.portal.service.permission.OrganizationPermissionUtil;
65  import com.liferay.portal.service.permission.UserPermissionUtil;
66  import com.liferay.portal.struts.PortletAction;
67  import com.liferay.portal.theme.ThemeDisplay;
68  import com.liferay.portal.util.PortalUtil;
69  import com.liferay.portal.util.PortletKeys;
70  import com.liferay.portal.util.PropsKeys;
71  import com.liferay.portal.util.PropsUtil;
72  import com.liferay.portal.util.PropsValues;
73  import com.liferay.portal.util.WebKeys;
74  import com.liferay.portlet.PortletPreferencesFactoryUtil;
75  import com.liferay.portlet.communities.util.CommunitiesUtil;
76  import com.liferay.portlet.communities.util.StagingUtil;
77  import com.liferay.portlet.tasks.NoSuchProposalException;
78  import com.liferay.util.LocalizationUtil;
79  import com.liferay.util.servlet.UploadException;
80  
81  import java.io.File;
82  
83  import java.util.List;
84  import java.util.Locale;
85  import java.util.Map;
86  
87  import javax.portlet.ActionRequest;
88  import javax.portlet.ActionResponse;
89  import javax.portlet.PortletConfig;
90  import javax.portlet.PortletPreferences;
91  import javax.portlet.PortletRequest;
92  import javax.portlet.PortletRequestDispatcher;
93  import javax.portlet.RenderRequest;
94  import javax.portlet.RenderResponse;
95  import javax.portlet.ResourceRequest;
96  import javax.portlet.ResourceResponse;
97  
98  import javax.servlet.http.HttpServletRequest;
99  import javax.servlet.http.HttpServletResponse;
100 
101 import org.apache.struts.action.ActionForm;
102 import org.apache.struts.action.ActionForward;
103 import org.apache.struts.action.ActionMapping;
104 
105 /**
106  * <a href="EditPagesAction.java.html"><b><i>View Source</i></b></a>
107  *
108  * @author Brian Wing Shun Chan
109  *
110  */
111 public class EditPagesAction extends PortletAction {
112 
113     public void processAction(
114             ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
115             ActionRequest actionRequest, ActionResponse actionResponse)
116         throws Exception {
117 
118         try {
119             checkPermissions(actionRequest);
120         }
121         catch (PrincipalException pe) {
122             return;
123         }
124 
125         String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
126 
127         try {
128             if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
129                 updateLayout(actionRequest, actionResponse);
130             }
131             else if (cmd.equals(Constants.DELETE)) {
132                 CommunitiesUtil.deleteLayout(actionRequest, actionResponse);
133             }
134             else if (cmd.equals("copy_from_live")) {
135                 StagingUtil.copyFromLive(actionRequest);
136             }
137             else if (cmd.equals("display_order")) {
138                 updateDisplayOrder(actionRequest);
139             }
140             else if (cmd.equals("logo")) {
141                 updateLogo(actionRequest);
142             }
143             else if (cmd.equals("look_and_feel")) {
144                 updateLookAndFeel(actionRequest);
145             }
146             else if (cmd.equals("merge_pages")) {
147                 updateMergePages(actionRequest);
148             }
149             else if (cmd.equals("monitoring")) {
150                 updateMonitoring(actionRequest);
151             }
152             else if (cmd.equals("publish_to_live")) {
153                 StagingUtil.publishToLive(actionRequest);
154             }
155             else if (cmd.equals("publish_to_remote")) {
156                 StagingUtil.publishToRemote(actionRequest);
157             }
158             else if (cmd.equals("schedule_copy_from_live")) {
159                 StagingUtil.scheduleCopyFromLive(actionRequest);
160             }
161             else if (cmd.equals("schedule_publish_to_live")) {
162                 StagingUtil.schedulePublishToLive(actionRequest);
163             }
164             else if (cmd.equals("schedule_publish_to_remote")) {
165                 StagingUtil.schedulePublishToRemote(actionRequest);
166             }
167             else if (cmd.equals("staging")) {
168                 StagingUtil.updateStaging(actionRequest);
169             }
170             else if (cmd.equals("unschedule_copy_from_live")) {
171                 StagingUtil.unscheduleCopyFromLive(actionRequest);
172             }
173             else if (cmd.equals("unschedule_publish_to_live")) {
174                 StagingUtil.unschedulePublishToLive(actionRequest);
175             }
176             else if (cmd.equals("unschedule_publish_to_remote")) {
177                 StagingUtil.unschedulePublishToRemote(actionRequest);
178             }
179             else if (cmd.equals("virtual_host")) {
180                 updateVirtualHost(actionRequest);
181             }
182             else if (cmd.equals("workflow")) {
183                 updateWorkflow(actionRequest);
184             }
185 
186             String redirect = ParamUtil.getString(
187                 actionRequest, "pagesRedirect");
188 
189             sendRedirect(actionRequest, actionResponse, redirect);
190         }
191         catch (Exception e) {
192             if (e instanceof NoSuchLayoutException ||
193                 e instanceof NoSuchProposalException ||
194                 e instanceof PrincipalException) {
195 
196                 SessionErrors.add(actionRequest, e.getClass().getName());
197 
198                 setForward(actionRequest, "portlet.communities.error");
199             }
200             else if (e instanceof RemoteExportException) {
201                 SessionErrors.add(actionRequest, e.getClass().getName(), e);
202 
203                 String redirect = ParamUtil.getString(
204                     actionRequest, "pagesRedirect");
205 
206                 sendRedirect(actionRequest, actionResponse, redirect);
207             }
208             else if (e instanceof LayoutFriendlyURLException ||
209                      e instanceof LayoutHiddenException ||
210                      e instanceof LayoutNameException ||
211                      e instanceof LayoutParentLayoutIdException ||
212                      e instanceof LayoutSetVirtualHostException ||
213                      e instanceof LayoutTypeException ||
214                      e instanceof RequiredLayoutException ||
215                      e instanceof UploadException) {
216 
217                 if (e instanceof LayoutFriendlyURLException) {
218                     SessionErrors.add(
219                         actionRequest,
220                         LayoutFriendlyURLException.class.getName(), e);
221                 }
222                 else {
223                     SessionErrors.add(actionRequest, e.getClass().getName(), e);
224                 }
225             }
226             else {
227                 throw e;
228             }
229         }
230     }
231 
232     public ActionForward render(
233             ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
234             RenderRequest renderRequest, RenderResponse renderResponse)
235         throws Exception {
236 
237         try {
238             checkPermissions(renderRequest);
239         }
240         catch (PrincipalException pe) {
241             SessionErrors.add(
242                 renderRequest, PrincipalException.class.getName());
243 
244             return mapping.findForward("portlet.communities.error");
245         }
246 
247         try {
248             ActionUtil.getGroup(renderRequest);
249         }
250         catch (Exception e) {
251             if (e instanceof NoSuchGroupException ||
252                 e instanceof PrincipalException) {
253 
254                 SessionErrors.add(renderRequest, e.getClass().getName());
255 
256                 return mapping.findForward("portlet.communities.error");
257             }
258             else {
259                 throw e;
260             }
261         }
262 
263         return mapping.findForward(
264             getForward(renderRequest, "portlet.communities.edit_pages"));
265     }
266 
267     public void serveResource(
268             ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
269             ResourceRequest resourceRequest, ResourceResponse resourceResponse)
270         throws Exception {
271 
272         String path =
273             "/html/portlet/communities/scheduled_publishing_events.jsp";
274 
275         PortletRequestDispatcher portletRequestDispatcher =
276             portletConfig.getPortletContext().getRequestDispatcher(path);
277 
278         portletRequestDispatcher.include(resourceRequest, resourceResponse);
279     }
280 
281     protected void checkPermissions(PortletRequest portletRequest)
282         throws Exception {
283 
284         // LEP-850
285 
286         ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
287             WebKeys.THEME_DISPLAY);
288 
289         PermissionChecker permissionChecker =
290             themeDisplay.getPermissionChecker();
291 
292         String tabs1 = ParamUtil.getString(portletRequest, "tabs1");
293 
294         long groupId = ParamUtil.getLong(portletRequest, "groupId");
295         boolean privateLayout = tabs1.equals("private-pages");
296 
297         Group group = GroupLocalServiceUtil.getGroup(groupId);
298 
299         if (group.isCommunity()) {
300             if (!GroupPermissionUtil.contains(
301                     permissionChecker, group.getGroupId(),
302                     ActionKeys.APPROVE_PROPOSAL) &&
303                 !GroupPermissionUtil.contains(
304                     permissionChecker, group.getGroupId(),
305                     ActionKeys.MANAGE_LAYOUTS)) {
306 
307                 throw new PrincipalException();
308             }
309         }
310         else if (group.isOrganization()) {
311             long organizationId = group.getClassPK();
312 
313             if (!OrganizationPermissionUtil.contains(
314                     permissionChecker, organizationId,
315                     ActionKeys.APPROVE_PROPOSAL) &&
316                 !OrganizationPermissionUtil.contains(
317                     permissionChecker, organizationId,
318                     ActionKeys.MANAGE_LAYOUTS)) {
319 
320                 throw new PrincipalException();
321             }
322         }
323         else if (group.isUser()) {
324             long groupUserId = group.getClassPK();
325 
326             User groupUser = UserLocalServiceUtil.getUserById(groupUserId);
327 
328             long[] organizationIds = groupUser.getOrganizationIds();
329 
330             UserPermissionUtil.check(
331                 permissionChecker, groupUserId, organizationIds,
332                 ActionKeys.UPDATE);
333 
334             if ((privateLayout &&
335                  !PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_MODIFIABLE) ||
336                 (!privateLayout &&
337                  !PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_MODIFIABLE)) {
338 
339                 throw new PrincipalException();
340             }
341         }
342     }
343 
344     protected void copyPreferences(
345             ActionRequest actionRequest, Layout layout, Layout copyLayout)
346         throws Exception {
347 
348         long companyId = layout.getCompanyId();
349 
350         LayoutTypePortlet copyLayoutTypePortlet =
351             (LayoutTypePortlet)copyLayout.getLayoutType();
352 
353         List<String> copyPortletIds = copyLayoutTypePortlet.getPortletIds();
354 
355         for (String copyPortletId : copyPortletIds) {
356             HttpServletRequest request = PortalUtil.getHttpServletRequest(
357                 actionRequest);
358 
359             // Copy preference
360 
361             PortletPreferencesIds portletPreferencesIds =
362                 PortletPreferencesFactoryUtil.getPortletPreferencesIds(
363                     request, layout, copyPortletId);
364 
365             PortletPreferencesLocalServiceUtil.getPreferences(
366                 portletPreferencesIds);
367 
368             PortletPreferencesIds copyPortletPreferencesIds =
369                 PortletPreferencesFactoryUtil.getPortletPreferencesIds(
370                     request, copyLayout, copyPortletId);
371 
372             PortletPreferences copyPrefs =
373                 PortletPreferencesLocalServiceUtil.getPreferences(
374                     copyPortletPreferencesIds);
375 
376             PortletPreferencesLocalServiceUtil.updatePreferences(
377                 portletPreferencesIds.getOwnerId(),
378                 portletPreferencesIds.getOwnerType(),
379                 portletPreferencesIds.getPlid(),
380                 portletPreferencesIds.getPortletId(), copyPrefs);
381 
382             // Copy portlet setup
383 
384             PortletPreferencesLocalServiceUtil.getPreferences(
385                 companyId, PortletKeys.PREFS_OWNER_ID_DEFAULT,
386                 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid(),
387                 copyPortletId);
388 
389             copyPrefs =
390                 PortletPreferencesLocalServiceUtil.getPreferences(
391                     companyId, PortletKeys.PREFS_OWNER_ID_DEFAULT,
392                     PortletKeys.PREFS_OWNER_TYPE_LAYOUT, copyLayout.getPlid(),
393                     copyPortletId);
394 
395             PortletPreferencesLocalServiceUtil.updatePreferences(
396                 PortletKeys.PREFS_OWNER_ID_DEFAULT,
397                 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid(),
398                 copyPortletId, copyPrefs);
399         }
400     }
401 
402     protected UnicodeProperties getTypeSettingsProperties(
403         ActionRequest actionRequest) {
404 
405         UnicodeProperties typeSettingsProperties = new UnicodeProperties(true);
406 
407         String prefix = "TypeSettingsProperties(";
408 
409         for (String paramName: actionRequest.getParameterMap().keySet()) {
410             if (paramName.startsWith(prefix)) {
411                 String key = paramName.substring(
412                     prefix.length(), paramName.length() - 1);
413 
414                 typeSettingsProperties.setProperty(
415                     key, actionRequest.getParameter(paramName));
416             }
417         }
418 
419         return typeSettingsProperties;
420     }
421 
422     protected void updateDisplayOrder(ActionRequest actionRequest)
423         throws Exception {
424 
425         long groupId = ParamUtil.getLong(actionRequest, "groupId");
426         boolean privateLayout = ParamUtil.getBoolean(
427             actionRequest, "privateLayout");
428         long parentLayoutId = ParamUtil.getLong(
429             actionRequest, "parentLayoutId");
430         long[] layoutIds = StringUtil.split(
431             ParamUtil.getString(actionRequest, "layoutIds"), 0L);
432 
433         LayoutServiceUtil.setLayouts(
434             groupId, privateLayout, parentLayoutId, layoutIds);
435     }
436 
437     protected void updateLayout(
438             ActionRequest actionRequest, ActionResponse actionResponse)
439         throws Exception {
440 
441         UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(
442             actionRequest);
443 
444         String cmd = ParamUtil.getString(uploadRequest, Constants.CMD);
445 
446         long groupId = ParamUtil.getLong(actionRequest, "groupId");
447         boolean privateLayout = ParamUtil.getBoolean(
448             actionRequest, "privateLayout");
449         long layoutId = ParamUtil.getLong(actionRequest, "layoutId");
450         long parentLayoutId = ParamUtil.getLong(
451             uploadRequest, "parentLayoutId");
452         String description = ParamUtil.getString(uploadRequest, "description");
453         String type = ParamUtil.getString(uploadRequest, "type");
454         boolean hidden = ParamUtil.getBoolean(uploadRequest, "hidden");
455         String friendlyURL = ParamUtil.getString(uploadRequest, "friendlyURL");
456         boolean iconImage = ParamUtil.getBoolean(uploadRequest, "iconImage");
457         byte[] iconBytes = FileUtil.getBytes(
458             uploadRequest.getFile("iconFileName"));
459 
460         boolean inheritFromParentLayoutId = ParamUtil.getBoolean(
461             uploadRequest, "inheritFromParentLayoutId");
462 
463         long copyLayoutId = ParamUtil.getLong(uploadRequest, "copyLayoutId");
464 
465         Map<Locale, String> localeNamesMap =
466             LocalizationUtil.getLocalizedParameter(actionRequest, "name");
467         Map<Locale, String> localeTitlesMap =
468             LocalizationUtil.getLocalizedParameter(actionRequest, "title");
469 
470         if (cmd.equals(Constants.ADD)) {
471 
472             // Add layout
473 
474             if (inheritFromParentLayoutId && (parentLayoutId > 0)) {
475                 Layout parentLayout = LayoutLocalServiceUtil.getLayout(
476                     groupId, privateLayout, parentLayoutId);
477 
478                 Layout layout = LayoutServiceUtil.addLayout(
479                     groupId, privateLayout, parentLayoutId, localeNamesMap,
480                     localeTitlesMap, description, parentLayout.getType(),
481                     parentLayout.isHidden(), friendlyURL);
482 
483                 LayoutServiceUtil.updateLayout(
484                     layout.getGroupId(), layout.isPrivateLayout(),
485                     layout.getLayoutId(), parentLayout.getTypeSettings());
486             }
487             else {
488                 LayoutServiceUtil.addLayout(
489                     groupId, privateLayout, parentLayoutId, localeNamesMap,
490                     localeTitlesMap, description, type, hidden, friendlyURL);
491             }
492         }
493         else {
494 
495             // Update layout
496 
497             Layout layout = LayoutLocalServiceUtil.getLayout(
498                 groupId, privateLayout, layoutId);
499 
500             layout = LayoutServiceUtil.updateLayout(
501                 groupId, privateLayout, layoutId, layout.getParentLayoutId(),
502                 localeNamesMap, localeTitlesMap, description, type, hidden,
503                 friendlyURL, Boolean.valueOf(iconImage), iconBytes);
504 
505             UnicodeProperties formTypeSettingsProperties =
506                 getTypeSettingsProperties(actionRequest);
507 
508             if (type.equals(LayoutConstants.TYPE_PORTLET)) {
509                 if ((copyLayoutId > 0) &&
510                     (copyLayoutId != layout.getLayoutId())) {
511 
512                     try {
513                         Layout copyLayout = LayoutLocalServiceUtil.getLayout(
514                             groupId, privateLayout, copyLayoutId);
515 
516                         if (copyLayout.getType().equals(
517                                 LayoutConstants.TYPE_PORTLET)) {
518 
519                             LayoutServiceUtil.updateLayout(
520                                 groupId, privateLayout, layoutId,
521                                 copyLayout.getTypeSettings());
522 
523                             copyPreferences(actionRequest, layout, copyLayout);
524                         }
525                     }
526                     catch (NoSuchLayoutException nsle) {
527                     }
528                 }
529                 else {
530                     UnicodeProperties layoutTypeSettingsProperties =
531                         layout.getTypeSettingsProperties();
532 
533                     for (String property: formTypeSettingsProperties.keySet()) {
534                         layoutTypeSettingsProperties.setProperty(
535                             property,
536                             formTypeSettingsProperties.getProperty(property));
537                     }
538 
539                     LayoutServiceUtil.updateLayout(
540                         groupId, privateLayout, layoutId,
541                         layout.getTypeSettings());
542                 }
543             }
544             else {
545                 layout.setTypeSettingsProperties(formTypeSettingsProperties);
546 
547                 LayoutServiceUtil.updateLayout(
548                     groupId, privateLayout, layoutId, layout.getTypeSettings());
549             }
550 
551             HttpServletResponse response = PortalUtil.getHttpServletResponse(
552                 actionResponse);
553 
554             String[] eventClasses = StringUtil.split(
555                 PropsUtil.get(
556                     PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE,
557                     new Filter(type)));
558 
559             EventsProcessor.process(
560                 PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE, eventClasses,
561                 uploadRequest, response);
562         }
563     }
564 
565     protected void updateLogo(ActionRequest actionRequest) throws Exception {
566         UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(
567             actionRequest);
568 
569         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
570         long stagingGroupId = ParamUtil.getLong(
571             actionRequest, "stagingGroupId");
572 
573         boolean privateLayout = ParamUtil.getBoolean(
574             actionRequest, "privateLayout");
575         boolean logo = ParamUtil.getBoolean(actionRequest, "logo");
576 
577         File file = uploadRequest.getFile("logoFileName");
578         byte[] bytes = FileUtil.getBytes(file);
579 
580         if (logo && ((bytes == null) || (bytes.length == 0))) {
581             throw new UploadException();
582         }
583 
584         LayoutSetServiceUtil.updateLogo(liveGroupId, privateLayout, logo, file);
585 
586         if (stagingGroupId > 0) {
587             LayoutSetServiceUtil.updateLogo(
588                 stagingGroupId, privateLayout, logo, file);
589         }
590     }
591 
592     protected void updateLookAndFeel(ActionRequest actionRequest)
593         throws Exception {
594 
595         ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
596             WebKeys.THEME_DISPLAY);
597 
598         long companyId = themeDisplay.getCompanyId();
599 
600         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
601         long stagingGroupId = ParamUtil.getLong(
602             actionRequest, "stagingGroupId");
603 
604         boolean privateLayout = ParamUtil.getBoolean(
605             actionRequest, "privateLayout");
606         long layoutId = ParamUtil.getLong(actionRequest, "layoutId");
607         String themeId = ParamUtil.getString(actionRequest, "themeId");
608         String colorSchemeId = ParamUtil.getString(
609             actionRequest, "colorSchemeId");
610         String css = ParamUtil.getString(actionRequest, "css");
611         boolean wapTheme = ParamUtil.getBoolean(actionRequest, "wapTheme");
612 
613         if (stagingGroupId > 0) {
614             updateLookAndFeel(
615                 companyId, stagingGroupId, privateLayout, layoutId, themeId,
616                 colorSchemeId, css, wapTheme);
617         }
618         else {
619             updateLookAndFeel(
620                 companyId, liveGroupId, privateLayout, layoutId, themeId,
621                 colorSchemeId, css, wapTheme);
622         }
623     }
624 
625     protected void updateLookAndFeel(
626             long companyId, long groupId, boolean privateLayout, long layoutId,
627             String themeId, String colorSchemeId, String css, boolean wapTheme)
628         throws Exception {
629 
630         if (Validator.isNotNull(themeId) && Validator.isNull(colorSchemeId)) {
631             ColorScheme colorScheme = ThemeLocalServiceUtil.getColorScheme(
632                 companyId, themeId, colorSchemeId, wapTheme);
633 
634             colorSchemeId = colorScheme.getColorSchemeId();
635         }
636 
637         if (layoutId <= 0) {
638             LayoutSetServiceUtil.updateLookAndFeel(
639                 groupId, privateLayout, themeId, colorSchemeId, css, wapTheme);
640         }
641         else {
642             LayoutServiceUtil.updateLookAndFeel(
643                 groupId, privateLayout, layoutId, themeId, colorSchemeId, css,
644                 wapTheme);
645         }
646     }
647 
648     protected void updateMergePages(ActionRequest actionRequest)
649         throws Exception {
650 
651         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
652 
653         boolean mergeGuestPublicPages = ParamUtil.getBoolean(
654             actionRequest, "mergeGuestPublicPages");
655 
656         Group liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);
657 
658         UnicodeProperties props = liveGroup.getTypeSettingsProperties();
659 
660         props.setProperty(
661             "mergeGuestPublicPages", String.valueOf(mergeGuestPublicPages));
662 
663         GroupServiceUtil.updateGroup(liveGroupId, liveGroup.getTypeSettings());
664     }
665 
666     protected void updateMonitoring(ActionRequest actionRequest)
667         throws Exception {
668 
669         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
670 
671         String googleAnalyticsId = ParamUtil.getString(
672             actionRequest, "googleAnalyticsId");
673 
674         Group liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);
675 
676         UnicodeProperties props = liveGroup.getTypeSettingsProperties();
677 
678         props.setProperty("googleAnalyticsId", googleAnalyticsId);
679 
680         GroupServiceUtil.updateGroup(liveGroupId, liveGroup.getTypeSettings());
681     }
682 
683     protected void updateVirtualHost(ActionRequest actionRequest)
684         throws Exception {
685 
686         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
687 
688         String publicVirtualHost = ParamUtil.getString(
689             actionRequest, "publicVirtualHost");
690         String privateVirtualHost = ParamUtil.getString(
691             actionRequest, "privateVirtualHost");
692         String friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL");
693 
694         LayoutSetServiceUtil.updateVirtualHost(
695             liveGroupId, false, publicVirtualHost);
696 
697         LayoutSetServiceUtil.updateVirtualHost(
698             liveGroupId, true, privateVirtualHost);
699 
700         GroupServiceUtil.updateFriendlyURL(liveGroupId, friendlyURL);
701 
702         Group liveGroup = GroupServiceUtil.getGroup(liveGroupId);
703 
704         if (liveGroup.hasStagingGroup()) {
705             Group stagingGroup = liveGroup.getStagingGroup();
706 
707             publicVirtualHost = ParamUtil.getString(
708                 actionRequest, "stagingPublicVirtualHost");
709             privateVirtualHost = ParamUtil.getString(
710                 actionRequest, "stagingPrivateVirtualHost");
711             friendlyURL = ParamUtil.getString(
712                 actionRequest, "stagingFriendlyURL");
713 
714             LayoutSetServiceUtil.updateVirtualHost(
715                 stagingGroup.getGroupId(), false, publicVirtualHost);
716 
717             LayoutSetServiceUtil.updateVirtualHost(
718                 stagingGroup.getGroupId(), true, privateVirtualHost);
719 
720             GroupServiceUtil.updateFriendlyURL(
721                 stagingGroup.getGroupId(), friendlyURL);
722         }
723     }
724 
725     protected void updateWorkflow(ActionRequest actionRequest)
726         throws Exception {
727 
728         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
729 
730         boolean workflowEnabled = ParamUtil.getBoolean(
731             actionRequest, "workflowEnabled");
732         int workflowStages = ParamUtil.getInteger(
733             actionRequest, "workflowStages");
734 
735         StringBuilder sb = new StringBuilder();
736 
737         for (int i = 1; i <= workflowStages; i++) {
738             String workflowRoleName = ParamUtil.getString(
739                 actionRequest, "workflowRoleName_" + i);
740 
741             sb.append(workflowRoleName);
742 
743             if ((i + 1) <= workflowStages) {
744                 sb.append(",");
745             }
746         }
747 
748         String workflowRoleNames = sb.toString();
749 
750         GroupServiceUtil.updateWorkflow(
751             liveGroupId, workflowEnabled, workflowStages, workflowRoleNames);
752     }
753 
754 }