added support for speech export on /export page
This commit is contained in:
parent
e26bb412aa
commit
846e130418
4 changed files with 45 additions and 4 deletions
|
@ -69,12 +69,14 @@ public class RESTHandler {
|
|||
app.get("/reden", SpeechController::listAllSpeeches); // zeige alle Reden an (Filtern möglich)
|
||||
|
||||
app.get("/export/pdf/speech/{id}", SpeechesLatexExportController::exportSpeech); // exportiere eine Rede als PDF
|
||||
app.get("/export/pdf/speech", SpeechesLatexExportController::exportSpeech); // exportiere eine Rede als PDF
|
||||
app.get("/export/pdf/speaker/{id}", SpeechesLatexExportController::exportSpeechesFromSpeaker); // exportiere alle Reden eines Parlamentariers als PDF
|
||||
app.get("/export/pdf/topic/{topic}", SpeechesLatexExportController::exportSpeechesWithTopic); // exportiere alle Reden zu einem Thema als PDF
|
||||
app.get("/export/pdf/all", SpeechesLatexExportController::exportAllSpeeches); // exportiere alle Reden als PDF CAUTION!!!: This will take forever but is required in the exercise
|
||||
app.get("/export/pdf/speeches/{speechIds}", SpeechesLatexExportController::exportSpeeches); // exportiere eine Liste von Reden als PDF
|
||||
|
||||
app.get("/export/xml/speech/{id}", SpeechesXMLExportController::exportSpeech); // exportiere eine Rede als XML
|
||||
app.get("/export/xml/speech", SpeechesXMLExportController::exportSpeech); // exportiere eine Rede als XML
|
||||
app.get("/export/xml/speaker/{id}", SpeechesXMLExportController::exportSpeechesFromSpeaker); // exportiere alle Reden eines Parlamentariers als XML
|
||||
app.get("/export/xml/topic/{topic}", SpeechesXMLExportController::exportSpeechesWithTopic); // exportiere alle Reden zu einem Thema als XML
|
||||
app.get("/export/xml/all", SpeechesXMLExportController::exportAllSpeeches); // exportiere alle Reden als XML
|
||||
|
|
|
@ -26,11 +26,18 @@ public class SpeechesLatexExportController {
|
|||
@OpenApiResponse(status = "200")
|
||||
})
|
||||
public static void exportSpeech(Context ctx) {
|
||||
String speechId = null;
|
||||
try {
|
||||
speechId = ctx.pathParam("id");
|
||||
} catch (Exception e) {
|
||||
// check query param
|
||||
speechId = ctx.queryParam("speechId");
|
||||
}
|
||||
byte[] pdfBytes = new byte[0];
|
||||
try {
|
||||
pdfBytes = Base64.getDecoder().decode(getExportedSpeechBase64StringBySpeechId(ctx.pathParam("id")));
|
||||
pdfBytes = Base64.getDecoder().decode(getExportedSpeechBase64StringBySpeechId(speechId));
|
||||
} catch (Exception e) {
|
||||
Logger.error("Failed to generate Export of Speech with ID " + ctx.pathParam("id"));
|
||||
Logger.error("Failed to generate Export of Speech with ID " + speechId);
|
||||
Logger.error(e.getMessage());
|
||||
Logger.debug(Arrays.toString(e.getStackTrace()));
|
||||
}
|
||||
|
|
|
@ -28,9 +28,16 @@ public class SpeechesXMLExportController {
|
|||
@OpenApiResponse(status = "200")
|
||||
})
|
||||
public static void exportSpeech(Context ctx) {
|
||||
String speechId = null;
|
||||
try {
|
||||
speechId = ctx.pathParam("id");
|
||||
} catch (Exception e) {
|
||||
// check query param
|
||||
speechId = ctx.queryParam("speechId");
|
||||
}
|
||||
String xmlContent;
|
||||
try {
|
||||
xmlContent = getExportedSpeechById(ctx.pathParam("id"));
|
||||
xmlContent = getExportedSpeechById(speechId);
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(xmlContent.getBytes());
|
||||
if (stream.available() == 0) {
|
||||
Logger.error("XML stream is empty.");
|
||||
|
@ -41,7 +48,7 @@ public class SpeechesXMLExportController {
|
|||
ctx.contentType("application/xml");
|
||||
ctx.result(stream);
|
||||
} catch (Exception e) {
|
||||
Logger.error("Failed to generate Export of Speech with ID " + ctx.pathParam("id"));
|
||||
Logger.error("Failed to generate Export of Speech with ID " + speechId);
|
||||
Logger.error(e.getMessage());
|
||||
Logger.debug(Arrays.toString(e.getStackTrace()));
|
||||
ctx.result("Internal Server Error");
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
</head>
|
||||
<#include "header.ftl">
|
||||
<body>
|
||||
<main>
|
||||
<h2>Export von Reden</h2>
|
||||
<p>Export von allen Reden (Dieser Prozess kanne einige Zeit dauern):</p>
|
||||
<div class="export-button centered-flex-button">
|
||||
|
@ -14,5 +15,29 @@
|
|||
<div class="red-button centered-flex-button">
|
||||
<a href="/export/xml/all" target="_blank">XML Export</a>
|
||||
</div>
|
||||
<br>
|
||||
<br>
|
||||
<p>Export von allen Reden eines Parlamentariers.</p>
|
||||
</div>
|
||||
<#assign formAction = "/members">
|
||||
<#include "filterForm.ftl">
|
||||
<br>
|
||||
<br>
|
||||
<p>Export einer bestimmten Rede nach ID</p>
|
||||
<div class="filter-form">
|
||||
<form name="searchForm" action="/export/pdf/speech" method="GET">
|
||||
|
||||
<input type="text" name="speechId" placeholder="Reden ID">
|
||||
<button type="submit">Als PDF Exportieren</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="filter-form">
|
||||
<form name="searchForm" action="/export/xml/speech" method="GET">
|
||||
|
||||
<input type="text" name="speechId" placeholder="Reden ID">
|
||||
<button type="submit">Als XML Exportieren</button>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
<#include "footer.ftl">
|
Loading…
Add table
Add a link
Reference in a new issue