s5260822 2025-03-12 21:00:03 +01:00
commit 8317dff035
7 changed files with 220 additions and 41 deletions

View file

@ -5,18 +5,17 @@ import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import org.bson.Document;
import org.texttechnologylab.project.gruppe_05_1.database.domainimp.speeches.Speech_MongoDB_Impl;
import org.texttechnologylab.project.gruppe_05_1.domain.html.HtmlSpeech;
import org.texttechnologylab.project.gruppe_05_1.domain.html.Parlamentarier;
import org.texttechnologylab.project.gruppe_05_1.domain.html.ParlamentarierDetails;
import org.texttechnologylab.project.gruppe_05_1.domain.speaker.Membership;
import org.texttechnologylab.project.gruppe_05_1.domain.speech.SpeechMetaData;
import org.texttechnologylab.project.gruppe_05_1.util.GeneralUtils;
import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Impls.Speech_File_Impl;
import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Interfaces.Speech;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
/**
@ -277,6 +276,11 @@ public class MongoPprUtils {
return m;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Speech
// TODO: kopiere die Speech-Sachen von Übung 4 hierher!
/**
@ -313,7 +317,7 @@ public class MongoPprUtils {
* @param speakerId
* @return
*/
public static List<SpeechMetaData> getSpeechesMetadataForSeaker(String speakerId) {
public static List<SpeechMetaData> getSpeechesMetadataForSpeaker(String speakerId) {
List<SpeechMetaData> speechMetaDataList = new ArrayList<>();
List<Speech> speeches = MongoPprUtils.getSpeechesOfSpeaker(speakerId);
@ -388,4 +392,11 @@ public class MongoPprUtils {
return (String) iter.first().get("title");
}
}
public static HtmlSpeech getSpeechByKey(String key) {
Document filter = new Document("speechKey", key);
Document speechDoc = getSpeechCollection().find(filter).first();
return new HtmlSpeech(speechDoc);
}
}

View file

@ -0,0 +1,92 @@
package org.texttechnologylab.project.gruppe_05_1.domain.html;
import org.bson.Document;
import org.texttechnologylab.project.gruppe_05_1.database.MongoDBHandler;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;
public class HtmlSpeech {
String speechKey;
String speakerName;
String fraction;
List<SpeechContent> content = new ArrayList<>();
public HtmlSpeech() {
}
public HtmlSpeech(Document doc) {
setSpeechKey(doc.getString("speechKey"));
setSpeakerName(doc.getString("speakerName"));
setFraction(doc.getString("fraction"));
List<Document> contentDocList = doc.get("speechContents", MongoDBHandler.DOC_LIST_CLASS);
if (contentDocList == null) {
setContent(new ArrayList<>());
} else {
for (Document contentDoc : contentDocList) {
addContent(new SpeechContent(contentDoc));
}
}
}
public String getSpeechKey() {
return speechKey;
}
public void setSpeechKey(String speechKey) {
this.speechKey = speechKey;
}
public String getSpeakerName() {
return speakerName;
}
public void setSpeakerName(String speakerName) {
this.speakerName = speakerName;
}
public String getFraction() {
return fraction;
}
public void setFraction(String fraction) {
this.fraction = fraction;
}
public List<SpeechContent> getContent() {
return content;
}
public void setContent(List<SpeechContent> content) {
this.content = content;
}
public void addContent(SpeechContent contentLine) {
content.add(contentLine);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof HtmlSpeech that)) return false;
return Objects.equals(speechKey, that.speechKey) && Objects.equals(speakerName, that.speakerName) && Objects.equals(fraction, that.fraction) && Objects.equals(content, that.content);
}
@Override
public int hashCode() {
return Objects.hash(speechKey, speakerName, fraction, content);
}
@Override
public String toString() {
return new StringJoiner(", ", HtmlSpeech.class.getSimpleName() + "[", "]")
.add("speechKey='" + speechKey + "'")
.add("speakerName='" + speakerName + "'")
.add("fraction='" + fraction + "'")
.add("content=" + content)
.toString();
}
}

View file

@ -0,0 +1,69 @@
package org.texttechnologylab.project.gruppe_05_1.domain.html;
import org.bson.Document;
import java.util.Objects;
import java.util.StringJoiner;
public class SpeechContent {
public enum SpeechContentType {SPEAKER, LINE, COMMENT}
SpeechContentType type;
String content; // name und Fraktion für SPEAKER / content für LINE / comment für COMMENT
public SpeechContent() {
}
public SpeechContent(Document doc) {
String type = (String) doc.get("type");
if (type.equalsIgnoreCase("speaker")) {
setType(SpeechContentType.SPEAKER);
setContent(doc.getString("speakerName") + " / " + doc.getString("fraction"));
} else if (type.equalsIgnoreCase("line")) {
setType(SpeechContentType.LINE);
setContent(doc.getString("content"));
} else if (type.equalsIgnoreCase("comment")) {
setType(SpeechContentType.COMMENT);
setContent(doc.getString("comment"));
}
}
public SpeechContentType getType() {
return type;
}
public void setType(SpeechContentType type) {
this.type = type;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SpeechContent that)) return false;
return type == that.type && Objects.equals(content, that.content);
}
@Override
public int hashCode() {
return Objects.hash(type, content);
}
@Override
public String toString() {
return new StringJoiner(", ", SpeechContent.class.getSimpleName() + "[", "]")
.add("type=" + type)
.add("content='" + content + "'")
.toString();
}
}

