From bbdf144cabc2d9fb1a4a75b7583e23d9f8beda57 Mon Sep 17 00:00:00 2001 From: Michael Folz Date: Tue, 14 Jan 2025 17:11:39 +0100 Subject: [PATCH] #382 - Change display and translations structure for criteria and concepts - use correct onto tag in integration test - fix display entry for ontology item relations --- .github/workflows/ci.yml | 2 +- .../terminology/api/RelationEntry.java | 26 +++++++++++++++++++ .../terminology/es/TerminologyEsService.java | 6 +++-- .../v4/TerminologyRestController.java | 21 +++++++-------- .../es/TerminologyEsServiceIT.java | 4 +-- .../es/TerminologyEsServiceTest.java | 8 +++--- .../v4/TerminologyRestControllerIT.java | 4 +-- 7 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 src/main/java/de/numcodex/feasibility_gui_backend/terminology/api/RelationEntry.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8f8d7bd..7ff452bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -148,7 +148,7 @@ jobs: needs: tests runs-on: ubuntu-latest env: - ONTOLOGY_GIT_TAG: v3.0.1 + ONTOLOGY_GIT_TAG: v3.0.2-alpha ELASTIC_HOST: http://localhost:9200 ELASTIC_FILEPATH: https://github.com/medizininformatik-initiative/fhir-ontology-generator/releases/download/TAGPLACEHOLDER/ ELASTIC_FILENAME: elastic.zip diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/api/RelationEntry.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/api/RelationEntry.java new file mode 100644 index 00000000..46edb6d2 --- /dev/null +++ b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/api/RelationEntry.java @@ -0,0 +1,26 @@ +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.OntologyItemRelationsDocument; +import de.numcodex.feasibility_gui_backend.terminology.es.model.Relative; +import lombok.Builder; + +import java.util.Collection; + +@Builder +public record RelationEntry( + DisplayEntry display, + Collection parents, + Collection children, + Collection relatedTerms +) { + + public static RelationEntry of(OntologyItemRelationsDocument document) { + return RelationEntry.builder() + .display(DisplayEntry.of(document.display())) + .parents(document.parents()) + .children(document.children()) + .relatedTerms(document.relatedTerms()) + .build(); + } +} 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 c7d62e70..1f014d8a 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 @@ -7,6 +7,7 @@ import co.elastic.clients.elasticsearch._types.query_dsl.*; import de.numcodex.feasibility_gui_backend.terminology.api.EsSearchResult; import de.numcodex.feasibility_gui_backend.terminology.api.EsSearchResultEntry; +import de.numcodex.feasibility_gui_backend.terminology.api.RelationEntry; import de.numcodex.feasibility_gui_backend.terminology.es.model.*; import de.numcodex.feasibility_gui_backend.terminology.es.repository.OntologyItemEsRepository; import de.numcodex.feasibility_gui_backend.terminology.es.repository.OntologyItemNotFoundException; @@ -191,14 +192,15 @@ private SearchHits findByNameOrTermcode(String keyword } - public OntologyItemRelationsDocument getOntologyItemRelationsByHash(String hash) { + public RelationEntry getRelationEntryByHash(String hash) { var ontologyItem = ontologyItemEsRepository.findById(hash).orElseThrow(OntologyItemNotFoundException::new); - return OntologyItemRelationsDocument.builder() + var ontologyItemRelationsDocument = OntologyItemRelationsDocument.builder() .display(ontologyItem.display()) .parents(ontologyItem.parents()) .children(ontologyItem.children()) .relatedTerms(ontologyItem.relatedTerms()) .build(); + return RelationEntry.of(ontologyItemRelationsDocument); } diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/v4/TerminologyRestController.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/v4/TerminologyRestController.java index ba6ef2e5..10a33fb1 100644 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/v4/TerminologyRestController.java +++ b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/v4/TerminologyRestController.java @@ -4,7 +4,6 @@ import de.numcodex.feasibility_gui_backend.terminology.TerminologyService; import de.numcodex.feasibility_gui_backend.terminology.api.*; import de.numcodex.feasibility_gui_backend.terminology.es.TerminologyEsService; -import de.numcodex.feasibility_gui_backend.terminology.es.model.OntologyItemRelationsDocument; import de.numcodex.feasibility_gui_backend.terminology.es.model.TermFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; @@ -51,14 +50,14 @@ public List getAvailableFilters() { } @GetMapping("entry/search") - public EsSearchResult searchOntologyItemsCriteriaQuery2(@RequestParam("searchterm") String keyword, - @RequestParam(value = "criteria-sets", required = false) List criteriaSets, - @RequestParam(value = "contexts", required = false) List contexts, - @RequestParam(value = "kds-modules", required = false) List kdsModules, - @RequestParam(value = "terminologies", required = false) List terminologies, - @RequestParam(value = "availability", required = false, defaultValue = "false") boolean availability, - @RequestParam(value = "page-size", required = false, defaultValue = "20") int pageSize, - @RequestParam(value = "page", required = false, defaultValue = "0") int page) { + public EsSearchResult searchOntologyItemsCriteriaQuery(@RequestParam("searchterm") String keyword, + @RequestParam(value = "criteria-sets", required = false) List criteriaSets, + @RequestParam(value = "contexts", required = false) List contexts, + @RequestParam(value = "kds-modules", required = false) List kdsModules, + @RequestParam(value = "terminologies", required = false) List terminologies, + @RequestParam(value = "availability", required = false, defaultValue = "false") boolean availability, + @RequestParam(value = "page-size", required = false, defaultValue = "20") int pageSize, + @RequestParam(value = "page", required = false, defaultValue = "0") int page) { return terminologyEsService @@ -66,8 +65,8 @@ public EsSearchResult searchOntologyItemsCriteriaQuery2(@RequestParam("searchter } @GetMapping("entry/{hash}/relations") - public OntologyItemRelationsDocument getOntologyItemRelationsByHash(@PathVariable("hash") String hash) { - return terminologyEsService.getOntologyItemRelationsByHash(hash); + public RelationEntry getOntologyItemRelationsByHash(@PathVariable("hash") String hash) { + return terminologyEsService.getRelationEntryByHash(hash); } @GetMapping("entry/{hash}") diff --git a/src/test/java/de/numcodex/feasibility_gui_backend/terminology/es/TerminologyEsServiceIT.java b/src/test/java/de/numcodex/feasibility_gui_backend/terminology/es/TerminologyEsServiceIT.java index 0919222f..0021e271 100644 --- a/src/test/java/de/numcodex/feasibility_gui_backend/terminology/es/TerminologyEsServiceIT.java +++ b/src/test/java/de/numcodex/feasibility_gui_backend/terminology/es/TerminologyEsServiceIT.java @@ -169,7 +169,7 @@ void testGetSearchResultEntryByHash_throwsOnNotFound() { @Test void testGetSearchRelationsByHash_succeeds() { String entryId = "e2fcb288-0d08-3272-8f32-64b8f1cfe095"; - var relations = assertDoesNotThrow(() -> terminologyEsService.getOntologyItemRelationsByHash(entryId)); + var relations = assertDoesNotThrow(() -> terminologyEsService.getRelationEntryByHash(entryId)); assertThat(relations).isNotNull(); assertThat(relations.parents()).isNotNull(); assertThat(relations.parents()).isNotEmpty(); @@ -178,6 +178,6 @@ void testGetSearchRelationsByHash_succeeds() { @Test void testGetSearchRelationsByHash_throwsOnNotFound() { - assertThrows(OntologyItemNotFoundException.class, () -> terminologyEsService.getOntologyItemRelationsByHash("invalid-id")); + assertThrows(OntologyItemNotFoundException.class, () -> terminologyEsService.getRelationEntryByHash("invalid-id")); } } diff --git a/src/test/java/de/numcodex/feasibility_gui_backend/terminology/es/TerminologyEsServiceTest.java b/src/test/java/de/numcodex/feasibility_gui_backend/terminology/es/TerminologyEsServiceTest.java index 9838b7d5..6d23eef2 100644 --- a/src/test/java/de/numcodex/feasibility_gui_backend/terminology/es/TerminologyEsServiceTest.java +++ b/src/test/java/de/numcodex/feasibility_gui_backend/terminology/es/TerminologyEsServiceTest.java @@ -175,12 +175,12 @@ void testPerformOntologySearchWithRepoAndPaging_throwsOnInvalidPageSize() { } @Test - void testGetOntologyItemRelationsByHash_succeeds() { + void testGetRelationEntryByHash_succeeds() { String id = UUID.randomUUID().toString(); OntologyItemDocument dummyOntologyItem = createDummyOntologyItem(id); doReturn(Optional.of(dummyOntologyItem)).when(ontologyItemEsRepository).findById(any(String.class)); - var ontologyItemRelationsDocument = assertDoesNotThrow(() -> terminologyEsService.getOntologyItemRelationsByHash(id)); + var ontologyItemRelationsDocument = assertDoesNotThrow(() -> terminologyEsService.getRelationEntryByHash(id)); assertThat(ontologyItemRelationsDocument).isNotNull(); assertThat(ontologyItemRelationsDocument.relatedTerms()).isEqualTo(dummyOntologyItem.relatedTerms()); assertThat(ontologyItemRelationsDocument.children()).isEqualTo(dummyOntologyItem.children()); @@ -189,10 +189,10 @@ void testGetOntologyItemRelationsByHash_succeeds() { } @Test - void testGetOntologyItemRelationsByHash_throwsOnNotFound() { + void testGetRelationEntryByHash_throwsOnNotFound() { doReturn(Optional.empty()).when(ontologyItemEsRepository).findById(any(String.class)); - assertThrows(OntologyItemNotFoundException.class, () -> terminologyEsService.getOntologyItemRelationsByHash("id")); + assertThrows(OntologyItemNotFoundException.class, () -> terminologyEsService.getRelationEntryByHash("id")); } private OntologyListItemDocument createDummyOntologyListItem(String id) { diff --git a/src/test/java/de/numcodex/feasibility_gui_backend/terminology/v4/TerminologyRestControllerIT.java b/src/test/java/de/numcodex/feasibility_gui_backend/terminology/v4/TerminologyRestControllerIT.java index 9d60026e..2c6f52dd 100644 --- a/src/test/java/de/numcodex/feasibility_gui_backend/terminology/v4/TerminologyRestControllerIT.java +++ b/src/test/java/de/numcodex/feasibility_gui_backend/terminology/v4/TerminologyRestControllerIT.java @@ -155,7 +155,7 @@ public void testSearchOntologyItemsCriteriaQuery_failsOnUnauthorized() throws Ex @WithMockUser(roles = "DATAPORTAL_TEST_USER") public void testGetOntologyItemRelationsByHash_succeeds() throws Exception { var dummyOntologyItemRelations = createDummyOntologyItemRelations(); - doReturn(dummyOntologyItemRelations).when(terminologyEsService).getOntologyItemRelationsByHash(any(String.class)); + doReturn(dummyOntologyItemRelations).when(terminologyEsService).getRelationEntryByHash(any(String.class)); mockMvc.perform(get(URI.create(PATH_API + PATH_TERMINOLOGY + "/entry/abc/relations")).with(csrf())) .andExpect(status().isOk()) @@ -170,7 +170,7 @@ public void testGetOntologyItemRelationsByHash_succeeds() throws Exception { @Test public void testGetOntologyItemRelationsByHash_failsOnUnauthorized() throws Exception { var dummyOntologyItemRelations = createDummyOntologyItemRelations(); - doReturn(dummyOntologyItemRelations).when(terminologyEsService).getOntologyItemRelationsByHash(any(String.class)); + doReturn(dummyOntologyItemRelations).when(terminologyEsService).getRelationEntryByHash(any(String.class)); mockMvc.perform(get(URI.create(PATH_API + PATH_TERMINOLOGY + "/entry/abc/relations")).with(csrf())) .andExpect(status().isUnauthorized());