diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/common/api/DisplayEntry.java b/src/main/java/de/numcodex/feasibility_gui_backend/common/api/DisplayEntry.java new file mode 100644 index 00000000..6fdb68d7 --- /dev/null +++ b/src/main/java/de/numcodex/feasibility_gui_backend/common/api/DisplayEntry.java @@ -0,0 +1,33 @@ +package de.numcodex.feasibility_gui_backend.common.api; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import de.numcodex.feasibility_gui_backend.dse.api.LocalizedValue; +import de.numcodex.feasibility_gui_backend.terminology.es.model.Display; +import lombok.Builder; + +import java.util.List; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@Builder +public record DisplayEntry( + @JsonProperty String original, + @JsonProperty List translations + ) { + + public static DisplayEntry of(Display display) { + return DisplayEntry.builder() + .original(display.original()) + .translations(List.of( + LocalizedValue.builder() + .language("de-DE") + .value(display.deDe()) + .build(), + LocalizedValue.builder() + .language("en-US") + .value(display.enUs()) + .build() + )) + .build(); + } +} diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/dse/api/DisplayEntry.java b/src/main/java/de/numcodex/feasibility_gui_backend/dse/api/DisplayEntry.java deleted file mode 100644 index 2fae710f..00000000 --- a/src/main/java/de/numcodex/feasibility_gui_backend/dse/api/DisplayEntry.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.numcodex.feasibility_gui_backend.dse.api; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; - -import java.util.List; - -@JsonInclude(JsonInclude.Include.NON_NULL) -@Builder -public record DisplayEntry( - @JsonProperty String original, - @JsonProperty List translations - ) { -} diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/dse/api/DseProfile.java b/src/main/java/de/numcodex/feasibility_gui_backend/dse/api/DseProfile.java index 0ff50e78..c593f6ac 100644 --- a/src/main/java/de/numcodex/feasibility_gui_backend/dse/api/DseProfile.java +++ b/src/main/java/de/numcodex/feasibility_gui_backend/dse/api/DseProfile.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import de.numcodex.feasibility_gui_backend.common.api.DisplayEntry; import lombok.Builder; import java.util.List; diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/dse/api/DseProfileTreeNode.java b/src/main/java/de/numcodex/feasibility_gui_backend/dse/api/DseProfileTreeNode.java index 4e8f9192..565e1e54 100644 --- a/src/main/java/de/numcodex/feasibility_gui_backend/dse/api/DseProfileTreeNode.java +++ b/src/main/java/de/numcodex/feasibility_gui_backend/dse/api/DseProfileTreeNode.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import de.numcodex.feasibility_gui_backend.common.api.DisplayEntry; import lombok.Builder; import java.util.List; diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/dse/api/Field.java b/src/main/java/de/numcodex/feasibility_gui_backend/dse/api/Field.java index a9312877..eff12544 100644 --- a/src/main/java/de/numcodex/feasibility_gui_backend/dse/api/Field.java +++ b/src/main/java/de/numcodex/feasibility_gui_backend/dse/api/Field.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import de.numcodex.feasibility_gui_backend.common.api.DisplayEntry; import lombok.Builder; import java.util.List; diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/api/CcSearchResult.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/api/CcSearchResult.java index 599c1905..52f9366d 100644 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/api/CcSearchResult.java +++ b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/api/CcSearchResult.java @@ -10,5 +10,5 @@ @Builder public class CcSearchResult { private long totalHits; - private List results; + private List results; } diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/api/CodeableConceptEntry.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/api/CodeableConceptEntry.java new file mode 100644 index 00000000..936e6b2f --- /dev/null +++ b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/api/CodeableConceptEntry.java @@ -0,0 +1,35 @@ +package de.numcodex.feasibility_gui_backend.terminology.api; + +import de.numcodex.feasibility_gui_backend.common.api.TermCode; +import de.numcodex.feasibility_gui_backend.common.api.DisplayEntry; +import de.numcodex.feasibility_gui_backend.dse.api.LocalizedValue; +import de.numcodex.feasibility_gui_backend.terminology.es.model.CodeableConceptDocument; +import lombok.Builder; + +import java.util.List; + +@Builder +public record CodeableConceptEntry( + TermCode termCode, + DisplayEntry display +) { + public static CodeableConceptEntry of(CodeableConceptDocument document) { + return CodeableConceptEntry.builder() + .termCode(document.termCode()) + .display(DisplayEntry.builder() + .original(document.display().original()) + .translations(List.of( + LocalizedValue.builder() + .language("de-DE") + .value(document.display().deDe()) + .build(), + LocalizedValue.builder() + .language("en-US") + .value(document.display().enUs()) + .build() + )) + .build() + ) + .build(); + } +} diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/api/EsSearchResultEntry.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/api/EsSearchResultEntry.java index 36a828cb..46453ae1 100644 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/api/EsSearchResultEntry.java +++ b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/api/EsSearchResultEntry.java @@ -1,12 +1,13 @@ package de.numcodex.feasibility_gui_backend.terminology.api; +import de.numcodex.feasibility_gui_backend.common.api.DisplayEntry; import de.numcodex.feasibility_gui_backend.terminology.es.model.OntologyListItemDocument; import lombok.Builder; @Builder public record EsSearchResultEntry( String id, - String name, + DisplayEntry display, int availability, String context, String terminology, @@ -17,7 +18,7 @@ public record EsSearchResultEntry( public static EsSearchResultEntry of(OntologyListItemDocument ontologyListItemDocument) { return EsSearchResultEntry.builder() .id(ontologyListItemDocument.id()) - .name(ontologyListItemDocument.name()) + .display(DisplayEntry.of(ontologyListItemDocument.display())) .availability(ontologyListItemDocument.availability()) .context(ontologyListItemDocument.context().code()) .terminology(ontologyListItemDocument.terminology()) diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/CodeableConceptService.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/CodeableConceptService.java index a4d97f63..9e0ceceb 100644 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/CodeableConceptService.java +++ b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/CodeableConceptService.java @@ -2,8 +2,8 @@ import co.elastic.clients.elasticsearch._types.FieldValue; import co.elastic.clients.elasticsearch._types.query_dsl.*; -import de.numcodex.feasibility_gui_backend.common.api.TermCode; import de.numcodex.feasibility_gui_backend.terminology.api.CcSearchResult; +import de.numcodex.feasibility_gui_backend.terminology.api.CodeableConceptEntry; import de.numcodex.feasibility_gui_backend.terminology.es.model.CodeableConceptDocument; import de.numcodex.feasibility_gui_backend.terminology.es.repository.CodeableConceptEsRepository; import de.numcodex.feasibility_gui_backend.terminology.es.repository.OntologyItemNotFoundException; @@ -47,17 +47,18 @@ public CcSearchResult performCodeableConceptSearchWithRepoAndPaging(String keywo } var searchHitPage = findByCodeOrDisplay(keyword, filterList, PageRequest.of(page, pageSize)); - List codeableConceptEntries = new ArrayList<>(); + List codeableConceptEntries = new ArrayList<>(); - searchHitPage.getSearchHits().forEach(hit -> codeableConceptEntries.add(hit.getContent().termCode())); + searchHitPage.getSearchHits().forEach(hit -> codeableConceptEntries.add(CodeableConceptEntry.of(hit.getContent()))); return CcSearchResult.builder() .totalHits(searchHitPage.getTotalHits()) .results(codeableConceptEntries) .build(); } - public TermCode getSearchResultEntryByCode(String code) { - return repo.findById(code).orElseThrow(OntologyItemNotFoundException::new).termCode(); + public CodeableConceptEntry getSearchResultEntryByCode(String code) { + var document = repo.findById(code).orElseThrow(OntologyItemNotFoundException::new); + return CodeableConceptEntry.of(document); } private SearchHits findByCodeOrDisplay(String keyword, @@ -88,7 +89,7 @@ private SearchHits findByCodeOrDisplay(String keyword, } else { var mmQuery = new MultiMatchQuery.Builder() .query(keyword) - .fields(List.of("termcode.display", "termcode.code^2")) + .fields(List.of("display.de-DE", "display.en-US", "termcode.code^2")) .build(); boolQuery = new BoolQuery.Builder() diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/TerminologyEsService.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/TerminologyEsService.java index 6c54ee55..e7a1d061 100644 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/TerminologyEsService.java +++ b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/TerminologyEsService.java @@ -150,7 +150,7 @@ private SearchHits findByNameOrTermcode(String keyword } else { var mmQuery = new MultiMatchQuery.Builder() .query(keyword) - .fields(List.of("name", "termcode^2")) + .fields(List.of("display.de-DE", "display.en-US", "termcode^2")) .build(); boolQuery = new BoolQuery.Builder() @@ -196,7 +196,7 @@ private SearchHits findByNameOrTermcode(String keyword public OntologyItemRelationsDocument getOntologyItemRelationsByHash(String hash) { var ontologyItem = ontologyItemEsRepository.findById(hash).orElseThrow(OntologyItemNotFoundException::new); return OntologyItemRelationsDocument.builder() - .translations(ontologyItem.translations()) + .display(ontologyItem.display()) .parents(ontologyItem.parents()) .children(ontologyItem.children()) .relatedTerms(ontologyItem.relatedTerms()) diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/CodeableConceptDocument.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/CodeableConceptDocument.java index 45aa9d9f..5b01ff03 100644 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/CodeableConceptDocument.java +++ b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/CodeableConceptDocument.java @@ -16,6 +16,8 @@ public record CodeableConceptDocument( @Field(name = "termcode") TermCode termCode, @Field(name = "value_sets") - List valueSets + List valueSets, + @Field(name = "display") + Display display ) { } diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/Display.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/Display.java new file mode 100644 index 00000000..0b37d69c --- /dev/null +++ b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/Display.java @@ -0,0 +1,14 @@ +package de.numcodex.feasibility_gui_backend.terminology.es.model; + +import lombok.Builder; +import org.springframework.data.elasticsearch.annotations.Field; + +@Builder +public record Display( + String original, + @Field(name = "de-De") + String deDe, + @Field(name = "en-Us") + String enUs +) { +} diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/OntologyItemDocument.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/OntologyItemDocument.java index dd8ceebd..997df07b 100644 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/OntologyItemDocument.java +++ b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/OntologyItemDocument.java @@ -13,15 +13,14 @@ @Document(indexName = "ontology") public record OntologyItemDocument( @Id String id, - String name, int availability, TermCode context, String terminology, String termcode, - @Field(name = "kds_module") String kdsModule, - - @Field(name = "translations") - Collection translations, + @Field(name = "display") + Display display, + @Field(name = "kds_module") + String kdsModule, @Field(name = "parents") Collection parents, @Field(name = "children") diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/OntologyItemRelationsDocument.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/OntologyItemRelationsDocument.java index c4ec5dbe..7e0133aa 100644 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/OntologyItemRelationsDocument.java +++ b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/OntologyItemRelationsDocument.java @@ -10,8 +10,8 @@ @Builder @Document(indexName = "ontology") public record OntologyItemRelationsDocument( - @Field(name = "translations") - Collection translations, + @Field(name = "display") + Display display, @Field(name = "parents") Collection parents, @Field(name = "children") diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/OntologyListItemDocument.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/OntologyListItemDocument.java index 629f7173..661a4986 100644 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/OntologyListItemDocument.java +++ b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/OntologyListItemDocument.java @@ -10,7 +10,7 @@ @Document(indexName = "ontology") public record OntologyListItemDocument( @Id String id, - String name, + Display display, int availability, TermCode context, String terminology, diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/Translation.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/Translation.java deleted file mode 100644 index 035221dc..00000000 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/es/model/Translation.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.numcodex.feasibility_gui_backend.terminology.es.model; - -import lombok.Builder; - -@Builder -public record Translation( - String lang, - String value -) { -} diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/v4/CodeableConceptRestController.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/v4/CodeableConceptRestController.java index 792e542b..461da20b 100644 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/v4/CodeableConceptRestController.java +++ b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/v4/CodeableConceptRestController.java @@ -1,7 +1,7 @@ package de.numcodex.feasibility_gui_backend.terminology.v4; -import de.numcodex.feasibility_gui_backend.common.api.TermCode; import de.numcodex.feasibility_gui_backend.terminology.api.CcSearchResult; +import de.numcodex.feasibility_gui_backend.terminology.api.CodeableConceptEntry; import de.numcodex.feasibility_gui_backend.terminology.es.CodeableConceptService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; @@ -34,7 +34,7 @@ public CcSearchResult searchOntologyItemsCriteriaQuery(@RequestParam("searchterm } @GetMapping(value = "/entry/{code}", produces = MediaType.APPLICATION_JSON_VALUE) - public TermCode getCodeableConceptByCode(@PathVariable("code") String code) { + public CodeableConceptEntry getCodeableConceptByCode(@PathVariable("code") String code) { return codeableConceptService.getSearchResultEntryByCode(code); } } diff --git a/src/test/java/de/numcodex/feasibility_gui_backend/dse/DseServiceTest.java b/src/test/java/de/numcodex/feasibility_gui_backend/dse/DseServiceTest.java index a23cf6b1..0bd4a08c 100644 --- a/src/test/java/de/numcodex/feasibility_gui_backend/dse/DseServiceTest.java +++ b/src/test/java/de/numcodex/feasibility_gui_backend/dse/DseServiceTest.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; -import de.numcodex.feasibility_gui_backend.dse.api.DisplayEntry; +import de.numcodex.feasibility_gui_backend.common.api.DisplayEntry; import de.numcodex.feasibility_gui_backend.dse.api.DseProfileTreeNode; import de.numcodex.feasibility_gui_backend.dse.api.LocalizedValue; import de.numcodex.feasibility_gui_backend.dse.persistence.DseProfile; diff --git a/src/test/java/de/numcodex/feasibility_gui_backend/dse/v4/DseRestControllerIT.java b/src/test/java/de/numcodex/feasibility_gui_backend/dse/v4/DseRestControllerIT.java index f3932f74..78bb530b 100644 --- a/src/test/java/de/numcodex/feasibility_gui_backend/dse/v4/DseRestControllerIT.java +++ b/src/test/java/de/numcodex/feasibility_gui_backend/dse/v4/DseRestControllerIT.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import de.numcodex.feasibility_gui_backend.dse.DseService; -import de.numcodex.feasibility_gui_backend.dse.api.DisplayEntry; +import de.numcodex.feasibility_gui_backend.common.api.DisplayEntry; import de.numcodex.feasibility_gui_backend.dse.api.DseProfile; import de.numcodex.feasibility_gui_backend.dse.api.DseProfileTreeNode; import de.numcodex.feasibility_gui_backend.dse.api.LocalizedValue;