From 14d3ad7e034ae0e0f8e9467ffac494b01a3303b9 Mon Sep 17 00:00:00 2001 From: JKatzwinkel Date: Sat, 30 Sep 2023 00:29:21 +0000 Subject: [PATCH] some random polishing --- README.md | 4 +- src/main/java/tla/web/model/Annotation.java | 42 +++++++++---------- src/main/java/tla/web/model/Sentence.java | 10 ++--- src/main/java/tla/web/model/Text.java | 2 + .../tla/web/model/mappings/MappingConfig.java | 2 - .../tla/web/model/parts/Transcription.java | 2 - 6 files changed, 30 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 0909c3ff..2736bc21 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ![build](https://github.com/JKatzwinkel/tla-web/workflows/build/badge.svg) ![deploy](https://github.com/JKatzwinkel/tla-web/workflows/deploy/badge.svg) -![LINE](https://img.shields.io/badge/line--coverage-90.99%25-brightgreen.svg) -![METHOD](https://img.shields.io/badge/method--coverage-91.33%25-brightgreen.svg) +![LINE](https://img.shields.io/badge/line--coverage-91.00%25-brightgreen.svg) +![METHOD](https://img.shields.io/badge/method--coverage-92.46%25-brightgreen.svg) TLA web frontend. diff --git a/src/main/java/tla/web/model/Annotation.java b/src/main/java/tla/web/model/Annotation.java index cfc48fde..063aa0ab 100644 --- a/src/main/java/tla/web/model/Annotation.java +++ b/src/main/java/tla/web/model/Annotation.java @@ -1,7 +1,6 @@ package tla.web.model; import java.util.Collection; -import java.util.Collections; import java.util.List; import lombok.AccessLevel; @@ -41,11 +40,11 @@ public String getName() { * Escapes markup. */ public String getBody() { + if (this.body == null) { + this.body = this.extractBody(); + } return Util.escapeMarkup( - String.join( - "\n\n", - this.body != null ? this.body : this.extractBody() - ) + String.join("\n\n", this.body) ); } @@ -53,23 +52,24 @@ public String getBody() { * Try to extract text content from "annotation.lemma" nodes in the annotation's passport. */ private Collection extractBody() { - if (this.getPassport() != null) { - List nodes = this.getPassport().extractProperty( - "annotation.lemma" - ); - if (nodes != null) { - return nodes.stream().filter( - node -> { - return !node.isEmpty() && !node.getLeafNodeValue().isBlank(); - } - ).map( - Passport::getLeafNodeValue - ).map( - String::trim - ).toList(); - } + if (this.getPassport() == null) { + return List.of(); } - return Collections.emptyList(); + List nodes = this.getPassport().extractProperty( + "annotation.lemma" + ); + if (nodes == null) { + return List.of(); + } + return nodes.stream().filter( + node -> { + return !node.isEmpty() && !node.getLeafNodeValue().isBlank(); + } + ).map( + Passport::getLeafNodeValue + ).map( + String::trim + ).toList(); } } \ No newline at end of file diff --git a/src/main/java/tla/web/model/Sentence.java b/src/main/java/tla/web/model/Sentence.java index 37007031..4f80d8a0 100644 --- a/src/main/java/tla/web/model/Sentence.java +++ b/src/main/java/tla/web/model/Sentence.java @@ -36,7 +36,7 @@ public class Sentence extends TLAObject implements Hierarchic { private Transcription transcription; - private Text text; + private Text text = Text.EMPTY; @Singular private SortedMap> translations; @@ -51,20 +51,20 @@ public boolean hasGlyphs() { } public String getName() { - return this.getText() != null ? this.getText().getName() : null; + return this.getText().getName(); } public String reviewState() { - return this.getText() != null ? this.getText().getReviewState() : "published"; + return this.getText().getReviewState(); } public EditorInfo getEdited() { - return this.getText() != null ? this.getText().getEdited() : null; + return this.getText().getEdited(); } @Override public List getPaths() { - return this.getText() != null ? this.getText().getPaths() : null; + return this.getText().getPaths(); } } diff --git a/src/main/java/tla/web/model/Text.java b/src/main/java/tla/web/model/Text.java index 8adba1dd..4f265aad 100644 --- a/src/main/java/tla/web/model/Text.java +++ b/src/main/java/tla/web/model/Text.java @@ -16,6 +16,8 @@ @TLADTO(TextDto.class) public class Text extends CorpusObject { + public static final Text EMPTY = new Text(); + private TextDto.WordCount wordCount; } diff --git a/src/main/java/tla/web/model/mappings/MappingConfig.java b/src/main/java/tla/web/model/mappings/MappingConfig.java index 5c3ee30b..55340da4 100644 --- a/src/main/java/tla/web/model/mappings/MappingConfig.java +++ b/src/main/java/tla/web/model/mappings/MappingConfig.java @@ -7,7 +7,6 @@ import org.modelmapper.ModelMapper; import org.modelmapper.TypeMap; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -55,7 +54,6 @@ public class MappingConfig { private ExternalReferencesConverter externalReferencesConverter; - @Autowired public MappingConfig(ExternalReferencesConverter externalReferencesConverter) { this.externalReferencesConverter = externalReferencesConverter; } diff --git a/src/main/java/tla/web/model/parts/Transcription.java b/src/main/java/tla/web/model/parts/Transcription.java index aad2a291..a1f87c39 100644 --- a/src/main/java/tla/web/model/parts/Transcription.java +++ b/src/main/java/tla/web/model/parts/Transcription.java @@ -2,13 +2,11 @@ import lombok.Getter; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.NoArgsConstructor; import lombok.Setter; @Getter @Setter -@Builder @NoArgsConstructor @AllArgsConstructor public class Transcription {