@Override protected void doInTransactionWithoutResult(TransactionStatus status) { AuthenticatedUserThreadLocal.setUser(remoteUser); RequestCacheThreadLocal.getRequestCache().put(RequestCacheThreadLocal.CONTEXT_PATH_KEY, contextPath); PdfExportProgressMonitor monitor = flyingPdfExporterService.createProgressMonitor(progress); File pdfFile; try { monitor.beginCalculationOfContentTree(); Space space = spaceManager.getSpace(spaceId); ContentTree contentTree = importExportManager.getContentTree(remoteUser, space); if (!contentToBeExported.isEmpty()) { contentTree.filter(contentToBeExported); } monitor.completedCalculationOfContentTree(contentTree.size()); pdfFile = flyingPdfExporterService.createPdfForSpace(remoteUser, space, contentTree, monitor, contextPath, new SpaceExportMetrics()); downloadPath = importExportManager.prepareDownloadPath(pdfFile.getAbsolutePath()); gateKeeper.addKey(downloadPath, remoteUser); downloadPath = contextPath + downloadPath; monitor.completed(downloadPath); } catch (Exception ex) { log.error("Error during PDF export", ex); String exceptionMessage = ex.getMessage(); if (StringUtils.isBlank(exceptionMessage)) exceptionMessage = ex.getClass().getName(); monitor.errored(exceptionMessage); } } });
@Override public File createPdfForSpace(User user, Space space, ContentTree contentTree, PdfExportProgressMonitor progress, String contextPath, SpaceExportMetrics spaceExportMetrics) throws ImportExportException { spaceExportMetrics.getEnvironmentInfo().setSpaceKey(space.getKey()); spaceExportMetrics.setConfluencePages(contentTree.size()); spaceExportMetrics.getEnvironmentInfo().setExportScope(ExportScope.SPACE); fillEnvironmentData(space, spaceExportMetrics.getEnvironmentInfo()); final long startTime = System.currentTimeMillis(); try { final File result = delegate.createPdfForSpace(user, space, contentTree, progress, contextPath, spaceExportMetrics); spaceExportMetrics.getExportResults().setExportStatus(ExportStatus.OK); return result; } catch (Exception e) { setGenericError(spaceExportMetrics.getExportResults()); throw e; } finally { spaceExportMetrics.setTotalTime((int) (System.currentTimeMillis() - startTime)); sendToAnalytics(new PdfExportAnalyticEvent(spaceExportMetrics)); } }