Commit 50240cab authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Add extra institutions fields to fields.

parent 1a09f438
Pipeline #24678 passed with stages
in 5 minutes and 5 seconds
......@@ -342,6 +342,10 @@ class DocumentsSearchDocBuilder(
.flatMap { it.toList() },
callNumber = Extract.typedEntityByType(physicalIdentifiers, "type", "callNumber", "identifier")
.flatMap { it.toList() },
accessInstitution = elasticSearchWrapper.getExtraInstitutionsFromRecordSet(recordSetId, "access"),
originalInstitution = elasticSearchWrapper.getExtraInstitutionsFromRecordSet(recordSetId, "original"),
masterInstitution = elasticSearchWrapper.getExtraInstitutionsFromRecordSet(recordSetId, "master"),
published = (record[KEYS.isPublished] as Boolean?) ?: false,
suggest = suggestContainerBuilder.build()[0]
)
......
......@@ -206,4 +206,38 @@ class ElasticSearchWrapper(
LanguageContainer.EMPTY
}
}
fun getExtraInstitutionsFromRecordSet(identifier: String, extraType: String): List<FacetContainer> {
return try {
log.debug("Attempting to retrieve record set document from $recordSetIndex.")
val request = GetRequest(recordSetIndex, identifier)
val response = client.get(request, RequestOptions.DEFAULT)
if (response.isExists) {
when (val map = response.sourceAsMap["${extraType}Institution"]) {
is List<*> -> {
log.debug("Retrieval of '${extraType}Institution' was successful.")
map.map { FacetContainer.fromMap(it) }
}
null -> {
log.error("Found record set for id $identifier in $recordSetIndex, but could not retrieve names in field '${extraType}Institution'.")
emptyList()
}
is Map<*, *> -> {
log.debug("Retrieval of '${extraType}Institution' was successful.")
listOf(FacetContainer.fromMap(map))
}
else -> {
log.error("Found record set for id $identifier in $recordSetIndex, but could not retrieve names in field '${extraType}Institution'.")
emptyList()
}
}
} else {
log.error("Could not find record set $identifier in index $recordSetIndex.")
emptyList()
}
} catch (ex: ElasticsearchException) {
log.error(ex.detailedMessage)
emptyList()
}
}
}
\ No newline at end of file
......@@ -113,6 +113,10 @@ data class DocumentsSearchDoc(
// Combined Physical & Digital
val access: List<FacetContainer>,
val accessInstitution: List<FacetContainer>,
val originalInstitution: List<FacetContainer>,
val masterInstitution: List<FacetContainer>,
// internal fields
val published: Boolean,
......@@ -192,6 +196,9 @@ data class DocumentsSearchDoc(
emptyList(),
emptyList(),
emptyList(),
emptyList(),
emptyList(),
emptyList(),
false,
SuggestContainer(emptyList(), emptyList(), emptyList(), emptyList())
)
......
......@@ -46,5 +46,32 @@ data class FacetContainer(
listOf(placeholder)
)
}
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"))
}
else -> EMPTY
}
}
private fun extractMapItem(map: Map<String, Any?>, language: String): List<String> {
return when (val item = map[language]) {
is String -> listOf(item)
is List<*> ->
try {
item as List<String>
} catch (ex: ClassCastException) {
emptyList<String>()
}
else -> emptyList()
}
}
}
}
......@@ -51,6 +51,9 @@ class IntegrationTest {
val internal = mockk<ElasticSearchWrapper>()
every { internal.getRecordSetName("soz-004") } returns LanguageContainer.placeholder("soz-004")
every { internal.getInstitutionName("soz") } returns FacetContainer.placeholder("soz")
every { internal.getExtraInstitutionsFromRecordSet("soz-004", "access") } returns emptyList()
every { internal.getExtraInstitutionsFromRecordSet("soz-004", "original") } returns emptyList()
every { internal.getExtraInstitutionsFromRecordSet("soz-004", "master") } returns emptyList()
internal
}
......
......@@ -25,6 +25,9 @@ class TestDocumentsSearchDoc {
private val elasticSearchWrapperMocked = run {
val internal = mockk<ElasticSearchWrapper>()
every { internal.getRecordSetName("") } returns LanguageContainer.EMPTY
every { internal.getExtraInstitutionsFromRecordSet("", "access") } returns emptyList()
every { internal.getExtraInstitutionsFromRecordSet("", "original") } returns emptyList()
every { internal.getExtraInstitutionsFromRecordSet("", "master") } returns emptyList()
internal
}
......
......@@ -18,6 +18,9 @@ class TestTransform {
private val elasticSearchWrapperMocked = run {
val internal = mockk<ElasticSearchWrapper>()
every { internal.getRecordSetName("") } returns LanguageContainer.EMPTY
every { internal.getExtraInstitutionsFromRecordSet("", "access") } returns emptyList()
every { internal.getExtraInstitutionsFromRecordSet("", "original") } returns emptyList()
every { internal.getExtraInstitutionsFromRecordSet("", "master") } returns emptyList()
internal
}
......
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