Commit 33602acd authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Fix facet container generation from map

parent 341ea9e9
Pipeline #25001 canceled with stages
in 1 minute and 54 seconds
......@@ -19,7 +19,6 @@
package org.memobase.model
import com.fasterxml.jackson.annotation.JsonInclude
import org.memobase.model.LanguageContainer.Companion
@JsonInclude(JsonInclude.Include.NON_EMPTY)
data class FacetContainer(
......@@ -50,19 +49,25 @@ data class FacetContainer(
fun fromMap(map: Any?): FacetContainer {
return when (map) {
is Map<*, *> -> {
val languageContainer = LanguageContainer(
extractMapItem(map as Map<String, Any?>, "de"),
extractMapItem(map, "fr"),
extractMapItem(map, "it"),
extractMapItem(map, "unt")
)
FacetContainer(languageContainer, null, extractMapItem(map, "facet"))
val languageContainer = if (map.containsKey("name")) {
val names = map["name"] as Map<String, Any?>
LanguageContainer(
extractMapItem(names, "de"),
extractMapItem(names, "fr"),
extractMapItem(names, "it"),
extractMapItem(names, "unt")
)
} else {
LanguageContainer.EMPTY
}
FacetContainer(languageContainer, null, extractMapItem(map as Map<String, Any?>, "filter"))
}
else -> EMPTY
}
}
private fun extractMapItem(map: Map<String, Any?>, language: String): List<String> {
return when (val item = map[language]) {
private fun extractMapItem(map: Map<String, Any?>, tag: String): List<String> {
return when (val item = map[tag]) {
is String -> listOf(item)
is List<*> ->
try {
......
......@@ -26,9 +26,9 @@ class TestElasticSearchWrapper {
private val log = LogManager.getLogger(TestElasticSearchWrapper::class.java)
private val host = "localhost"
private val port = 8080
private val documentsIndex = "documents-v17"
private val institutionIndex = "institutions-v1"
private val recordSetIndex = "record-sets-v1"
private val documentsIndex = "documents-v20"
private val institutionIndex = "institutions-v5"
private val recordSetIndex = "record-sets-v5"
private val client: RestHighLevelClient = connect()
......@@ -129,5 +129,37 @@ class TestElasticSearchWrapper {
)
}
)
} @Test
@Disabled
fun `test get original institutions from aag-001`() {
val wrapper = ElasticSearchWrapper(
client,
TestUtilities.translationMappers,
documentsIndex,
institutionIndex,
recordSetIndex
)
val results = wrapper.getExtraInstitutionsFromRecordSet("aag-001", "original")
assertAll("",
{
assertThat(results)
.hasSize(1)
},
{
assertThat(results[0])
.isEqualTo(
FacetContainer(
LanguageContainer(
listOf("Staatsarchiv des Kantons Aargau"),
listOf("Archives de l’Etat Argovie"),
listOf("Archivio cantonale del Argovia"),
emptyList()
),
null,
listOf("aag")
)
)
}
)
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment