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         long groupId = ParamUtil.getLong(portletRequest, "groupId");
293         boolean privateLayout = ParamUtil.getBoolean(
294             portletRequest, "privateLayout");
295 
296         Group group = GroupLocalServiceUtil.getGroup(groupId);
297 
298         if (group.isCommunity()) {
299             if (!GroupPermissionUtil.contains(
300                     permissionChecker, group.getGroupId(),
301                     ActionKeys.APPROVE_PROPOSAL) &&
302                 !GroupPermissionUtil.contains(
303                     permissionChecker, group.getGroupId(),
304                     ActionKeys.MANAGE_LAYOUTS)) {
305 
306                 throw new PrincipalException();
307             }
308         }
309         else if (group.isOrganization()) {
310             long organizationId = group.getClassPK();
311 
312             if (!OrganizationPermissionUtil.contains(
313                     permissionChecker, organizationId,
314                     ActionKeys.APPROVE_PROPOSAL) &&
315                 !OrganizationPermissionUtil.contains(
316                     permissionChecker, organizationId,
317                     ActionKeys.MANAGE_LAYOUTS)) {
318 
319                 throw new PrincipalException();
320             }
321         }
322         else if (group.isUser()) {
323             long groupUserId = group.getClassPK();
324 
325             User groupUser = UserLocalServiceUtil.getUserById(groupUserId);
326 
327             long[] organizationIds = groupUser.getOrganizationIds();
328 
329             UserPermissionUtil.check(
330                 permissionChecker, groupUserId, organizationIds,
331                 ActionKeys.UPDATE);
332 
333             if ((privateLayout &&
334                  !PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_MODIFIABLE) ||
335                 (!privateLayout &&
336                  !PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_MODIFIABLE)) {
337 
338                 throw new PrincipalException();
339             }
340         }
341     }
342 
343     protected void copyPreferences(
344             ActionRequest actionRequest, Layout layout, Layout copyLayout)
345         throws Exception {
346 
347         long companyId = layout.getCompanyId();
348 
349         LayoutTypePortlet copyLayoutTypePortlet =
350             (LayoutTypePortlet)copyLayout.getLayoutType();
351 
352         List<String> copyPortletIds = copyLayoutTypePortlet.getPortletIds();
353 
354         for (String copyPortletId : copyPortletIds) {
355             HttpServletRequest request = PortalUtil.getHttpServletRequest(
356                 actionRequest);
357 
358             // Copy preference
359 
360             PortletPreferencesIds portletPreferencesIds =
361                 PortletPreferencesFactoryUtil.getPortletPreferencesIds(
362                     request, layout, copyPortletId);
363 
364             PortletPreferencesLocalServiceUtil.getPreferences(
365                 portletPreferencesIds);
366 
367             PortletPreferencesIds copyPortletPreferencesIds =
368                 PortletPreferencesFactoryUtil.getPortletPreferencesIds(
369                     request, copyLayout, copyPortletId);
370 
371             PortletPreferences copyPrefs =
372                 PortletPreferencesLocalServiceUtil.getPreferences(
373                     copyPortletPreferencesIds);
374 
375             PortletPreferencesLocalServiceUtil.updatePreferences(
376                 portletPreferencesIds.getOwnerId(),
377                 portletPreferencesIds.getOwnerType(),
378                 portletPreferencesIds.getPlid(),
379                 portletPreferencesIds.getPortletId(), copyPrefs);
380 
381             // Copy portlet setup
382 
383             PortletPreferencesLocalServiceUtil.getPreferences(
384                 companyId, PortletKeys.PREFS_OWNER_ID_DEFAULT,
385                 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid(),
386                 copyPortletId);
387 
388             copyPrefs =
389                 PortletPreferencesLocalServiceUtil.getPreferences(
390                     companyId, PortletKeys.PREFS_OWNER_ID_DEFAULT,
391                     PortletKeys.PREFS_OWNER_TYPE_LAYOUT, copyLayout.getPlid(),
392                     copyPortletId);
393 
394             PortletPreferencesLocalServiceUtil.updatePreferences(
395                 PortletKeys.PREFS_OWNER_ID_DEFAULT,
396                 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid(),
397                 copyPortletId, copyPrefs);
398         }
399     }
400 
401     protected UnicodeProperties getTypeSettingsProperties(
402         ActionRequest actionRequest) {
403 
404         UnicodeProperties typeSettingsProperties = new UnicodeProperties(true);
405 
406         String prefix = "TypeSettingsProperties(";
407 
408         for (String paramName: actionRequest.getParameterMap().keySet()) {
409             if (paramName.startsWith(prefix)) {
410                 String key = paramName.substring(
411                     prefix.length(), paramName.length() - 1);
412 
413                 typeSettingsProperties.setProperty(
414                     key, actionRequest.getParameter(paramName));
415             }
416         }
417 
418         return typeSettingsProperties;
419     }
420 
421     protected void updateDisplayOrder(ActionRequest actionRequest)
422         throws Exception {
423 
424         long groupId = ParamUtil.getLong(actionRequest, "groupId");
425         boolean privateLayout = ParamUtil.getBoolean(
426             actionRequest, "privateLayout");
427         long parentLayoutId = ParamUtil.getLong(
428             actionRequest, "parentLayoutId");
429         long[] layoutIds = StringUtil.split(
430             ParamUtil.getString(actionRequest, "layoutIds"), 0L);
431 
432         LayoutServiceUtil.setLayouts(
433             groupId, privateLayout, parentLayoutId, layoutIds);
434     }
435 
436     protected void updateLayout(
437             ActionRequest actionRequest, ActionResponse actionResponse)
438         throws Exception {
439 
440         UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(
441             actionRequest);
442 
443         String cmd = ParamUtil.getString(uploadRequest, Constants.CMD);
444 
445         long groupId = ParamUtil.getLong(actionRequest, "groupId");
446         boolean privateLayout = ParamUtil.getBoolean(
447             actionRequest, "privateLayout");
448         long layoutId = ParamUtil.getLong(actionRequest, "layoutId");
449         long parentLayoutId = ParamUtil.getLong(
450             uploadRequest, "parentLayoutId");
451         String description = ParamUtil.getString(uploadRequest, "description");
452         String type = ParamUtil.getString(uploadRequest, "type");
453         boolean hidden = ParamUtil.getBoolean(uploadRequest, "hidden");
454         String friendlyURL = ParamUtil.getString(uploadRequest, "friendlyURL");
455         boolean iconImage = ParamUtil.getBoolean(uploadRequest, "iconImage");
456         byte[] iconBytes = FileUtil.getBytes(
457             uploadRequest.getFile("iconFileName"));
458 
459         boolean inheritFromParentLayoutId = ParamUtil.getBoolean(
460             uploadRequest, "inheritFromParentLayoutId");
461 
462         long copyLayoutId = ParamUtil.getLong(uploadRequest, "copyLayoutId");
463 
464         Map<Locale, String> localeNamesMap =
465             LocalizationUtil.getLocalizedParameter(actionRequest, "name");
466         Map<Locale, String> localeTitlesMap =
467             LocalizationUtil.getLocalizedParameter(actionRequest, "title");
468 
469         if (cmd.equals(Constants.ADD)) {
470 
471             // Add layout
472 
473             if (inheritFromParentLayoutId && (parentLayoutId > 0)) {
474                 Layout parentLayout = LayoutLocalServiceUtil.getLayout(
475                     groupId, privateLayout, parentLayoutId);
476 
477                 Layout layout = LayoutServiceUtil.addLayout(
478                     groupId, privateLayout, parentLayoutId, localeNamesMap,
479                     localeTitlesMap, description, parentLayout.getType(),
480                     parentLayout.isHidden(), friendlyURL);
481 
482                 LayoutServiceUtil.updateLayout(
483                     layout.getGroupId(), layout.isPrivateLayout(),
484                     layout.getLayoutId(), parentLayout.getTypeSettings());
485             }
486             else {
487                 LayoutServiceUtil.addLayout(
488                     groupId, privateLayout, parentLayoutId, localeNamesMap,
489                     localeTitlesMap, description, type, hidden, friendlyURL);
490             }
491         }
492         else {
493 
494             // Update layout
495 
496             Layout layout = LayoutLocalServiceUtil.getLayout(
497                 groupId, privateLayout, layoutId);
498 
499             layout = LayoutServiceUtil.updateLayout(
500                 groupId, privateLayout, layoutId, layout.getParentLayoutId(),
501                 localeNamesMap, localeTitlesMap, description, type, hidden,
502                 friendlyURL, Boolean.valueOf(iconImage), iconBytes);
503 
504             UnicodeProperties formTypeSettingsProperties =
505                 getTypeSettingsProperties(actionRequest);
506 
507             if (type.equals(LayoutConstants.TYPE_PORTLET)) {
508                 if ((copyLayoutId > 0) &&
509                     (copyLayoutId != layout.getLayoutId())) {
510 
511                     try {
512                         Layout copyLayout = LayoutLocalServiceUtil.getLayout(
513                             groupId, privateLayout, copyLayoutId);
514 
515                         if (copyLayout.getType().equals(
516                                 LayoutConstants.TYPE_PORTLET)) {
517 
518                             LayoutServiceUtil.updateLayout(
519                                 groupId, privateLayout, layoutId,
520                                 copyLayout.getTypeSettings());
521 
522                             copyPreferences(actionRequest, layout, copyLayout);
523                         }
524                     }
525                     catch (NoSuchLayoutException nsle) {
526                     }
527                 }
528                 else {
529                     UnicodeProperties layoutTypeSettingsProperties =
530                         layout.getTypeSettingsProperties();
531 
532                     for (String property: formTypeSettingsProperties.keySet()) {
533                         layoutTypeSettingsProperties.setProperty(
534                             property,
535                             formTypeSettingsProperties.getProperty(property));
536                     }
537 
538                     LayoutServiceUtil.updateLayout(
539                         groupId, privateLayout, layoutId,
540                         layout.getTypeSettings());
541                 }
542             }
543             else {
544                 layout.setTypeSettingsProperties(formTypeSettingsProperties);
545 
546                 LayoutServiceUtil.updateLayout(
547                     groupId, privateLayout, layoutId, layout.getTypeSettings());
548             }
549 
550             HttpServletResponse response = PortalUtil.getHttpServletResponse(
551                 actionResponse);
552 
553             String[] eventClasses = StringUtil.split(
554                 PropsUtil.get(
555                     PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE,
556                     new Filter(type)));
557 
558             EventsProcessor.process(
559                 PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE, eventClasses,
560                 uploadRequest, response);
561         }
562     }
563 
564     protected void updateLogo(ActionRequest actionRequest) throws Exception {
565         UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(
566             actionRequest);
567 
568         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
569         long stagingGroupId = ParamUtil.getLong(
570             actionRequest, "stagingGroupId");
571 
572         boolean privateLayout = ParamUtil.getBoolean(
573             actionRequest, "privateLayout");
574         boolean logo = ParamUtil.getBoolean(actionRequest, "logo");
575 
576         File file = uploadRequest.getFile("logoFileName");
577         byte[] bytes = FileUtil.getBytes(file);
578 
579         if (logo && ((bytes == null) || (bytes.length == 0))) {
580             throw new UploadException();
581         }
582 
583         LayoutSetServiceUtil.updateLogo(liveGroupId, privateLayout, logo, file);
584 
585         if (stagingGroupId > 0) {
586             LayoutSetServiceUtil.updateLogo(
587                 stagingGroupId, privateLayout, logo, file);
588         }
589     }
590 
591     protected void updateLookAndFeel(ActionRequest actionRequest)
592         throws Exception {
593 
594         ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
595             WebKeys.THEME_DISPLAY);
596 
597         long companyId = themeDisplay.getCompanyId();
598 
599         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
600         long stagingGroupId = ParamUtil.getLong(
601             actionRequest, "stagingGroupId");
602 
603         boolean privateLayout = ParamUtil.getBoolean(
604             actionRequest, "privateLayout");
605         long layoutId = ParamUtil.getLong(actionRequest, "layoutId");
606         String themeId = ParamUtil.getString(actionRequest, "themeId");
607         String colorSchemeId = ParamUtil.getString(
608             actionRequest, "colorSchemeId");
609         String css = ParamUtil.getString(actionRequest, "css");
610         boolean wapTheme = ParamUtil.getBoolean(actionRequest, "wapTheme");
611 
612         if (stagingGroupId > 0) {
613             updateLookAndFeel(
614                 companyId, stagingGroupId, privateLayout, layoutId, themeId,
615                 colorSchemeId, css, wapTheme);
616         }
617         else {
618             updateLookAndFeel(
619                 companyId, liveGroupId, privateLayout, layoutId, themeId,
620                 colorSchemeId, css, wapTheme);
621         }
622     }
623 
624     protected void updateLookAndFeel(
625             long companyId, long groupId, boolean privateLayout, long layoutId,
626             String themeId, String colorSchemeId, String css, boolean wapTheme)
627         throws Exception {
628 
629         if (Validator.isNotNull(themeId) && Validator.isNull(colorSchemeId)) {
630             ColorScheme colorScheme = ThemeLocalServiceUtil.getColorScheme(
631                 companyId, themeId, colorSchemeId, wapTheme);
632 
633             colorSchemeId = colorScheme.getColorSchemeId();
634         }
635 
636         if (layoutId <= 0) {
637             LayoutSetServiceUtil.updateLookAndFeel(
638                 groupId, privateLayout, themeId, colorSchemeId, css, wapTheme);
639         }
640         else {
641             LayoutServiceUtil.updateLookAndFeel(
642                 groupId, privateLayout, layoutId, themeId, colorSchemeId, css,
643                 wapTheme);
644         }
645     }
646 
647     protected void updateMergePages(ActionRequest actionRequest)
648         throws Exception {
649 
650         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
651 
652         boolean mergeGuestPublicPages = ParamUtil.getBoolean(
653             actionRequest, "mergeGuestPublicPages");
654 
655         Group liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);
656 
657         UnicodeProperties props = liveGroup.getTypeSettingsProperties();
658 
659         props.setProperty(
660             "mergeGuestPublicPages", String.valueOf(mergeGuestPublicPages));
661 
662         GroupServiceUtil.updateGroup(liveGroupId, liveGroup.getTypeSettings());
663     }
664 
665     protected void updateMonitoring(ActionRequest actionRequest)
666         throws Exception {
667 
668         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
669 
670         String googleAnalyticsId = ParamUtil.getString(
671             actionRequest, "googleAnalyticsId");
672 
673         Group liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);
674 
675         UnicodeProperties props = liveGroup.getTypeSettingsProperties();
676 
677         props.setProperty("googleAnalyticsId", googleAnalyticsId);
678 
679         GroupServiceUtil.updateGroup(liveGroupId, liveGroup.getTypeSettings());
680     }
681 
682     protected void updateVirtualHost(ActionRequest actionRequest)
683         throws Exception {
684 
685         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
686 
687         String publicVirtualHost = ParamUtil.getString(
688             actionRequest, "publicVirtualHost");
689         String privateVirtualHost = ParamUtil.getString(
690             actionRequest, "privateVirtualHost");
691         String friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL");
692 
693         LayoutSetServiceUtil.updateVirtualHost(
694             liveGroupId, false, publicVirtualHost);
695 
696         LayoutSetServiceUtil.updateVirtualHost(
697             liveGroupId, true, privateVirtualHost);
698 
699         GroupServiceUtil.updateFriendlyURL(liveGroupId, friendlyURL);
700 
701         Group liveGroup = GroupServiceUtil.getGroup(liveGroupId);
702 
703         if (liveGroup.hasStagingGroup()) {
704             Group stagingGroup = liveGroup.getStagingGroup();
705 
706             publicVirtualHost = ParamUtil.getString(
707                 actionRequest, "stagingPublicVirtualHost");
708             privateVirtualHost = ParamUtil.getString(
709                 actionRequest, "stagingPrivateVirtualHost");
710             friendlyURL = ParamUtil.getString(
711                 actionRequest, "stagingFriendlyURL");
712 
713             LayoutSetServiceUtil.updateVirtualHost(
714                 stagingGroup.getGroupId(), false, publicVirtualHost);
715 
716             LayoutSetServiceUtil.updateVirtualHost(
717                 stagingGroup.getGroupId(), true, privateVirtualHost);
718 
719             GroupServiceUtil.updateFriendlyURL(
720                 stagingGroup.getGroupId(), friendlyURL);
721         }
722     }
723 
724     protected void updateWorkflow(ActionRequest actionRequest)
725         throws Exception {
726 
727         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
728 
729         boolean workflowEnabled = ParamUtil.getBoolean(
730             actionRequest, "workflowEnabled");
731         int workflowStages = ParamUtil.getInteger(
732             actionRequest, "workflowStages");
733 
734         StringBuilder sb = new StringBuilder();
735 
736         for (int i = 1; i <= workflowStages; i++) {
737             String workflowRoleName = ParamUtil.getString(
738                 actionRequest, "workflowRoleName_" + i);
739 
740             sb.append(workflowRoleName);
741 
742             if ((i + 1) <= workflowStages) {
743                 sb.append(",");
744             }
745         }
746 
747         String workflowRoleNames = sb.toString();
748 
749         GroupServiceUtil.updateWorkflow(
750             liveGroupId, workflowEnabled, workflowStages, workflowRoleNames);
751     }
752 
753 }