Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.ConnectException;
Expand Down Expand Up @@ -117,21 +118,29 @@ public void generatePdfReport(@Parameter(name = "token", required = true, descri
long reportStart = System.currentTimeMillis();
AnalysisStoredResult asr = this.token.getFromToken(token);

ByteArrayOutputStream buffer = new ByteArrayOutputStream();
analysisReport.create(asr, resource, s.getDbId(), number, importableOnly, diagramProfile, analysisProfile, fireworksProfile, buffer);

response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment; filename=\"" + "report.pdf" + "\"");

response.setContentLength(buffer.size());
OutputStream os = response.getOutputStream();
analysisReport.create(asr, resource, s.getDbId(), number, importableOnly, diagramProfile, analysisProfile, fireworksProfile, os);
buffer.writeTo(os);
os.flush();

Long reportTime = System.currentTimeMillis() - reportStart;
logger.debug(String.format("_REPORT_ format:PDF token:%s pathways:%d time:%s", token, number, FormatUtils.getTimeFormatted(reportTime)));

Map<String, String> map = getReportInformation(request);
doAsyncSearchReport(map.get("ip-address"), waitingTime, reportTime, number, map.get("user-agent"));
} catch (PdfException | IllegalStateException | IOException ise) {
} catch (PdfException | IllegalStateException e) {
logger.error(String.format("_REPORT_ format:PDF token:%s PDF_Generation_Failed", token), e);
try { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to generate PDF report"); } catch (IOException ignored) {}
} catch (IOException e) {
logger.debug(String.format("_REPORT_ format:PDF token:%s User_Closed_Connection", token));
} catch (AnalysisExporterException e) {
throw new RuntimeException(e.getMessage());
logger.error(String.format("_REPORT_ format:PDF token:%s Export_Failed", token), e);
try { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to generate PDF report"); } catch (IOException ignored) {}
} finally {
synchronized (REPORT_SEMAPHORE) {
REPORT_COUNT--;
Expand Down