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.lar.PortletDataHandlerKeys;
021 import com.liferay.portal.kernel.staging.StagingUtil;
022 import com.liferay.portal.kernel.util.GetterUtil;
023 import com.liferay.portal.kernel.util.MapUtil;
024 import com.liferay.portal.model.BackgroundTask;
025 import com.liferay.portal.service.BackgroundTaskLocalServiceUtil;
026 import com.liferay.portal.service.LayoutLocalServiceUtil;
027
028 import java.io.File;
029 import java.io.Serializable;
030
031 import java.util.Date;
032 import java.util.Map;
033
034
038 public class LayoutExportBackgroundTaskExecutor
039 extends BaseBackgroundTaskExecutor {
040
041 public LayoutExportBackgroundTaskExecutor() {
042 setBackgroundTaskStatusMessageTranslator(
043 new LayoutExportImportBackgroundTaskStatusMessageTranslator());
044 setSerial(true);
045 }
046
047 @Override
048 public BackgroundTaskResult execute(BackgroundTask backgroundTask)
049 throws Exception {
050
051 Map<String, Serializable> taskContextMap =
052 backgroundTask.getTaskContextMap();
053
054 long userId = MapUtil.getLong(taskContextMap, "userId");
055 String fileName = MapUtil.getString(taskContextMap, "fileName");
056
057 long groupId = MapUtil.getLong(taskContextMap, "groupId");
058 boolean privateLayout = MapUtil.getBoolean(
059 taskContextMap, "privateLayout");
060 long[] layoutIds = GetterUtil.getLongValues(
061 taskContextMap.get("layoutIds"));
062 Map<String, String[]> parameterMap =
063 (Map<String, String[]>)taskContextMap.get("parameterMap");
064 Date startDate = (Date)taskContextMap.get("startDate");
065 Date endDate = (Date)taskContextMap.get("endDate");
066
067 File larFile = LayoutLocalServiceUtil.exportLayoutsAsFile(
068 groupId, privateLayout, layoutIds, parameterMap, startDate,
069 endDate);
070
071 BackgroundTaskLocalServiceUtil.addBackgroundTaskAttachment(
072 userId, backgroundTask.getBackgroundTaskId(), fileName, larFile);
073
074 boolean updateLastPublishDate = MapUtil.getBoolean(
075 parameterMap, PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE);
076
077 if (updateLastPublishDate) {
078 StagingUtil.updateLastPublishDate(groupId, privateLayout, endDate);
079 }
080
081 return BackgroundTaskResult.SUCCESS;
082 }
083
084 @Override
085 public String handleException(BackgroundTask backgroundTask, Exception e) {
086 JSONObject jsonObject = StagingUtil.getExceptionMessagesJSONObject(
087 getLocale(backgroundTask), e, backgroundTask.getTaskContextMap());
088
089 return jsonObject.toString();
090 }
091
092 }