/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.exportimport.internal.background.task;
import com.liferay.exportimport.internal.background.task.display.PortletExportImportBackgroundTaskDisplay;
import com.liferay.exportimport.kernel.model.ExportImportConfiguration;
import com.liferay.exportimport.kernel.service.ExportImportLocalServiceUtil;
import com.liferay.portal.kernel.backgroundtask.BackgroundTask;
import com.liferay.portal.kernel.backgroundtask.BackgroundTaskExecutor;
import com.liferay.portal.kernel.backgroundtask.BackgroundTaskManagerUtil;
import com.liferay.portal.kernel.backgroundtask.BackgroundTaskResult;
import com.liferay.portal.kernel.backgroundtask.display.BackgroundTaskDisplay;
import com.liferay.portal.kernel.util.MapUtil;
import java.io.File;
import java.io.Serializable;
import java.util.Map;
/**
* @author Daniel Kocsis
* @author Michael C. Han
* @author Akos Thurzo
*/
public class PortletExportBackgroundTaskExecutor
extends BaseExportImportBackgroundTaskExecutor {
public PortletExportBackgroundTaskExecutor() {
setBackgroundTaskStatusMessageTranslator(
new PortletExportImportBackgroundTaskStatusMessageTranslator());
}
@Override
public BackgroundTaskExecutor clone() {
PortletExportBackgroundTaskExecutor
portletExportBackgroundTaskExecutor =
new PortletExportBackgroundTaskExecutor();
portletExportBackgroundTaskExecutor.
setBackgroundTaskStatusMessageTranslator(
getBackgroundTaskStatusMessageTranslator());
portletExportBackgroundTaskExecutor.setIsolationLevel(
getIsolationLevel());
return portletExportBackgroundTaskExecutor;
}
@Override
public BackgroundTaskResult execute(BackgroundTask backgroundTask)
throws Exception {
ExportImportConfiguration exportImportConfiguration =
getExportImportConfiguration(backgroundTask);
Map<String, Serializable> settingsMap =
exportImportConfiguration.getSettingsMap();
long userId = MapUtil.getLong(settingsMap, "userId");
String fileName = MapUtil.getString(settingsMap, "fileName");
File larFile = ExportImportLocalServiceUtil.exportPortletInfoAsFile(
exportImportConfiguration);
BackgroundTaskManagerUtil.addBackgroundTaskAttachment(
userId, backgroundTask.getBackgroundTaskId(), fileName, larFile);
return BackgroundTaskResult.SUCCESS;
}
@Override
public BackgroundTaskDisplay getBackgroundTaskDisplay(
BackgroundTask backgroundTask) {
return new PortletExportImportBackgroundTaskDisplay(backgroundTask);
}
}