001    /**
002     * Copyright (c) 2000-2013 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.lar.backgroundtask;
016    
017    import com.liferay.portal.kernel.backgroundtask.BackgroundTaskResult;
018    import com.liferay.portal.kernel.backgroundtask.BaseBackgroundTaskExecutor;
019    import com.liferay.portal.kernel.util.MapUtil;
020    import com.liferay.portal.model.BackgroundTask;
021    import com.liferay.portal.service.BackgroundTaskLocalServiceUtil;
022    import com.liferay.portal.service.LayoutLocalServiceUtil;
023    
024    import java.io.File;
025    import java.io.Serializable;
026    
027    import java.util.Date;
028    import java.util.Map;
029    
030    /**
031     * @author Daniel Kocsis
032     * @author Michael C. Han
033     */
034    public class PortletExportBackgroundTaskExecutor
035            extends BaseBackgroundTaskExecutor {
036    
037            public PortletExportBackgroundTaskExecutor() {
038                    setBackgroundTaskStatusMessageTranslator(
039                            new ExportBackgroundTaskStatusMessageTranslator());
040                    setSerial(true);
041            }
042    
043            @Override
044            public BackgroundTaskResult execute(BackgroundTask backgroundTask)
045                    throws Exception {
046    
047                    Map<String, Serializable> taskContextMap =
048                            backgroundTask.getTaskContextMap();
049    
050                    long userId = MapUtil.getLong(taskContextMap, "userId");
051                    String fileName = MapUtil.getString(taskContextMap, "fileName");
052    
053                    long plid = MapUtil.getLong(taskContextMap, "plid");
054                    long groupId = MapUtil.getLong(taskContextMap, "groupId");
055                    String portletId = MapUtil.getString(taskContextMap, "portletId");
056                    Map<String, String[]> parameterMap =
057                            (Map<String, String[]>)taskContextMap.get("parameterMap");
058                    Date startDate = (Date)taskContextMap.get("startDate");
059                    Date endDate = (Date)taskContextMap.get("endDate");
060    
061                    File larFile = LayoutLocalServiceUtil.exportPortletInfoAsFile(
062                            plid, groupId, portletId, parameterMap, startDate, endDate);
063    
064                    BackgroundTaskLocalServiceUtil.addBackgroundTaskAttachment(
065                            userId, backgroundTask.getBackgroundTaskId(), fileName, larFile);
066    
067                    return BackgroundTaskResult.SUCCESS;
068            }
069    
070    }