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.repository.model.FileEntry;
020    import com.liferay.portal.kernel.util.MapUtil;
021    import com.liferay.portal.model.BackgroundTask;
022    import com.liferay.portal.service.LayoutLocalServiceUtil;
023    
024    import java.io.Serializable;
025    
026    import java.util.List;
027    import java.util.Map;
028    
029    /**
030     * @author Daniel Kocsis
031     */
032    public class PortletImportBackgroundTaskExecutor
033            extends BaseBackgroundTaskExecutor {
034    
035            public PortletImportBackgroundTaskExecutor() {
036                    setBackgroundTaskStatusMessageTranslator(
037                            new DefaultExportImportBackgroundTaskStatusMessageTranslator());
038                    setSerial(true);
039            }
040    
041            @Override
042            public BackgroundTaskResult execute(BackgroundTask backgroundTask)
043                    throws Exception {
044    
045                    Map<String, Serializable> taskContextMap =
046                            backgroundTask.getTaskContextMap();
047    
048                    long userId = MapUtil.getLong(taskContextMap, "userId");
049                    long plid = MapUtil.getLong(taskContextMap, "plid");
050                    long groupId = MapUtil.getLong(taskContextMap, "groupId");
051                    String portletId = MapUtil.getString(taskContextMap, "portletId");
052                    Map<String, String[]> parameterMap =
053                            (Map<String, String[]>)taskContextMap.get("parameterMap");
054    
055                    List<FileEntry> attachmentsFileEntries =
056                            backgroundTask.getAttachmentsFileEntries();
057    
058                    for (FileEntry attachmentsFileEntry : attachmentsFileEntries) {
059                            LayoutLocalServiceUtil.importPortletInfo(
060                                    userId, plid, groupId, portletId, parameterMap,
061                                    attachmentsFileEntry.getContentStream());
062                    }
063    
064                    return BackgroundTaskResult.SUCCESS;
065            }
066    
067    }