1
19
20 package com.liferay.portlet.communities.action;
21
22 import com.liferay.portal.LayoutFriendlyURLException;
23 import com.liferay.portal.LayoutHiddenException;
24 import com.liferay.portal.LayoutNameException;
25 import com.liferay.portal.LayoutParentLayoutIdException;
26 import com.liferay.portal.LayoutSetVirtualHostException;
27 import com.liferay.portal.LayoutTypeException;
28 import com.liferay.portal.NoSuchGroupException;
29 import com.liferay.portal.NoSuchLayoutException;
30 import com.liferay.portal.RemoteExportException;
31 import com.liferay.portal.RequiredLayoutException;
32 import com.liferay.portal.events.EventsProcessorUtil;
33 import com.liferay.portal.kernel.configuration.Filter;
34 import com.liferay.portal.kernel.servlet.SessionErrors;
35 import com.liferay.portal.kernel.upload.UploadPortletRequest;
36 import com.liferay.portal.kernel.util.Constants;
37 import com.liferay.portal.kernel.util.FileUtil;
38 import com.liferay.portal.kernel.util.GetterUtil;
39 import com.liferay.portal.kernel.util.ParamUtil;
40 import com.liferay.portal.kernel.util.PropertiesParamUtil;
41 import com.liferay.portal.kernel.util.StringUtil;
42 import com.liferay.portal.kernel.util.UnicodeProperties;
43 import com.liferay.portal.kernel.util.Validator;
44 import com.liferay.portal.model.ColorScheme;
45 import com.liferay.portal.model.Group;
46 import com.liferay.portal.model.Layout;
47 import com.liferay.portal.model.LayoutConstants;
48 import com.liferay.portal.model.LayoutTypePortlet;
49 import com.liferay.portal.model.PortletPreferencesIds;
50 import com.liferay.portal.model.User;
51 import com.liferay.portal.security.auth.PrincipalException;
52 import com.liferay.portal.security.permission.ActionKeys;
53 import com.liferay.portal.security.permission.PermissionChecker;
54 import com.liferay.portal.service.GroupLocalServiceUtil;
55 import com.liferay.portal.service.GroupServiceUtil;
56 import com.liferay.portal.service.LayoutLocalServiceUtil;
57 import com.liferay.portal.service.LayoutServiceUtil;
58 import com.liferay.portal.service.LayoutSetServiceUtil;
59 import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
60 import com.liferay.portal.service.ThemeLocalServiceUtil;
61 import com.liferay.portal.service.UserLocalServiceUtil;
62 import com.liferay.portal.service.permission.GroupPermissionUtil;
63 import com.liferay.portal.service.permission.LayoutPermissionUtil;
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
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 resourceId = GetterUtil.getString(
273 resourceRequest.getResourceID());
274
275 if (resourceId.equals("/html/portlet/communities/tree_js_node.jsp")) {
276 long groupId = ParamUtil.getLong(resourceRequest, "groupId");
277 boolean privateLayout = ParamUtil.getBoolean(
278 resourceRequest, "privateLayout");
279 long parentLayoutId = ParamUtil.getLong(
280 resourceRequest, "parentLayoutId");
281 long nodeId = ParamUtil.getLong(resourceRequest, "nodeId");
282 long[] openNodes = StringUtil.split(
283 ParamUtil.getString(resourceRequest, "openNodes"), 0L);
284 boolean selectableTree = ParamUtil.getBoolean(
285 resourceRequest, "selectableTree");
286 long[] selectedNodes = StringUtil.split(
287 ParamUtil.getString(resourceRequest, "selectedNodes"), 0L);
288 String portletURL = ParamUtil.getString(
289 resourceRequest, "portletURL");
290
291 resourceRequest.setAttribute(WebKeys.TREE_GROUP_ID, groupId);
292 resourceRequest.setAttribute(
293 WebKeys.TREE_PRIVATE_LAYOUT, privateLayout);
294 resourceRequest.setAttribute(
295 WebKeys.TREE_PARENT_LAYOUT_ID, parentLayoutId);
296 resourceRequest.setAttribute(WebKeys.TREE_NODE_ID, nodeId);
297 resourceRequest.setAttribute(WebKeys.TREE_OPEN_NODES, openNodes);
298 resourceRequest.setAttribute(
299 WebKeys.TREE_SELECTABLE_TREE, selectableTree);
300 resourceRequest.setAttribute(
301 WebKeys.TREE_SELECTED_NODES, selectedNodes);
302 resourceRequest.setAttribute(WebKeys.TREE_PORTLET_URL, portletURL);
303 resourceRequest.setAttribute(
304 WebKeys.TREE_RENDER_CHILDREN_ONLY, true);
305 }
306 else {
307 resourceId =
308 "/html/portlet/communities/scheduled_publishing_events.jsp";
309 }
310
311 PortletRequestDispatcher portletRequestDispatcher =
312 portletConfig.getPortletContext().getRequestDispatcher(resourceId);
313
314 portletRequestDispatcher.include(resourceRequest, resourceResponse);
315 }
316
317 protected void checkPermissions(PortletRequest portletRequest)
318 throws Exception {
319
320
322 ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
323 WebKeys.THEME_DISPLAY);
324
325 PermissionChecker permissionChecker =
326 themeDisplay.getPermissionChecker();
327
328 String tabs1 = ParamUtil.getString(portletRequest, "tabs1");
329
330 long groupId = ParamUtil.getLong(portletRequest, "groupId");
331 boolean privateLayout = tabs1.equals("private-pages");
332
333 Group group = GroupLocalServiceUtil.getGroup(groupId);
334
335 Layout layout = themeDisplay.getLayout();
336
337 boolean hasUpdateLayoutPermission = false;
338
339 if (layout != null) {
340 hasUpdateLayoutPermission = LayoutPermissionUtil.contains(
341 permissionChecker, layout.getGroupId(),
342 layout.isPrivateLayout(), layout.getLayoutId(),
343 ActionKeys.UPDATE);
344 }
345
346 if (group.isCommunity()) {
347 if (!GroupPermissionUtil.contains(
348 permissionChecker, group.getGroupId(),
349 ActionKeys.APPROVE_PROPOSAL) &&
350 !GroupPermissionUtil.contains(
351 permissionChecker, group.getGroupId(),
352 ActionKeys.MANAGE_LAYOUTS) &&
353 !hasUpdateLayoutPermission) {
354
355 throw new PrincipalException();
356 }
357 }
358 else if (group.isOrganization()) {
359 long organizationId = group.getClassPK();
360
361 if (!OrganizationPermissionUtil.contains(
362 permissionChecker, organizationId,
363 ActionKeys.APPROVE_PROPOSAL) &&
364 !OrganizationPermissionUtil.contains(
365 permissionChecker, organizationId,
366 ActionKeys.MANAGE_LAYOUTS) &&
367 !hasUpdateLayoutPermission) {
368
369 throw new PrincipalException();
370 }
371 }
372 else if (group.isUser()) {
373 long groupUserId = group.getClassPK();
374
375 User groupUser = UserLocalServiceUtil.getUserById(groupUserId);
376
377 long[] organizationIds = groupUser.getOrganizationIds();
378
379 UserPermissionUtil.check(
380 permissionChecker, groupUserId, organizationIds,
381 ActionKeys.UPDATE);
382
383 if ((privateLayout &&
384 !PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_MODIFIABLE) ||
385 (!privateLayout &&
386 !PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_MODIFIABLE)) {
387
388 throw new PrincipalException();
389 }
390 }
391 }
392
393 protected void copyPreferences(
394 ActionRequest actionRequest, Layout layout, Layout copyLayout)
395 throws Exception {
396
397 long companyId = layout.getCompanyId();
398
399 LayoutTypePortlet copyLayoutTypePortlet =
400 (LayoutTypePortlet)copyLayout.getLayoutType();
401
402 List<String> copyPortletIds = copyLayoutTypePortlet.getPortletIds();
403
404 for (String copyPortletId : copyPortletIds) {
405 HttpServletRequest request = PortalUtil.getHttpServletRequest(
406 actionRequest);
407
408
410 PortletPreferencesIds portletPreferencesIds =
411 PortletPreferencesFactoryUtil.getPortletPreferencesIds(
412 request, layout, copyPortletId);
413
414 PortletPreferencesLocalServiceUtil.getPreferences(
415 portletPreferencesIds);
416
417 PortletPreferencesIds copyPortletPreferencesIds =
418 PortletPreferencesFactoryUtil.getPortletPreferencesIds(
419 request, copyLayout, copyPortletId);
420
421 PortletPreferences copyPrefs =
422 PortletPreferencesLocalServiceUtil.getPreferences(
423 copyPortletPreferencesIds);
424
425 PortletPreferencesLocalServiceUtil.updatePreferences(
426 portletPreferencesIds.getOwnerId(),
427 portletPreferencesIds.getOwnerType(),
428 portletPreferencesIds.getPlid(),
429 portletPreferencesIds.getPortletId(), copyPrefs);
430
431
433 PortletPreferencesLocalServiceUtil.getPreferences(
434 companyId, PortletKeys.PREFS_OWNER_ID_DEFAULT,
435 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid(),
436 copyPortletId);
437
438 copyPrefs =
439 PortletPreferencesLocalServiceUtil.getPreferences(
440 companyId, PortletKeys.PREFS_OWNER_ID_DEFAULT,
441 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, copyLayout.getPlid(),
442 copyPortletId);
443
444 PortletPreferencesLocalServiceUtil.updatePreferences(
445 PortletKeys.PREFS_OWNER_ID_DEFAULT,
446 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid(),
447 copyPortletId, copyPrefs);
448 }
449 }
450
451 protected UnicodeProperties getTypeSettingsProperties(
452 ActionRequest actionRequest) {
453
454 return PropertiesParamUtil.getProperties(
455 actionRequest, "TypeSettingsProperties(");
456 }
457
458 protected void updateDisplayOrder(ActionRequest actionRequest)
459 throws Exception {
460
461 long groupId = ParamUtil.getLong(actionRequest, "groupId");
462 boolean privateLayout = ParamUtil.getBoolean(
463 actionRequest, "privateLayout");
464 long parentLayoutId = ParamUtil.getLong(
465 actionRequest, "parentLayoutId");
466 long[] layoutIds = StringUtil.split(
467 ParamUtil.getString(actionRequest, "layoutIds"), 0L);
468
469 LayoutServiceUtil.setLayouts(
470 groupId, privateLayout, parentLayoutId, layoutIds);
471 }
472
473 protected void updateLayout(
474 ActionRequest actionRequest, ActionResponse actionResponse)
475 throws Exception {
476
477 UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(
478 actionRequest);
479
480 String cmd = ParamUtil.getString(uploadRequest, Constants.CMD);
481
482 long groupId = ParamUtil.getLong(actionRequest, "groupId");
483 boolean privateLayout = ParamUtil.getBoolean(
484 actionRequest, "privateLayout");
485 long layoutId = ParamUtil.getLong(actionRequest, "layoutId");
486 long parentLayoutId = ParamUtil.getLong(
487 uploadRequest, "parentLayoutId");
488 String description = ParamUtil.getString(uploadRequest, "description");
489 String type = ParamUtil.getString(uploadRequest, "type");
490 boolean hidden = ParamUtil.getBoolean(uploadRequest, "hidden");
491 String friendlyURL = ParamUtil.getString(uploadRequest, "friendlyURL");
492 boolean iconImage = ParamUtil.getBoolean(uploadRequest, "iconImage");
493 byte[] iconBytes = FileUtil.getBytes(
494 uploadRequest.getFile("iconFileName"));
495
496 boolean inheritFromParentLayoutId = ParamUtil.getBoolean(
497 uploadRequest, "inheritFromParentLayoutId");
498
499 long copyLayoutId = ParamUtil.getLong(uploadRequest, "copyLayoutId");
500
501 Map<Locale, String> localeNamesMap =
502 LocalizationUtil.getLocalizedParameter(actionRequest, "name");
503 Map<Locale, String> localeTitlesMap =
504 LocalizationUtil.getLocalizedParameter(actionRequest, "title");
505
506 if (cmd.equals(Constants.ADD)) {
507
508
510 if (inheritFromParentLayoutId && (parentLayoutId > 0)) {
511 Layout parentLayout = LayoutLocalServiceUtil.getLayout(
512 groupId, privateLayout, parentLayoutId);
513
514 Layout layout = LayoutServiceUtil.addLayout(
515 groupId, privateLayout, parentLayoutId, localeNamesMap,
516 localeTitlesMap, description, parentLayout.getType(),
517 parentLayout.isHidden(), friendlyURL);
518
519 LayoutServiceUtil.updateLayout(
520 layout.getGroupId(), layout.isPrivateLayout(),
521 layout.getLayoutId(), parentLayout.getTypeSettings());
522
523 if (parentLayout.getType().equals(
524 LayoutConstants.TYPE_PORTLET)) {
525
526 copyPreferences(actionRequest, layout, parentLayout);
527 }
528 }
529 else {
530 LayoutServiceUtil.addLayout(
531 groupId, privateLayout, parentLayoutId, localeNamesMap,
532 localeTitlesMap, description, type, hidden, friendlyURL);
533 }
534 }
535 else {
536
537
539 Layout layout = LayoutLocalServiceUtil.getLayout(
540 groupId, privateLayout, layoutId);
541
542 layout = LayoutServiceUtil.updateLayout(
543 groupId, privateLayout, layoutId, layout.getParentLayoutId(),
544 localeNamesMap, localeTitlesMap, description, type, hidden,
545 friendlyURL, Boolean.valueOf(iconImage), iconBytes);
546
547 UnicodeProperties formTypeSettingsProperties =
548 getTypeSettingsProperties(actionRequest);
549
550 if (type.equals(LayoutConstants.TYPE_PORTLET)) {
551 if ((copyLayoutId > 0) &&
552 (copyLayoutId != layout.getLayoutId())) {
553
554 try {
555 Layout copyLayout = LayoutLocalServiceUtil.getLayout(
556 groupId, privateLayout, copyLayoutId);
557
558 if (copyLayout.getType().equals(
559 LayoutConstants.TYPE_PORTLET)) {
560
561 LayoutServiceUtil.updateLayout(
562 groupId, privateLayout, layoutId,
563 copyLayout.getTypeSettings());
564
565 copyPreferences(actionRequest, layout, copyLayout);
566 }
567 }
568 catch (NoSuchLayoutException nsle) {
569 }
570 }
571 else {
572 UnicodeProperties layoutTypeSettingsProperties =
573 layout.getTypeSettingsProperties();
574
575 for (String property: formTypeSettingsProperties.keySet()) {
576 layoutTypeSettingsProperties.setProperty(
577 property,
578 formTypeSettingsProperties.getProperty(property));
579 }
580
581 LayoutServiceUtil.updateLayout(
582 groupId, privateLayout, layoutId,
583 layout.getTypeSettings());
584 }
585 }
586 else {
587 layout.setTypeSettingsProperties(formTypeSettingsProperties);
588
589 LayoutServiceUtil.updateLayout(
590 groupId, privateLayout, layoutId, layout.getTypeSettings());
591 }
592
593 HttpServletResponse response = PortalUtil.getHttpServletResponse(
594 actionResponse);
595
596 String[] eventClasses = StringUtil.split(
597 PropsUtil.get(
598 PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE,
599 new Filter(type)));
600
601 EventsProcessorUtil.process(
602 PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE, eventClasses,
603 uploadRequest, response);
604 }
605 }
606
607 protected void updateLogo(ActionRequest actionRequest) throws Exception {
608 UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(
609 actionRequest);
610
611 long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
612 long stagingGroupId = ParamUtil.getLong(
613 actionRequest, "stagingGroupId");
614
615 boolean privateLayout = ParamUtil.getBoolean(
616 actionRequest, "privateLayout");
617 boolean logo = ParamUtil.getBoolean(actionRequest, "logo");
618
619 File file = uploadRequest.getFile("logoFileName");
620 byte[] bytes = FileUtil.getBytes(file);
621
622 if (logo && ((bytes == null) || (bytes.length == 0))) {
623 throw new UploadException();
624 }
625
626 LayoutSetServiceUtil.updateLogo(liveGroupId, privateLayout, logo, file);
627
628 if (stagingGroupId > 0) {
629 LayoutSetServiceUtil.updateLogo(
630 stagingGroupId, privateLayout, logo, file);
631 }
632 }
633
634 protected void updateLookAndFeel(ActionRequest actionRequest)
635 throws Exception {
636
637 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
638 WebKeys.THEME_DISPLAY);
639
640 long companyId = themeDisplay.getCompanyId();
641
642 long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
643 long stagingGroupId = ParamUtil.getLong(
644 actionRequest, "stagingGroupId");
645
646 boolean privateLayout = ParamUtil.getBoolean(
647 actionRequest, "privateLayout");
648 long layoutId = ParamUtil.getLong(actionRequest, "layoutId");
649 String themeId = ParamUtil.getString(actionRequest, "themeId");
650 String colorSchemeId = ParamUtil.getString(
651 actionRequest, "colorSchemeId");
652 String css = ParamUtil.getString(actionRequest, "css");
653 boolean wapTheme = ParamUtil.getBoolean(actionRequest, "wapTheme");
654
655 if (stagingGroupId > 0) {
656 updateLookAndFeel(
657 companyId, stagingGroupId, privateLayout, layoutId, themeId,
658 colorSchemeId, css, wapTheme);
659 }
660 else {
661 updateLookAndFeel(
662 companyId, liveGroupId, privateLayout, layoutId, themeId,
663 colorSchemeId, css, wapTheme);
664 }
665 }
666
667 protected void updateLookAndFeel(
668 long companyId, long groupId, boolean privateLayout, long layoutId,
669 String themeId, String colorSchemeId, String css, boolean wapTheme)
670 throws Exception {
671
672 if (Validator.isNotNull(themeId) && Validator.isNull(colorSchemeId)) {
673 ColorScheme colorScheme = ThemeLocalServiceUtil.getColorScheme(
674 companyId, themeId, colorSchemeId, wapTheme);
675
676 colorSchemeId = colorScheme.getColorSchemeId();
677 }
678
679 if (layoutId <= 0) {
680 LayoutSetServiceUtil.updateLookAndFeel(
681 groupId, privateLayout, themeId, colorSchemeId, css, wapTheme);
682 }
683 else {
684 LayoutServiceUtil.updateLookAndFeel(
685 groupId, privateLayout, layoutId, themeId, colorSchemeId, css,
686 wapTheme);
687 }
688 }
689
690 protected void updateMergePages(ActionRequest actionRequest)
691 throws Exception {
692
693 long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
694
695 boolean mergeGuestPublicPages = ParamUtil.getBoolean(
696 actionRequest, "mergeGuestPublicPages");
697
698 Group liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);
699
700 UnicodeProperties props = liveGroup.getTypeSettingsProperties();
701
702 props.setProperty(
703 "mergeGuestPublicPages", String.valueOf(mergeGuestPublicPages));
704
705 GroupServiceUtil.updateGroup(liveGroupId, liveGroup.getTypeSettings());
706 }
707
708 protected void updateMonitoring(ActionRequest actionRequest)
709 throws Exception {
710
711 long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
712
713 String googleAnalyticsId = ParamUtil.getString(
714 actionRequest, "googleAnalyticsId");
715
716 Group liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);
717
718 UnicodeProperties props = liveGroup.getTypeSettingsProperties();
719
720 props.setProperty("googleAnalyticsId", googleAnalyticsId);
721
722 GroupServiceUtil.updateGroup(liveGroupId, liveGroup.getTypeSettings());
723 }
724
725 protected void updateVirtualHost(ActionRequest actionRequest)
726 throws Exception {
727
728 long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
729
730 String publicVirtualHost = ParamUtil.getString(
731 actionRequest, "publicVirtualHost");
732 String privateVirtualHost = ParamUtil.getString(
733 actionRequest, "privateVirtualHost");
734 String friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL");
735
736 LayoutSetServiceUtil.updateVirtualHost(
737 liveGroupId, false, publicVirtualHost);
738
739 LayoutSetServiceUtil.updateVirtualHost(
740 liveGroupId, true, privateVirtualHost);
741
742 GroupServiceUtil.updateFriendlyURL(liveGroupId, friendlyURL);
743
744 Group liveGroup = GroupServiceUtil.getGroup(liveGroupId);
745
746 if (liveGroup.hasStagingGroup()) {
747 Group stagingGroup = liveGroup.getStagingGroup();
748
749 publicVirtualHost = ParamUtil.getString(
750 actionRequest, "stagingPublicVirtualHost");
751 privateVirtualHost = ParamUtil.getString(
752 actionRequest, "stagingPrivateVirtualHost");
753 friendlyURL = ParamUtil.getString(
754 actionRequest, "stagingFriendlyURL");
755
756 LayoutSetServiceUtil.updateVirtualHost(
757 stagingGroup.getGroupId(), false, publicVirtualHost);
758
759 LayoutSetServiceUtil.updateVirtualHost(
760 stagingGroup.getGroupId(), true, privateVirtualHost);
761
762 GroupServiceUtil.updateFriendlyURL(
763 stagingGroup.getGroupId(), friendlyURL);
764 }
765 }
766
767 protected void updateWorkflow(ActionRequest actionRequest)
768 throws Exception {
769
770 long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
771
772 boolean workflowEnabled = ParamUtil.getBoolean(
773 actionRequest, "workflowEnabled");
774 int workflowStages = ParamUtil.getInteger(
775 actionRequest, "workflowStages");
776
777 StringBuilder sb = new StringBuilder();
778
779 for (int i = 1; i <= workflowStages; i++) {
780 String workflowRoleName = ParamUtil.getString(
781 actionRequest, "workflowRoleName_" + i);
782
783 sb.append(workflowRoleName);
784
785 if ((i + 1) <= workflowStages) {
786 sb.append(",");
787 }
788 }
789
790 String workflowRoleNames = sb.toString();
791
792 GroupServiceUtil.updateWorkflow(
793 liveGroupId, workflowEnabled, workflowStages, workflowRoleNames);
794 }
795
796 }