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.portal.model;
016    
017    import com.liferay.portal.ModelListenerException;
018    import com.liferay.portal.kernel.util.MapUtil;
019    import com.liferay.portal.kernel.workflow.WorkflowConstants;
020    import com.liferay.portlet.exportimport.model.ExportImportConfiguration;
021    import com.liferay.portlet.exportimport.service.ExportImportConfigurationLocalServiceUtil;
022    
023    import java.io.Serializable;
024    
025    import java.util.Map;
026    
027    /**
028     * @author Levente Hud??k
029     */
030    public class BackgroundTaskModelListener
031            extends BaseModelListener<BackgroundTask> {
032    
033            @Override
034            public void onBeforeRemove(BackgroundTask backgroundTask)
035                    throws ModelListenerException {
036    
037                    Map<String, Serializable> taskContextMap =
038                            backgroundTask.getTaskContextMap();
039    
040                    long exportImportConfigurationId = MapUtil.getLong(
041                            taskContextMap, "exportImportConfigurationId");
042    
043                    if (exportImportConfigurationId == 0) {
044                            return;
045                    }
046    
047                    try {
048                            ExportImportConfiguration exportImportConfiguration =
049                                    ExportImportConfigurationLocalServiceUtil.
050                                            getExportImportConfiguration(exportImportConfigurationId);
051    
052                            if (exportImportConfiguration.getStatus() ==
053                                            WorkflowConstants.STATUS_DRAFT) {
054    
055                                    ExportImportConfigurationLocalServiceUtil.
056                                            deleteExportImportConfiguration(exportImportConfiguration);
057                            }
058                    }
059                    catch (Exception e) {
060                            throw new ModelListenerException(e);
061                    }
062            }
063    
064    }