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