001
014
015 package com.liferay.portlet.exportimport.lifecycle;
016
017 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_LAYOUT_EXPORT_FAILED;
018 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_LAYOUT_EXPORT_STARTED;
019 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_LAYOUT_EXPORT_SUCCEEDED;
020 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_LAYOUT_IMPORT_FAILED;
021 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_LAYOUT_IMPORT_STARTED;
022 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_LAYOUT_IMPORT_SUCCEEDED;
023 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_PORTLET_EXPORT_FAILED;
024 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_PORTLET_EXPORT_STARTED;
025 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_PORTLET_EXPORT_SUCCEEDED;
026 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_PORTLET_IMPORT_FAILED;
027 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_PORTLET_IMPORT_STARTED;
028 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_PORTLET_IMPORT_SUCCEEDED;
029 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_PUBLICATION_LAYOUT_LOCAL_FAILED;
030 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_PUBLICATION_LAYOUT_LOCAL_STARTED;
031 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_PUBLICATION_LAYOUT_LOCAL_SUCCEEDED;
032 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_PUBLICATION_LAYOUT_REMOTE_FAILED;
033 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_PUBLICATION_LAYOUT_REMOTE_STARTED;
034 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_PUBLICATION_LAYOUT_REMOTE_SUCCEEDED;
035 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_PUBLICATION_PORTLET_LOCAL_FAILED;
036 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_PUBLICATION_PORTLET_LOCAL_STARTED;
037 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_PUBLICATION_PORTLET_LOCAL_SUCCEEDED;
038 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_STAGED_MODEL_EXPORT_FAILED;
039 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_STAGED_MODEL_EXPORT_STARTED;
040 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_STAGED_MODEL_EXPORT_SUCCEEDED;
041 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_STAGED_MODEL_IMPORT_FAILED;
042 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_STAGED_MODEL_IMPORT_STARTED;
043 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.EVENT_STAGED_MODEL_IMPORT_SUCCEEDED;
044 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.PROCESS_FLAG_LAYOUT_IMPORT_IN_PROCESS;
045 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.PROCESS_FLAG_LAYOUT_STAGING_IN_PROCESS;
046 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.PROCESS_FLAG_PORTLET_IMPORT_IN_PROCESS;
047 import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.PROCESS_FLAG_PORTLET_STAGING_IN_PROCESS;
048
049 import com.liferay.portal.kernel.util.TransientValue;
050 import com.liferay.portal.model.StagedModel;
051 import com.liferay.portlet.exportimport.lar.PortletDataContext;
052 import com.liferay.portlet.exportimport.model.ExportImportConfiguration;
053
054 import java.io.Serializable;
055
056 import java.util.List;
057
058
062 public abstract class BaseExportImportLifecycleListener
063 implements ExportImportLifecycleListener {
064
065 @Override
066 public abstract boolean isParallel();
067
068 @Override
069 public void onExportImportLifecycleEvent(
070 ExportImportLifecycleEvent exportImportLifecycleEvent)
071 throws Exception {
072
073 List<Serializable> attributes =
074 exportImportLifecycleEvent.getAttributes();
075
076 int code = exportImportLifecycleEvent.getCode();
077 int processFlag = exportImportLifecycleEvent.getProcessFlag();
078
079 if (code == EVENT_LAYOUT_EXPORT_FAILED) {
080 onLayoutExportFailed(
081 getPortletDataContextAttribute(attributes),
082 getThrowableAttribute(attributes));
083 }
084 else if (code == EVENT_LAYOUT_EXPORT_STARTED) {
085 onLayoutExportStarted(getPortletDataContextAttribute(attributes));
086 }
087 else if (code == EVENT_LAYOUT_EXPORT_SUCCEEDED) {
088 onLayoutExportSucceeded(getPortletDataContextAttribute(attributes));
089 }
090 else if (code == EVENT_LAYOUT_IMPORT_FAILED) {
091 onLayoutImportFailed(
092 getPortletDataContextAttribute(attributes),
093 getThrowableAttribute(attributes));
094 }
095 else if (code == EVENT_LAYOUT_IMPORT_STARTED) {
096 onLayoutImportStarted(getPortletDataContextAttribute(attributes));
097 }
098 else if (code == EVENT_LAYOUT_IMPORT_SUCCEEDED) {
099 if ((processFlag == PROCESS_FLAG_LAYOUT_IMPORT_IN_PROCESS) ||
100 (processFlag == PROCESS_FLAG_LAYOUT_STAGING_IN_PROCESS)) {
101
102 onLayoutImportProcessFinished(
103 getPortletDataContextAttribute(attributes));
104 }
105 else {
106 onLayoutImportSucceeded(
107 getPortletDataContextAttribute(attributes));
108 }
109 }
110 else if (code == EVENT_PORTLET_EXPORT_FAILED) {
111 onPortletExportFailed(
112 getPortletDataContextAttribute(attributes),
113 getThrowableAttribute(attributes));
114 }
115 else if (code == EVENT_PORTLET_EXPORT_STARTED) {
116 onPortletExportStarted(getPortletDataContextAttribute(attributes));
117 }
118 else if (code == EVENT_PORTLET_EXPORT_SUCCEEDED) {
119 onPortletExportSucceeded(
120 getPortletDataContextAttribute(attributes));
121 }
122 else if (code == EVENT_PORTLET_IMPORT_FAILED) {
123 onPortletImportFailed(
124 getPortletDataContextAttribute(attributes),
125 getThrowableAttribute(attributes));
126 }
127 else if (code == EVENT_PORTLET_IMPORT_STARTED) {
128 onPortletImportStarted(getPortletDataContextAttribute(attributes));
129 }
130 else if (code == EVENT_PORTLET_IMPORT_SUCCEEDED) {
131 if ((processFlag == PROCESS_FLAG_PORTLET_IMPORT_IN_PROCESS) ||
132 (processFlag == PROCESS_FLAG_PORTLET_STAGING_IN_PROCESS)) {
133
134 onPortletImportProcessFinished(
135 getPortletDataContextAttribute(attributes));
136 }
137 else {
138 onPortletImportSucceeded(
139 getPortletDataContextAttribute(attributes));
140 }
141 }
142 else if (code == EVENT_PUBLICATION_LAYOUT_LOCAL_FAILED) {
143 onLayoutLocalPublicationFailed(
144 getExportImportConfigurationAttribute(attributes),
145 getThrowableAttribute(attributes));
146 }
147 else if (code == EVENT_PUBLICATION_LAYOUT_LOCAL_STARTED) {
148 onLayoutLocalPublicationStarted(
149 getExportImportConfigurationAttribute(attributes));
150 }
151 else if (code == EVENT_PUBLICATION_LAYOUT_LOCAL_SUCCEEDED) {
152 onLayoutLocalPublicationSucceeded(
153 getExportImportConfigurationAttribute(attributes));
154 }
155 else if (code == EVENT_PUBLICATION_LAYOUT_REMOTE_FAILED) {
156 onLayoutRemotePublicationFailed(
157 getExportImportConfigurationAttribute(attributes),
158 getThrowableAttribute(attributes));
159 }
160 else if (code == EVENT_PUBLICATION_LAYOUT_REMOTE_STARTED) {
161 onLayoutRemotePublicationStarted(
162 getExportImportConfigurationAttribute(attributes));
163 }
164 else if (code == EVENT_PUBLICATION_LAYOUT_REMOTE_SUCCEEDED) {
165 onLayoutRemotePublicationSucceeded(
166 getExportImportConfigurationAttribute(attributes));
167 }
168 else if (code == EVENT_PUBLICATION_PORTLET_LOCAL_FAILED) {
169 onPortletPublicationFailed(
170 getExportImportConfigurationAttribute(attributes),
171 getThrowableAttribute(attributes));
172 }
173 else if (code == EVENT_PUBLICATION_PORTLET_LOCAL_STARTED) {
174 onPortletPublicationStarted(
175 getExportImportConfigurationAttribute(attributes));
176 }
177 else if (code == EVENT_PUBLICATION_PORTLET_LOCAL_SUCCEEDED) {
178 onPortletPublicationSucceeded(
179 getExportImportConfigurationAttribute(attributes));
180 }
181 else if (code == EVENT_STAGED_MODEL_EXPORT_FAILED) {
182 onStagedModelExportFailed(
183 getPortletDataContextAttribute(attributes),
184 getStagedModelAttribute(attributes),
185 getThrowableAttribute(attributes));
186 }
187 else if (code == EVENT_STAGED_MODEL_EXPORT_STARTED) {
188 onStagedModelExportStarted(
189 getPortletDataContextAttribute(attributes),
190 getStagedModelAttribute(attributes));
191 }
192 else if (code == EVENT_STAGED_MODEL_EXPORT_SUCCEEDED) {
193 onStagedModelExportSucceeded(
194 getPortletDataContextAttribute(attributes),
195 getStagedModelAttribute(attributes));
196 }
197 else if (code == EVENT_STAGED_MODEL_IMPORT_FAILED) {
198 onStagedModelImportFailed(
199 getPortletDataContextAttribute(attributes),
200 getStagedModelAttribute(attributes),
201 getThrowableAttribute(attributes));
202 }
203 else if (code == EVENT_STAGED_MODEL_IMPORT_STARTED) {
204 onStagedModelImportStarted(
205 getPortletDataContextAttribute(attributes),
206 getStagedModelAttribute(attributes));
207 }
208 else if (code == EVENT_STAGED_MODEL_IMPORT_SUCCEEDED) {
209 onStagedModelImportSucceeded(
210 getPortletDataContextAttribute(attributes),
211 getStagedModelAttribute(attributes));
212 }
213 }
214
215 protected <T> T getAttributeByType(
216 List<Serializable> attributes, Class<T> clazz) {
217
218 for (Serializable attribute : attributes) {
219 if (clazz.isInstance(attribute)) {
220 return clazz.cast(attribute);
221 }
222 }
223
224 return null;
225 }
226
227 protected ExportImportConfiguration getExportImportConfigurationAttribute(
228 List<Serializable> attributes) {
229
230 return getAttributeByType(attributes, ExportImportConfiguration.class);
231 }
232
233 protected PortletDataContext getPortletDataContextAttribute(
234 List<Serializable> attributes) {
235
236 return getAttributeByType(attributes, PortletDataContext.class);
237 }
238
239 protected StagedModel getStagedModelAttribute(
240 List<Serializable> attributes) {
241
242 TransientValue<Object> transientValue = getAttributeByType(
243 attributes, TransientValue.class);
244
245 Object value = transientValue.getValue();
246
247 if (value instanceof StagedModel) {
248 return (StagedModel)value;
249 }
250
251 return null;
252 }
253
254 protected Throwable getThrowableAttribute(List<Serializable> attributes) {
255 return getAttributeByType(attributes, Throwable.class);
256 }
257
258 protected void onLayoutExportFailed(
259 PortletDataContext portletDataContext, Throwable throwable)
260 throws Exception {
261 }
262
263 protected void onLayoutExportStarted(PortletDataContext portletDataContext)
264 throws Exception {
265 }
266
267 protected void onLayoutExportSucceeded(
268 PortletDataContext portletDataContext)
269 throws Exception {
270 }
271
272 protected void onLayoutImportFailed(
273 PortletDataContext portletDataContext, Throwable throwable)
274 throws Exception {
275 }
276
277 protected void onLayoutImportProcessFinished(
278 PortletDataContext portletDataContext)
279 throws Exception {
280 }
281
282 protected void onLayoutImportStarted(PortletDataContext portletDataContext)
283 throws Exception {
284 }
285
286 protected void onLayoutImportSucceeded(
287 PortletDataContext portletDataContext)
288 throws Exception {
289 }
290
291 protected void onLayoutLocalPublicationFailed(
292 ExportImportConfiguration exportImportConfiguration,
293 Throwable throwable)
294 throws Exception {
295 }
296
297 protected void onLayoutLocalPublicationStarted(
298 ExportImportConfiguration exportImportConfiguration)
299 throws Exception {
300 }
301
302 protected void onLayoutLocalPublicationSucceeded(
303 ExportImportConfiguration exportImportConfiguration)
304 throws Exception {
305 }
306
307 protected void onLayoutRemotePublicationFailed(
308 ExportImportConfiguration exportImportConfiguration,
309 Throwable throwable)
310 throws Exception {
311 }
312
313 protected void onLayoutRemotePublicationStarted(
314 ExportImportConfiguration exportImportConfiguration)
315 throws Exception {
316 }
317
318 protected void onLayoutRemotePublicationSucceeded(
319 ExportImportConfiguration exportImportConfiguration)
320 throws Exception {
321 }
322
323 protected void onPortletExportFailed(
324 PortletDataContext portletDataContext, Throwable throwable)
325 throws Exception {
326 }
327
328 protected void onPortletExportStarted(PortletDataContext portletDataContext)
329 throws Exception {
330 }
331
332 protected void onPortletExportSucceeded(
333 PortletDataContext portletDataContext)
334 throws Exception {
335 }
336
337 protected void onPortletImportFailed(
338 PortletDataContext portletDataContext, Throwable throwable)
339 throws Exception {
340 }
341
342 protected void onPortletImportProcessFinished(
343 PortletDataContext portletDataContext)
344 throws Exception {
345 }
346
347 protected void onPortletImportStarted(PortletDataContext portletDataContext)
348 throws Exception {
349 }
350
351 protected void onPortletImportSucceeded(
352 PortletDataContext portletDataContext)
353 throws Exception {
354 }
355
356 protected void onPortletPublicationFailed(
357 ExportImportConfiguration exportImportConfiguration,
358 Throwable throwable)
359 throws Exception {
360 }
361
362 protected void onPortletPublicationStarted(
363 ExportImportConfiguration exportImportConfiguration)
364 throws Exception {
365 }
366
367 protected void onPortletPublicationSucceeded(
368 ExportImportConfiguration exportImportConfiguration)
369 throws Exception {
370 }
371
372 protected void onStagedModelExportFailed(
373 PortletDataContext portletDataContext, StagedModel stagedModel,
374 Throwable throwable)
375 throws Exception {
376 }
377
378 protected void onStagedModelExportStarted(
379 PortletDataContext portletDataContext, StagedModel stagedModel)
380 throws Exception {
381 }
382
383 protected void onStagedModelExportSucceeded(
384 PortletDataContext portletDataContext, StagedModel stagedModel)
385 throws Exception {
386 }
387
388 protected void onStagedModelImportFailed(
389 PortletDataContext portletDataContext, StagedModel stagedModel,
390 Throwable throwable)
391 throws Exception {
392 }
393
394 protected void onStagedModelImportStarted(
395 PortletDataContext portletDataContext, StagedModel stagedModel)
396 throws Exception {
397 }
398
399 protected void onStagedModelImportSucceeded(
400 PortletDataContext portletDataContext, StagedModel stagedModel)
401 throws Exception {
402 }
403
404 }