001
014
015 package com.liferay.portlet.journalcontent.action;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.portlet.DefaultConfigurationAction;
020 import com.liferay.portal.kernel.portlet.PortletLayoutListener;
021 import com.liferay.portal.kernel.servlet.SessionErrors;
022 import com.liferay.portal.kernel.transaction.Isolation;
023 import com.liferay.portal.kernel.transaction.Propagation;
024 import com.liferay.portal.kernel.transaction.Transactional;
025 import com.liferay.portal.kernel.util.ParamUtil;
026 import com.liferay.portal.kernel.util.ServiceBeanMethodInvocationFactoryUtil;
027 import com.liferay.portal.kernel.util.Validator;
028 import com.liferay.portal.model.Layout;
029 import com.liferay.portal.model.Portlet;
030 import com.liferay.portal.service.PortletLocalServiceUtil;
031 import com.liferay.portal.theme.ThemeDisplay;
032 import com.liferay.portal.util.WebKeys;
033
034 import java.lang.reflect.Method;
035
036 import javax.portlet.ActionRequest;
037 import javax.portlet.ActionResponse;
038 import javax.portlet.PortletConfig;
039 import javax.portlet.PortletPreferences;
040 import javax.portlet.PortletRequest;
041
042
047 public class ConfigurationActionImpl extends DefaultConfigurationAction {
048
049 public ConfigurationActionImpl() {
050 try {
051 Class<?> clazz = getClass();
052
053 _doProcessActionMethod = clazz.getDeclaredMethod(
054 "doProcessAction",
055 new Class<?>[] {
056 PortletConfig.class, ActionRequest.class,
057 ActionResponse.class
058 });
059 }
060 catch (Exception e) {
061 _log.error(e, e);
062 }
063 }
064
065 @Override
066 public void processAction(
067 PortletConfig portletConfig, ActionRequest actionRequest,
068 ActionResponse actionResponse)
069 throws Exception {
070
071
072
073
074 ServiceBeanMethodInvocationFactoryUtil.proceed(
075 this, ConfigurationActionImpl.class, _doProcessActionMethod,
076 new Object[] {portletConfig, actionRequest, actionResponse},
077 new String[] {"transactionAdvice"});
078 }
079
080
085 @Transactional(
086 isolation = Isolation.PORTAL, propagation = Propagation.REQUIRES_NEW,
087 rollbackFor = {Exception.class}
088 )
089 protected void doProcessAction(
090 PortletConfig portletConfig, ActionRequest actionRequest,
091 ActionResponse actionResponse)
092 throws Exception {
093
094 String[] extensions = actionRequest.getParameterValues("extensions");
095
096 setPreference(actionRequest, "extensions", extensions);
097
098 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
099 WebKeys.THEME_DISPLAY);
100
101 Layout layout = themeDisplay.getLayout();
102
103 String portletResource = ParamUtil.getString(
104 actionRequest, "portletResource");
105
106 PortletPreferences preferences = actionRequest.getPreferences();
107
108 String articleId = getArticleId(actionRequest);
109
110 String originalArticleId = preferences.getValue("articleId", null);
111
112 Portlet portlet = PortletLocalServiceUtil.getPortletById(
113 themeDisplay.getCompanyId(), portletResource);
114
115 PortletLayoutListener portletLayoutListener =
116 portlet.getPortletLayoutListenerInstance();
117
118 if ((portletLayoutListener != null) &&
119 Validator.isNotNull(originalArticleId) &&
120 !originalArticleId.equals(articleId)) {
121
122
123
124 portletLayoutListener.onRemoveFromLayout(
125 portletResource, layout.getPlid());
126 }
127
128
129
130 super.processAction(portletConfig, actionRequest, actionResponse);
131
132 if (SessionErrors.isEmpty(actionRequest) &&
133 (portletLayoutListener != null)) {
134
135
136
137 portletLayoutListener.onAddToLayout(
138 portletResource, layout.getPlid());
139 }
140 }
141
142 protected String getArticleId(PortletRequest portletRequest) {
143 String articleId = getParameter(portletRequest, "articleId");
144
145 return articleId.toUpperCase();
146 }
147
148 private static Log _log = LogFactoryUtil.getLog(
149 ConfigurationActionImpl.class);
150
151 private Method _doProcessActionMethod;
152
153 }