001
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.json.JSONObject;
020 import com.liferay.portal.kernel.repository.model.FileEntry;
021 import com.liferay.portal.kernel.staging.StagingUtil;
022 import com.liferay.portal.kernel.util.MapUtil;
023 import com.liferay.portal.model.BackgroundTask;
024 import com.liferay.portal.service.LayoutLocalServiceUtil;
025
026 import java.io.Serializable;
027
028 import java.util.List;
029 import java.util.Map;
030
031
034 public class PortletImportBackgroundTaskExecutor
035 extends BaseBackgroundTaskExecutor {
036
037 public PortletImportBackgroundTaskExecutor() {
038 setBackgroundTaskStatusMessageTranslator(
039 new PortletExportImportBackgroundTaskStatusMessageTranslator());
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 long plid = MapUtil.getLong(taskContextMap, "plid");
052 long groupId = MapUtil.getLong(taskContextMap, "groupId");
053 String portletId = MapUtil.getString(taskContextMap, "portletId");
054 Map<String, String[]> parameterMap =
055 (Map<String, String[]>)taskContextMap.get("parameterMap");
056
057 List<FileEntry> attachmentsFileEntries =
058 backgroundTask.getAttachmentsFileEntries();
059
060 for (FileEntry attachmentsFileEntry : attachmentsFileEntries) {
061 LayoutLocalServiceUtil.importPortletInfo(
062 userId, plid, groupId, portletId, parameterMap,
063 attachmentsFileEntry.getContentStream());
064 }
065
066 return BackgroundTaskResult.SUCCESS;
067 }
068
069 @Override
070 public String handleException(BackgroundTask backgroundTask, Exception e) {
071 JSONObject jsonObject = StagingUtil.getExceptionMessagesJSONObject(
072 getLocale(backgroundTask), e, backgroundTask.getTaskContextMap());
073
074 return jsonObject.toString();
075 }
076
077 }