1
14
15 package com.liferay.portlet.journalcontent.action;
16
17 import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
18 import com.liferay.portal.kernel.servlet.SessionErrors;
19 import com.liferay.portal.kernel.servlet.SessionMessages;
20 import com.liferay.portal.kernel.util.Constants;
21 import com.liferay.portal.kernel.util.ParamUtil;
22 import com.liferay.portal.model.Layout;
23 import com.liferay.portal.theme.ThemeDisplay;
24 import com.liferay.portal.util.WebKeys;
25 import com.liferay.portlet.PortletPreferencesFactoryUtil;
26 import com.liferay.portlet.journal.service.JournalContentSearchLocalServiceUtil;
27
28 import javax.portlet.ActionRequest;
29 import javax.portlet.ActionResponse;
30 import javax.portlet.PortletConfig;
31 import javax.portlet.PortletPreferences;
32 import javax.portlet.RenderRequest;
33 import javax.portlet.RenderResponse;
34
35
40 public class ConfigurationActionImpl extends BaseConfigurationAction {
41
42 public void processAction(
43 PortletConfig portletConfig, ActionRequest actionRequest,
44 ActionResponse actionResponse)
45 throws Exception {
46
47 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
48
49 if (!cmd.equals(Constants.UPDATE)) {
50 return;
51 }
52
53 long groupId = ParamUtil.getLong(actionRequest, "groupId");
54 String articleId = ParamUtil.getString(
55 actionRequest, "articleId").toUpperCase();
56 String templateId = ParamUtil.getString(
57 actionRequest, "templateId").toUpperCase();
58 boolean showAvailableLocales = ParamUtil.getBoolean(
59 actionRequest, "showAvailableLocales");
60 boolean enableRatings = ParamUtil.getBoolean(
61 actionRequest, "enableRatings");
62 boolean enableComments = ParamUtil.getBoolean(
63 actionRequest, "enableComments");
64 boolean enableCommentRatings = ParamUtil.getBoolean(
65 actionRequest, "enableCommentRatings");
66
67 String portletResource = ParamUtil.getString(
68 actionRequest, "portletResource");
69
70 PortletPreferences preferences =
71 PortletPreferencesFactoryUtil.getPortletSetup(
72 actionRequest, portletResource);
73
74 preferences.setValue("group-id", String.valueOf(groupId));
75 preferences.setValue("article-id", articleId);
76 preferences.setValue("template-id", templateId);
77 preferences.setValue(
78 "show-available-locales", String.valueOf(showAvailableLocales));
79 preferences.setValue("enable-ratings", String.valueOf(enableRatings));
80 preferences.setValue("enable-comments", String.valueOf(enableComments));
81 preferences.setValue(
82 "enable-comment-ratings", String.valueOf(enableCommentRatings));
83
84 if (SessionErrors.isEmpty(actionRequest)) {
85 preferences.store();
86
87 updateContentSearch(actionRequest, portletResource, articleId);
88
89 SessionMessages.add(
90 actionRequest, portletConfig.getPortletName() + ".doConfigure");
91 }
92
93 actionResponse.sendRedirect(
94 ParamUtil.getString(actionRequest, "redirect"));
95 }
96
97 public String render(
98 PortletConfig portletConfig, RenderRequest renderRequest,
99 RenderResponse renderResponse)
100 throws Exception {
101
102 return "/html/portlet/journal_content/configuration.jsp";
103 }
104
105 protected void updateContentSearch(
106 ActionRequest actionRequest, String portletResource,
107 String articleId)
108 throws Exception {
109
110 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
111 WebKeys.THEME_DISPLAY);
112
113 Layout layout = themeDisplay.getLayout();
114
115 JournalContentSearchLocalServiceUtil.updateContentSearch(
116 layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
117 portletResource, articleId, true);
118 }
119
120 }