001
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
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 }