Wiki source code of PDFExport

Last modified by jklein on 2024/08/15 08:16

Hide last authors
jklein 1.1 1 {{velocity output="false"}}
2 #macro (returnPDFExportJobStatusJSON $pdfExportJobId)
3 #set ($pdfExportJobStatus = $services.job.getJobStatus($pdfExportJobId))
4 #set ($pdfExportJobStatusJSON = {
5 'id': $pdfExportJobStatus.request.id,
6 'state': $pdfExportJobStatus.state,
7 'canceled': $pdfExportJobStatus.canceled,
8 'progress': {
9 'offset': $pdfExportJobStatus.progress.offset
10 }
11 })
12 #if ($pdfExportJobStatus.state == 'FINISHED')
13 #if ($pdfExportJobStatus.request.isServerSide() && $services.resource.temporary.exists(
14 $pdfExportJobStatus.getPDFFileReference()))
15 #set ($pdfExportJobStatusJSON.pdfFileURL = $services.resource.temporary.getURL(
16 $pdfExportJobStatus.getPDFFileReference()))
17 #end
18 ## Check if the PDF export job failed.
19 #set ($lastError = {'throwable': $pdfExportJobStatus.error})
20 #set ($pdfExportJobStatusJSON.failed = "$!lastError.throwable" != '')
21 #if (!$pdfExportJobStatusJSON.failed)
22 ## The PDF export job log can contain errors even if the job did not fail. Let's extract the last error and warn
23 ## the user because it may justify why the result is not as expected.
24 #set ($lastError = $pdfExportJobStatus.logTail.getLastLogEvent('ERROR'))
25 #end
26 ## Extract the error message from the last error.
27 #if ($lastError.throwable)
28 #set ($lastError = $exceptiontool.getRootCauseMessage($lastError.throwable))
29 #else
30 #set ($lastError = $lastError.formattedMessage)
31 #end
32 #set ($pdfExportJobStatusJSON.lastError = $lastError)
33 #end
34 #jsonResponse($pdfExportJobStatusJSON)
35 #end
36 {{/velocity}}
37
38 {{velocity wiki="false"}}
39 #if ($xcontext.action == 'get')
40 #if ("$!request.action" != '' && !$services.csrf.isTokenValid($request.form_token))
41 #set ($discard = $response.sendError(401, 'CSRF token verification failed!'))
42 #elseif ($request.action == 'export')
43 #set ($pdfExportJobRequest = $services.export.pdf.createRequest())
44 #set ($pdfExportJob = $services.export.pdf.execute($pdfExportJobRequest))
45 #returnPDFExportJobStatusJSON($pdfExportJobRequest.id)
46 #elseif ($request.action == 'cancel')
47 #set ($pdfExportJobId = $request.jobId.split('/'))
48 #set ($pdfExportJobStatus = $services.job.getJobStatus($pdfExportJobId))
49 #set ($discard = $pdfExportJobStatus.cancel())
50 #returnPDFExportJobStatusJSON($pdfExportJobId)
51 #elseif ($request.data == 'jobStatus')
52 #set ($pdfExportJobId = $request.jobId.split('/'))
53 #returnPDFExportJobStatusJSON($pdfExportJobId)
54 #elseif ($request.data == 'serverSidePrintingAvailable')
55 #set ($serverSidePrintingAvailable = $services.export.pdf.configuration.isServerSide() &&
56 $services.export.pdf.isServerSidePrintingAvailable())
57 #jsonResponse({
58 "serverSidePrintingAvailable": $serverSidePrintingAvailable
59 })
60 #end
61 #end
62 {{/velocity}}
© Aagon GmbH 2025
Besuchen Sie unsere neue Aagon-Community