List of usage examples for com.liferay.portal.kernel.backgroundtask BackgroundTask getTaskContextMap
public Map<String, Serializable> getTaskContextMap();
From source file:com.liferay.adaptive.media.web.internal.background.task.OptimizeImagesBackgroundTaskExecutor.java
License:Open Source License
@Override public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws Exception { Map<String, Serializable> taskContextMap = backgroundTask.getTaskContextMap(); String configurationEntryUuid = (String) taskContextMap .get(OptimizeImagesBackgroundTaskConstants.CONFIGURATION_ENTRY_UUID); long companyId = GetterUtil.getLong(taskContextMap.get(OptimizeImagesBackgroundTaskConstants.COMPANY_ID)); optimizeImages(configurationEntryUuid, companyId); return BackgroundTaskResult.SUCCESS; }
From source file:com.liferay.dynamic.data.mapping.background.task.DDMStructureIndexerBackgroundTaskExecutor.java
License:Open Source License
@Override public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws Exception { Map<String, Serializable> taskContextMap = backgroundTask.getTaskContextMap(); Number structureIdNumber = (Number) taskContextMap.get("structureId"); long structureId = structureIdNumber.longValue(); DDMStructureIndexer structureIndexer = getDDMStructureIndexer(structureId); List<Long> ddmStructureIds = getChildrenStructureIds(structureId); structureIndexer.reindexDDMStructures(ddmStructureIds); return BackgroundTaskResult.SUCCESS; }
From source file:com.liferay.exportimport.internal.background.task.BaseExportImportBackgroundTaskExecutor.java
License:Open Source License
protected ExportImportConfiguration getExportImportConfiguration(BackgroundTask backgroundTask) { Map<String, Serializable> taskContextMap = backgroundTask.getTaskContextMap(); long exportImportConfigurationId = MapUtil.getLong(taskContextMap, "exportImportConfigurationId"); return ExportImportConfigurationLocalServiceUtil .fetchExportImportConfiguration(exportImportConfigurationId); }
From source file:com.liferay.exportimport.internal.background.task.BaseStagingBackgroundTaskExecutor.java
License:Open Source License
protected void markBackgroundTask(long backgroundTaskId, String backgroundTaskState) { BackgroundTask backgroundTask = BackgroundTaskManagerUtil.fetchBackgroundTask(backgroundTaskId); if ((backgroundTask == null) || Validator.isNull(backgroundTaskState)) { return;//from ww w. j a v a 2 s. c o m } Map<String, Serializable> taskContextMap = backgroundTask.getTaskContextMap(); if (taskContextMap == null) { taskContextMap = new HashMap<>(); } taskContextMap.put(backgroundTaskState, Boolean.TRUE); backgroundTask.setTaskContextMap(taskContextMap); BackgroundTaskManagerUtil.amendBackgroundTask(backgroundTask.getBackgroundTaskId(), taskContextMap, backgroundTask.getStatus(), new ServiceContext()); }
From source file:com.liferay.exportimport.internal.background.task.display.ExportImportBackgroundTaskDisplay.java
License:Open Source License
public ExportImportBackgroundTaskDisplay(BackgroundTask backgroundTask) { super(backgroundTask); Map<String, Serializable> taskContextMap = backgroundTask.getTaskContextMap(); _cmd = MapUtil.getString(taskContextMap, Constants.CMD); _percentage = PERCENTAGE_NONE;/*from w w w . j ava 2 s. c om*/ if (backgroundTaskStatus == null) { _allProgressBarCountersTotal = 0; _currentProgressBarCountersTotal = 0; _phase = null; _stagedModelName = null; _stagedModelType = null; return; } long allModelAdditionCountersTotal = getBackgroundTaskStatusAttributeLong("allModelAdditionCountersTotal"); long allPortletAdditionCounter = getBackgroundTaskStatusAttributeLong("allPortletAdditionCounter"); _allProgressBarCountersTotal = allModelAdditionCountersTotal + allPortletAdditionCounter; long currentModelAdditionCountersTotal = getBackgroundTaskStatusAttributeLong( "currentModelAdditionCountersTotal"); long currentPortletAdditionCounter = getBackgroundTaskStatusAttributeLong("currentPortletAdditionCounter"); _currentProgressBarCountersTotal = currentModelAdditionCountersTotal + currentPortletAdditionCounter; _phase = getBackgroundTaskStatusAttributeString("phase"); _stagedModelName = getBackgroundTaskStatusAttributeString("stagedModelName"); _stagedModelType = getBackgroundTaskStatusAttributeString("stagedModelType"); }
From source file:com.liferay.exportimport.internal.background.task.display.LayoutStagingBackgroundTaskDisplay.java
License:Open Source License
public LayoutStagingBackgroundTaskDisplay(BackgroundTask backgroundTask) { super(backgroundTask); try {/*from w w w . ja v a 2s . c om*/ Map<String, Serializable> taskContextMap = backgroundTask.getTaskContextMap(); ExportImportConfiguration exportImportConfiguration = ExportImportConfigurationLocalServiceUtil .getExportImportConfiguration(MapUtil.getLong(taskContextMap, "exportImportConfigurationId")); if ((exportImportConfiguration.getType() != TYPE_PUBLISH_LAYOUT_LOCAL) && (exportImportConfiguration.getType() != TYPE_SCHEDULED_PUBLISH_LAYOUT_LOCAL)) { return; } Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap(); long sourceGroupId = MapUtil.getLong(settingsMap, "sourceGroupId"); sourceGroup = GroupLocalServiceUtil.getGroup(sourceGroupId); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.liferay.exportimport.internal.background.task.display.PortletExportImportBackgroundTaskDisplay.java
License:Open Source License
public PortletExportImportBackgroundTaskDisplay(BackgroundTask backgroundTask) { super(backgroundTask); try {// ww w . j a v a 2 s . c o m Map<String, Serializable> taskContextMap = backgroundTask.getTaskContextMap(); ExportImportConfiguration exportImportConfiguration = ExportImportConfigurationLocalServiceUtil .getExportImportConfiguration(MapUtil.getLong(taskContextMap, "exportImportConfigurationId")); if ((exportImportConfiguration.getType() != ExportImportConfigurationConstants.TYPE_EXPORT_PORTLET) && (exportImportConfiguration .getType() != ExportImportConfigurationConstants.TYPE_IMPORT_PORTLET) && (exportImportConfiguration .getType() != ExportImportConfigurationConstants.TYPE_PUBLISH_PORTLET)) { throw new PortalException( "Invalid export import configuration type: " + exportImportConfiguration.getType()); } portlet = PortletLocalServiceUtil.getPortletById(backgroundTask.getName()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.liferay.exportimport.internal.background.task.LayoutRemoteStagingBackgroundTaskExecutor.java
License:Open Source License
@Override public BackgroundTaskResult execute(BackgroundTask backgroundTask) { ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask); clearBackgroundTaskStatus(backgroundTask); Thread currentThread = Thread.currentThread(); ClassLoader contextClassLoader = currentThread.getContextClassLoader(); File file = null;/* w w w . j a v a 2 s.c o m*/ HttpPrincipal httpPrincipal = null; MissingReferences missingReferences = null; long stagingRequestId = 0L; try { currentThread.setContextClassLoader(ClassLoaderUtil.getPortalClassLoader()); ExportImportThreadLocal.setLayoutStagingInProcess(true); ExportImportLifecycleManagerUtil.fireExportImportLifecycleEvent(EVENT_PUBLICATION_LAYOUT_REMOTE_STARTED, PROCESS_FLAG_LAYOUT_STAGING_IN_PROCESS, String.valueOf(exportImportConfiguration.getExportImportConfigurationId()), exportImportConfiguration); Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap(); long sourceGroupId = MapUtil.getLong(settingsMap, "sourceGroupId"); boolean privateLayout = MapUtil.getBoolean(settingsMap, "privateLayout"); initThreadLocals(sourceGroupId, privateLayout); Map<Long, Boolean> layoutIdMap = (Map<Long, Boolean>) settingsMap.get("layoutIdMap"); long targetGroupId = MapUtil.getLong(settingsMap, "targetGroupId"); Map<String, Serializable> taskContextMap = backgroundTask.getTaskContextMap(); httpPrincipal = (HttpPrincipal) taskContextMap.get("httpPrincipal"); file = exportLayoutsAsFile(exportImportConfiguration, layoutIdMap, targetGroupId, httpPrincipal); String checksum = FileUtil.getMD5Checksum(file); stagingRequestId = StagingServiceHttp.createStagingRequest(httpPrincipal, targetGroupId, checksum); transferFileToRemoteLive(file, stagingRequestId, httpPrincipal); markBackgroundTask(backgroundTask.getBackgroundTaskId(), "exported"); missingReferences = StagingServiceHttp.publishStagingRequest(httpPrincipal, stagingRequestId, exportImportConfiguration); ExportImportThreadLocal.setLayoutStagingInProcess(false); ExportImportLifecycleManagerUtil.fireExportImportLifecycleEvent( EVENT_PUBLICATION_LAYOUT_REMOTE_SUCCEEDED, PROCESS_FLAG_LAYOUT_STAGING_IN_PROCESS, String.valueOf(exportImportConfiguration.getExportImportConfigurationId()), exportImportConfiguration); } catch (Throwable t) { ExportImportThreadLocal.setLayoutStagingInProcess(false); ExportImportLifecycleManagerUtil.fireExportImportLifecycleEvent(EVENT_PUBLICATION_LAYOUT_REMOTE_FAILED, PROCESS_FLAG_LAYOUT_STAGING_IN_PROCESS, String.valueOf(exportImportConfiguration.getExportImportConfigurationId()), exportImportConfiguration); if (_log.isDebugEnabled()) { _log.debug(t, t); } else if (_log.isWarnEnabled()) { _log.warn("Unable to publish layout: " + t.getMessage()); } deleteTempLarOnFailure(file); throw new SystemException(t); } finally { currentThread.setContextClassLoader(contextClassLoader); if ((stagingRequestId > 0) && (httpPrincipal != null)) { try { StagingServiceHttp.cleanUpStagingRequest(httpPrincipal, stagingRequestId); } catch (PortalException pe) { if (_log.isWarnEnabled()) { _log.warn("Unable to clean up the remote live site", pe); } } } } deleteTempLarOnSuccess(file); return processMissingReferences(backgroundTask.getBackgroundTaskId(), missingReferences); }
From source file:com.liferay.exportimport.web.internal.portlet.action.EditExportConfigurationMVCActionCommand.java
License:Open Source License
protected void relaunchExportLayoutConfiguration(ActionRequest actionRequest) throws Exception { long backgroundTaskId = ParamUtil.getLong(actionRequest, BackgroundTaskConstants.BACKGROUND_TASK_ID); BackgroundTask backgroundTask = backgroundTaskManager.getBackgroundTask(backgroundTaskId); Map<String, Serializable> taskContextMap = backgroundTask.getTaskContextMap(); ExportImportConfiguration exportImportConfiguration = exportImportConfigurationLocalService .getExportImportConfiguration(MapUtil.getLong(taskContextMap, "exportImportConfigurationId")); exportImportConfiguration = ExportImportConfigurationFactory .cloneExportImportConfiguration(exportImportConfiguration); _exportImportService.exportLayoutsAsFileInBackground(exportImportConfiguration); }
From source file:com.liferay.exportimport.web.internal.portlet.action.EditPublishConfigurationMVCActionCommand.java
License:Open Source License
protected void relaunchPublishLayoutConfiguration(long userId, ActionRequest actionRequest) throws PortalException { long backgroundTaskId = ParamUtil.getLong(actionRequest, BackgroundTaskConstants.BACKGROUND_TASK_ID); BackgroundTask backgroundTask = BackgroundTaskManagerUtil.getBackgroundTask(backgroundTaskId); Map<String, Serializable> taskContextMap = backgroundTask.getTaskContextMap(); ExportImportConfiguration exportImportConfiguration = exportImportConfigurationLocalService .getExportImportConfiguration(MapUtil.getLong(taskContextMap, "exportImportConfigurationId")); if (exportImportConfiguration.getType() == ExportImportConfigurationConstants.TYPE_PUBLISH_LAYOUT_LOCAL) { StagingUtil.publishLayouts(userId, exportImportConfiguration); } else if (exportImportConfiguration .getType() == ExportImportConfigurationConstants.TYPE_PUBLISH_LAYOUT_REMOTE) { StagingUtil.copyRemoteLayouts(exportImportConfiguration); }/*from ww w . j ava2 s . c o m*/ }