List of usage examples for com.liferay.portal.kernel.backgroundtask BackgroundTask getBackgroundTaskId
public long getBackgroundTaskId();
From source file:ch.inofix.contact.service.impl.ContactLocalServiceImpl.java
License:Open Source License
@Override public long exportContactsAsFileInBackground(long userId, ExportImportConfiguration exportImportConfiguration) throws PortalException { // TODO: The export may have different file types / extensions: // - .csv// w w w.ja v a 2s .com // - .xml // - .txt // - .json // if // (!DLValidatorUtil.isValidName(exportImportConfiguration.getName())) { // throw new LARFileNameException(exportImportConfiguration.getName()); // } Map<String, Serializable> taskContextMap = new HashMap<>(); taskContextMap.put("exportImportConfigurationId", exportImportConfiguration.getExportImportConfigurationId()); BackgroundTask backgroundTask = BackgroundTaskManagerUtil.addBackgroundTask(userId, exportImportConfiguration.getGroupId(), exportImportConfiguration.getName(), ContactExportBackgroundTaskExecutor.class.getName(), taskContextMap, new ServiceContext()); return backgroundTask.getBackgroundTaskId(); }
From source file:ch.inofix.contact.service.impl.ContactLocalServiceImpl.java
License:Open Source License
@Override public long importContactsInBackground(long userId, ExportImportConfiguration exportImportConfiguration, File file) throws PortalException { Map<String, Serializable> taskContextMap = new HashMap<>(); taskContextMap.put("exportImportConfigurationId", exportImportConfiguration.getExportImportConfigurationId()); BackgroundTask backgroundTask = BackgroundTaskManagerUtil.addBackgroundTask(userId, exportImportConfiguration.getGroupId(), exportImportConfiguration.getName(), ContactImportBackgroundTaskExecutor.class.getName(), taskContextMap, new ServiceContext()); backgroundTask.addAttachment(userId, file.getName(), file); return backgroundTask.getBackgroundTaskId(); }
From source file:ch.inofix.referencemanager.service.impl.ReferenceLocalServiceImpl.java
License:Open Source License
/** * /* ww w .j a va2s . c o m*/ * @param userId * @param taskName * @param groupId * @param privateLayout * @param parameterMap * @param file * @param serviceContext * @since 1.0.8 * @return * @throws PortalException */ public long importReferencesInBackground(long userId, String taskName, long groupId, boolean privateLayout, Map<String, String[]> parameterMap, File file, ServiceContext serviceContext) throws PortalException { Map<String, Serializable> taskContextMap = new HashMap<String, Serializable>(); taskContextMap.put("userId", userId); taskContextMap.put("groupId", groupId); taskContextMap.put("parameterMap", (Serializable) parameterMap); taskContextMap.put("privateLayout", privateLayout); taskContextMap.put("serviceContext", serviceContext); BackgroundTask backgroundTask = backgroundTaskmanager.addBackgroundTask(userId, groupId, taskName, ReferenceImportBackgroundTaskExecutor.class.getName(), taskContextMap, serviceContext); backgroundTask.addAttachment(userId, file.getName(), file); return backgroundTask.getBackgroundTaskId(); }
From source file:com.liferay.exportimport.internal.background.task.BaseStagingBackgroundTaskExecutor.java
License:Open Source License
protected void clearBackgroundTaskStatus(BackgroundTask backgroundTask) { BackgroundTaskStatus backgroundTaskStatus = BackgroundTaskStatusRegistryUtil .getBackgroundTaskStatus(backgroundTask.getBackgroundTaskId()); backgroundTaskStatus.clearAttributes(); }
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 w w w .jav 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.LayoutExportBackgroundTaskExecutor.java
License:Open Source License
@Override public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws PortalException { ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask); Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap(); long userId = MapUtil.getLong(settingsMap, "userId"); StringBundler sb = new StringBundler(4); sb.append(StringUtil.replace(exportImportConfiguration.getName(), CharPool.SPACE, CharPool.UNDERLINE)); sb.append(StringPool.DASH);/*from ww w. j ava 2s . co m*/ sb.append(Time.getTimestamp()); sb.append(".lar"); File larFile = ExportImportLocalServiceUtil.exportLayoutsAsFile(exportImportConfiguration); BackgroundTaskManagerUtil.addBackgroundTaskAttachment(userId, backgroundTask.getBackgroundTaskId(), sb.toString(), larFile); return BackgroundTaskResult.SUCCESS; }
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 va2 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.internal.background.task.LayoutStagingBackgroundTaskExecutor.java
License:Open Source License
@Override public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws PortalException { ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask); Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap(); long userId = MapUtil.getLong(settingsMap, "userId"); long targetGroupId = MapUtil.getLong(settingsMap, "targetGroupId"); long sourceGroupId = MapUtil.getLong(settingsMap, "sourceGroupId"); clearBackgroundTaskStatus(backgroundTask); File file = null;//ww w . j a va 2 s . c om MissingReferences missingReferences = null; try { ExportImportThreadLocal.setLayoutStagingInProcess(true); Group targetGroup = GroupLocalServiceUtil.fetchGroup(targetGroupId); if (targetGroup == null) { throw new NoSuchGroupException( "Target group does not exists with the primary key " + targetGroupId); } Group sourceGroup = GroupLocalServiceUtil.getGroup(sourceGroupId); if (sourceGroup.hasStagingGroup()) { Group stagingGroup = sourceGroup.getStagingGroup(); if (stagingGroup.getGroupId() == targetGroupId) { ExportImportThreadLocal.setInitialLayoutStagingInProcess(true); TrashEntryLocalServiceUtil.deleteEntries(sourceGroupId, true); } } ExportImportLifecycleManagerUtil.fireExportImportLifecycleEvent(EVENT_PUBLICATION_LAYOUT_LOCAL_STARTED, PROCESS_FLAG_LAYOUT_STAGING_IN_PROCESS, String.valueOf(exportImportConfiguration.getExportImportConfigurationId()), exportImportConfiguration); boolean privateLayout = MapUtil.getBoolean(settingsMap, "privateLayout"); initThreadLocals(sourceGroupId, privateLayout); file = ExportImportLocalServiceUtil.exportLayoutsAsFile(exportImportConfiguration); markBackgroundTask(backgroundTask.getBackgroundTaskId(), "exported"); missingReferences = TransactionInvokerUtil.invoke(transactionConfig, new LayoutStagingImportCallable(backgroundTask.getBackgroundTaskId(), exportImportConfiguration, file, sourceGroupId, targetGroupId, userId)); ExportImportThreadLocal.setInitialLayoutStagingInProcess(false); ExportImportThreadLocal.setLayoutStagingInProcess(false); ExportImportLifecycleManagerUtil.fireExportImportLifecycleEvent( EVENT_PUBLICATION_LAYOUT_LOCAL_SUCCEEDED, PROCESS_FLAG_LAYOUT_STAGING_IN_PROCESS, String.valueOf(exportImportConfiguration.getExportImportConfigurationId()), exportImportConfiguration); } catch (Throwable t) { ExportImportThreadLocal.setInitialLayoutStagingInProcess(false); ExportImportThreadLocal.setLayoutStagingInProcess(false); ExportImportLifecycleManagerUtil.fireExportImportLifecycleEvent(EVENT_PUBLICATION_LAYOUT_LOCAL_FAILED, PROCESS_FLAG_LAYOUT_STAGING_IN_PROCESS, String.valueOf(exportImportConfiguration.getExportImportConfigurationId()), exportImportConfiguration, t); if (_log.isDebugEnabled()) { _log.debug(t, t); } else if (_log.isWarnEnabled()) { _log.warn("Unable to publish layout: " + t.getMessage()); } Group sourceGroup = GroupLocalServiceUtil.getGroup(sourceGroupId); if (sourceGroup.hasStagingGroup()) { ServiceContext serviceContext = new ServiceContext(); serviceContext.setUserId(userId); StagingLocalServiceUtil.disableStaging(sourceGroup, serviceContext); List<BackgroundTask> queuedBackgroundTasks = BackgroundTaskManagerUtil.getBackgroundTasks( sourceGroupId, LayoutStagingBackgroundTaskExecutor.class.getName(), BackgroundTaskConstants.STATUS_QUEUED); for (BackgroundTask queuedBackgroundTask : queuedBackgroundTasks) { BackgroundTaskManagerUtil.amendBackgroundTask(queuedBackgroundTask.getBackgroundTaskId(), null, BackgroundTaskConstants.STATUS_CANCELLED, new ServiceContext()); } } deleteTempLarOnFailure(file); throw new SystemException(t); } deleteTempLarOnSuccess(file); return processMissingReferences(backgroundTask.getBackgroundTaskId(), missingReferences); }
From source file:com.liferay.exportimport.internal.background.task.PortletExportBackgroundTaskExecutor.java
License:Open Source License
@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);//from w ww .j a v a2 s .c o m return BackgroundTaskResult.SUCCESS; }
From source file:com.liferay.exportimport.internal.background.task.PortletStagingBackgroundTaskExecutor.java
License:Open Source License
@Override public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws Exception { ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask); File file = null;//from ww w . j a v a 2 s. c o m MissingReferences missingReferences = null; try { ExportImportThreadLocal.setPortletStagingInProcess(true); ExportImportLifecycleManagerUtil.fireExportImportLifecycleEvent(EVENT_PUBLICATION_PORTLET_LOCAL_STARTED, PROCESS_FLAG_PORTLET_STAGING_IN_PROCESS, String.valueOf(exportImportConfiguration.getExportImportConfigurationId()), exportImportConfiguration); file = ExportImportLocalServiceUtil.exportPortletInfoAsFile(exportImportConfiguration); markBackgroundTask(backgroundTask.getBackgroundTaskId(), "exported"); missingReferences = TransactionInvokerUtil.invoke(transactionConfig, new PortletStagingCallable( backgroundTask.getBackgroundTaskId(), exportImportConfiguration, file)); ExportImportThreadLocal.setPortletStagingInProcess(false); ExportImportLifecycleManagerUtil.fireExportImportLifecycleEvent( EVENT_PUBLICATION_PORTLET_LOCAL_SUCCEEDED, PROCESS_FLAG_PORTLET_STAGING_IN_PROCESS, String.valueOf(exportImportConfiguration.getExportImportConfigurationId()), exportImportConfiguration); } catch (Throwable t) { ExportImportThreadLocal.setPortletStagingInProcess(false); ExportImportLifecycleManagerUtil.fireExportImportLifecycleEvent(EVENT_PUBLICATION_PORTLET_LOCAL_FAILED, PROCESS_FLAG_PORTLET_STAGING_IN_PROCESS, String.valueOf(exportImportConfiguration.getExportImportConfigurationId()), exportImportConfiguration); if (_log.isDebugEnabled()) { _log.debug(t, t); } else if (_log.isWarnEnabled()) { _log.warn("Unable to publish portlet: " + t.getMessage()); } deleteTempLarOnFailure(file); throw new SystemException(t); } deleteTempLarOnSuccess(file); return processMissingReferences(backgroundTask.getBackgroundTaskId(), missingReferences); }