001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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.PROCESS_FLAG_LAYOUT_EXPORT_IN_PROCESS;
039    import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.PROCESS_FLAG_LAYOUT_IMPORT_IN_PROCESS;
040    import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.PROCESS_FLAG_LAYOUT_STAGING_IN_PROCESS;
041    import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.PROCESS_FLAG_PORTLET_EXPORT_IN_PROCESS;
042    import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.PROCESS_FLAG_PORTLET_IMPORT_IN_PROCESS;
043    import static com.liferay.portlet.exportimport.lifecycle.ExportImportLifecycleConstants.PROCESS_FLAG_PORTLET_STAGING_IN_PROCESS;
044    
045    import java.io.Serializable;
046    
047    import java.util.List;
048    
049    /**
050     * @author Daniel Kocsis
051     */
052    public abstract class BaseProcessExportImportLifecycleListener
053            implements ExportImportLifecycleListener {
054    
055            @Override
056            public abstract boolean isParallel();
057    
058            @Override
059            public void onExportImportLifecycleEvent(
060                            ExportImportLifecycleEvent exportImportLifecycleEvent)
061                    throws Exception {
062    
063                    int code = exportImportLifecycleEvent.getCode();
064                    int processFlag = exportImportLifecycleEvent.getProcessFlag();
065    
066                    if (processFlag == PROCESS_FLAG_LAYOUT_EXPORT_IN_PROCESS) {
067                            if (code == EVENT_LAYOUT_EXPORT_FAILED) {
068                                    onProcessFailed(exportImportLifecycleEvent.getAttributes());
069                            }
070                            else if (code == EVENT_LAYOUT_EXPORT_STARTED) {
071                                    onProcessStarted(exportImportLifecycleEvent.getAttributes());
072                            }
073                            else if (code == EVENT_LAYOUT_EXPORT_SUCCEEDED) {
074                                    onProcessSucceeded(exportImportLifecycleEvent.getAttributes());
075                            }
076                    }
077                    else if (processFlag == PROCESS_FLAG_LAYOUT_IMPORT_IN_PROCESS) {
078                            if (code == EVENT_LAYOUT_IMPORT_FAILED) {
079                                    onProcessFailed(exportImportLifecycleEvent.getAttributes());
080                            }
081                            else if (code == EVENT_LAYOUT_IMPORT_STARTED) {
082                                    onProcessStarted(exportImportLifecycleEvent.getAttributes());
083                            }
084                            else if (code == EVENT_LAYOUT_IMPORT_SUCCEEDED) {
085                                    onProcessSucceeded(exportImportLifecycleEvent.getAttributes());
086                            }
087                    }
088                    else if (processFlag == PROCESS_FLAG_LAYOUT_STAGING_IN_PROCESS) {
089                            if ((code == EVENT_PUBLICATION_LAYOUT_LOCAL_FAILED) ||
090                                    (code == EVENT_PUBLICATION_LAYOUT_REMOTE_FAILED)) {
091    
092                                    onProcessFailed(exportImportLifecycleEvent.getAttributes());
093                            }
094                            else if ((code == EVENT_PUBLICATION_LAYOUT_LOCAL_STARTED) ||
095                                             (code == EVENT_PUBLICATION_LAYOUT_REMOTE_STARTED)) {
096    
097                                    onProcessStarted(exportImportLifecycleEvent.getAttributes());
098                            }
099                            else if ((code == EVENT_PUBLICATION_LAYOUT_LOCAL_SUCCEEDED) ||
100                                             (code == EVENT_PUBLICATION_LAYOUT_REMOTE_SUCCEEDED)) {
101    
102                                    onProcessSucceeded(exportImportLifecycleEvent.getAttributes());
103                            }
104                    }
105                    else if (processFlag == PROCESS_FLAG_PORTLET_EXPORT_IN_PROCESS) {
106                            if (code == EVENT_PORTLET_EXPORT_FAILED) {
107                                    onProcessFailed(exportImportLifecycleEvent.getAttributes());
108                            }
109                            else if (code == EVENT_PORTLET_EXPORT_STARTED) {
110                                    onProcessStarted(exportImportLifecycleEvent.getAttributes());
111                            }
112                            else if (code == EVENT_PORTLET_EXPORT_SUCCEEDED) {
113                                    onProcessSucceeded(exportImportLifecycleEvent.getAttributes());
114                            }
115                    }
116                    else if (processFlag == PROCESS_FLAG_PORTLET_IMPORT_IN_PROCESS) {
117                            if (code == EVENT_PORTLET_IMPORT_FAILED) {
118                                    onProcessFailed(exportImportLifecycleEvent.getAttributes());
119                            }
120                            else if (code == EVENT_PORTLET_IMPORT_STARTED) {
121                                    onProcessStarted(exportImportLifecycleEvent.getAttributes());
122                            }
123                            else if (code == EVENT_PORTLET_IMPORT_SUCCEEDED) {
124                                    onProcessSucceeded(exportImportLifecycleEvent.getAttributes());
125                            }
126                    }
127                    else if (processFlag == PROCESS_FLAG_PORTLET_STAGING_IN_PROCESS) {
128                            if (code == EVENT_PUBLICATION_PORTLET_LOCAL_FAILED) {
129                                    onProcessFailed(exportImportLifecycleEvent.getAttributes());
130                            }
131                            else if (code == EVENT_PUBLICATION_PORTLET_LOCAL_STARTED) {
132                                    onProcessStarted(exportImportLifecycleEvent.getAttributes());
133                            }
134                            else if (code == EVENT_PUBLICATION_PORTLET_LOCAL_SUCCEEDED) {
135                                    onProcessSucceeded(exportImportLifecycleEvent.getAttributes());
136                            }
137                    }
138            }
139    
140            protected void onProcessFailed(List<Serializable> attributes)
141                    throws Exception {
142            }
143    
144            protected void onProcessStarted(List<Serializable> attributes)
145                    throws Exception {
146            }
147    
148            protected void onProcessSucceeded(List<Serializable> attributes)
149                    throws Exception {
150            }
151    
152    }