View file

@ -100,8 +100,6 @@ public class ParlamentarierController {
attributes.put("speechesPlaceholder", emptyList);
}
List<Speech> speeches = MongoPprUtils.getSpeechesOfSpeaker(pd.getId());
ctx.render("parlamentarierDetails.ftl", attributes);
}

View file

@ -3,15 +3,11 @@ package org.texttechnologylab.project.gruppe_05_1.rest;
import io.javalin.http.Context;
import io.javalin.openapi.*;
import org.texttechnologylab.project.gruppe_05_1.database.MongoPprUtils;
import org.texttechnologylab.project.gruppe_05_1.domain.html.HtmlSpeech;
import org.texttechnologylab.project.gruppe_05_1.domain.html.ParlamentarierDetails;
import org.texttechnologylab.project.gruppe_05_1.domain.speech.Protocol;
import org.texttechnologylab.project.gruppe_05_1.domain.speech.SpeechMetaData;
import org.texttechnologylab.project.gruppe_05_1.util.GeneralUtils;
import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Interfaces.Comment;
import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Interfaces.Speech;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -38,7 +34,7 @@ public class SpeechController {
String parlamentarierId = ctx.pathParam("id");
ParlamentarierDetails p = MongoPprUtils.getParlamentarierDetailsByID(parlamentarierId);
List<SpeechMetaData> speechMetaDataList = MongoPprUtils.getSpeechesMetadataForSeaker(parlamentarierId);
List<SpeechMetaData> speechMetaDataList = MongoPprUtils.getSpeechesMetadataForSpeaker(parlamentarierId);
Map<String, Object> attributes = new HashMap<>();
attributes.put("p", p);
@ -65,41 +61,14 @@ public class SpeechController {
@OpenApiResponse(status = "200", content = {@OpenApiContent(from = Speech.class)})
})
public static void showSpeech(Context ctx) {
String parlamentarierId = ctx.pathParam("id");
String redeId = ctx.pathParam("redeId");
Map<String, Object> attributes = new HashMap<>();
/*
Speech rede = MongoPprUtils.getSpeechesById(redeId);
List<Comment> comments = MongoPprUtils.getCommentsForSpeech(redeId);
ParlamentarierDetails p = MongoPprUtils.getParlamentarierDetailsByID(parlamentarierId);
HtmlSpeech speech = MongoPprUtils.getSpeechByKey(redeId);
attributes.put("s", speech);
attributes.put("p", p);
attributes.put("rede", rede);
attributes.put("comments", comments.size() > 0 ? comments : null);
Protocol protocol = rede.getProtocol();
if (protocol == null) {
attributes.put("date", "(keine Angaben)");
attributes.put("time", "(keine Angaben)");
} else {
LocalDate date = protocol.getDate();
LocalTime time = protocol.getStarttime();
if (date == null) {
attributes.put("date", "(keine Angaben)");
} else {
attributes.put("date", GeneralUtils.formatDate(date));
}
if (time == null) {
attributes.put("time", "(keine Angaben)");
} else {
attributes.put("time", GeneralUtils.formatTime(time));
}
}
*/
ctx.render("speechWithComments.ftl", attributes);
ctx.render("speech.ftl", attributes);
}
}

View file

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rede von ${s.speakerName} <#if s.fraction??> (${s.fraction}) </#if></title>
<style type="text/css">
th, td {
padding: 12px;
text-align: center; /* Center-aligns both header and data cells */
border: 1px solid #ddd;
}
</style>
</head>
<body>
<header>
<h1>Rede von ${s.speakerName} <#if s.fraction??> (${s.fraction}) </#if> </h1>
</header>
<br>
<h2>Rede ${s.speechKey} </h2>
<main>
<#list s.content as c>
<#include "speechContent.ftl">
</#list>
</main>
</body>
</html>

View file

@ -0,0 +1,7 @@
<#if c.type == 'SPEAKER'>
<#elseif c.type == 'LINE'>
${c.content}
<#elseif c.type == 'COMMENT'>
<span style="color:Blue">Kommentar: </span> ${c.content}
</#if>
<p>