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.backgroundtask;
016    
017    import com.liferay.portal.kernel.backgroundtask.BackgroundTaskResult;
018    import com.liferay.portal.kernel.util.MapUtil;
019    import com.liferay.portal.model.BackgroundTask;
020    import com.liferay.portal.service.BackgroundTaskLocalServiceUtil;
021    import com.liferay.portlet.exportimport.model.ExportImportConfiguration;
022    import com.liferay.portlet.exportimport.service.ExportImportLocalServiceUtil;
023    
024    import java.io.File;
025    import java.io.Serializable;
026    
027    import java.util.Map;
028    
029    /**
030     * @author Daniel Kocsis
031     * @author Michael C. Han
032     * @author Akos Thurzo
033     */
034    public class PortletExportBackgroundTaskExecutor
035            extends BaseExportImportBackgroundTaskExecutor {
036    
037            public PortletExportBackgroundTaskExecutor() {
038                    setBackgroundTaskStatusMessageTranslator(
039                            new PortletExportImportBackgroundTaskStatusMessageTranslator());
040            }
041    
042            @Override
043            public BackgroundTaskResult execute(BackgroundTask backgroundTask)
044                    throws Exception {
045    
046                    ExportImportConfiguration exportImportConfiguration =
047                            getExportImportConfiguration(backgroundTask);
048    
049                    Map<String, Serializable> settingsMap =
050                            exportImportConfiguration.getSettingsMap();
051    
052                    long userId = MapUtil.getLong(settingsMap, "userId");
053                    String fileName = MapUtil.getString(settingsMap, "fileName");
054    
055                    File larFile = ExportImportLocalServiceUtil.exportPortletInfoAsFile(
056                            exportImportConfiguration);
057    
058                    BackgroundTaskLocalServiceUtil.addBackgroundTaskAttachment(
059                            userId, backgroundTask.getBackgroundTaskId(), fileName, larFile);
060    
061                    return BackgroundTaskResult.SUCCESS;
062            }
063    
064    }