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