001
014
015 package com.liferay.portal.lar.backgroundtask;
016
017 import com.liferay.portal.kernel.backgroundtask.BackgroundTaskResult;
018 import com.liferay.portal.kernel.lar.MissingReferences;
019 import com.liferay.portal.kernel.util.MapUtil;
020 import com.liferay.portal.model.BackgroundTask;
021 import com.liferay.portal.service.LayoutLocalServiceUtil;
022
023 import java.io.File;
024 import java.io.Serializable;
025
026 import java.util.Date;
027 import java.util.Map;
028
029
032 public class PortletStagingBackgroundTaskExecutor
033 extends BaseStagingBackgroundTaskExecutor {
034
035 public PortletStagingBackgroundTaskExecutor() {
036 setBackgroundTaskStatusMessageTranslator(
037 new PortletStagingBackgroundTaskStatusMessageTranslator());
038 }
039
040 @Override
041 public BackgroundTaskResult execute(BackgroundTask backgroundTask)
042 throws Exception {
043
044 Map<String, Serializable> taskContextMap =
045 backgroundTask.getTaskContextMap();
046
047 long userId = MapUtil.getLong(taskContextMap, "userId");
048 long targetPlid = MapUtil.getLong(taskContextMap, "targetPlid");
049 long targetGroupId = MapUtil.getLong(taskContextMap, "targetGroupId");
050 String portletId = MapUtil.getString(taskContextMap, "portletId");
051 Map<String, String[]> parameterMap =
052 (Map<String, String[]>)taskContextMap.get("parameterMap");
053
054 long sourcePlid = MapUtil.getLong(taskContextMap, "sourcePlid");
055 long sourceGroupId = MapUtil.getLong(taskContextMap, "sourceGroupId");
056 Date startDate = (Date)taskContextMap.get("startDate");
057 Date endDate = (Date)taskContextMap.get("endDate");
058
059 File larFile = LayoutLocalServiceUtil.exportPortletInfoAsFile(
060 sourcePlid, sourceGroupId, portletId, parameterMap, startDate,
061 endDate);
062
063 markBackgroundTask(backgroundTask.getBackgroundTaskId(), "exported");
064
065 MissingReferences missingReferences = null;
066
067 try {
068 missingReferences =
069 LayoutLocalServiceUtil.validateImportPortletInfo(
070 userId, targetPlid, targetGroupId, portletId, parameterMap,
071 larFile);
072
073 markBackgroundTask(
074 backgroundTask.getBackgroundTaskId(), "validated");
075
076 LayoutLocalServiceUtil.importPortletInfo(
077 userId, targetPlid, targetGroupId, portletId, parameterMap,
078 larFile);
079 }
080 finally {
081 larFile.delete();
082 }
083
084 return processMissingReferences(
085 backgroundTask.getBackgroundTaskId(), missingReferences);
086 }
087
088 }