Commit 85197517 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Update institution containers for record sets

parent d06bee56
Pipeline #24585 passed with stages
in 5 minutes and 47 seconds
......@@ -22,7 +22,7 @@ targetCompatibility = 1.8
repositories {
jcenter()
maven {
url "https://dl.bintray.com/memoriav/memobase"
url "https://gitlab.switch.ch/api/v4/projects/1324/packages/maven"
}
}
......@@ -34,7 +34,7 @@ ext {
dependencies {
compile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-high-level-client', version: '7.6.1'
implementation 'org.memobase:memobase-service-utilities:2.0.15'
implementation 'org.memobase:memobase-service-utilities:2.0.16'
implementation 'org.apache.jena:apache-jena:3.14.0'
// Logging Framework
......
......@@ -39,6 +39,7 @@ import org.memobase.model.DocumentsSearchDoc
import org.memobase.model.InstitutionSearchDoc
import org.memobase.model.RecordSetSearchDoc
import org.memobase.model.Schema
import org.memobase.model.UpdateQuery
class KafkaTopology(
private val settings: SettingsLoader,
......@@ -183,11 +184,19 @@ class KafkaTopology(
.mapValues { value -> JSON.queryToJson(value!!) }
.to(updateTopic)
schema.map { key, value ->
recordSetUpdate(schema, "masterInstitution")
recordSetUpdate(schema, "originalInstitution")
recordSetUpdate(schema, "accessInstitution")
}
private fun recordSetUpdate(stream: KStream<String, Schema>, targetField: String) {
stream.map { key, value ->
when (value) {
is RecordSetSearchDoc -> KeyValue(
"$key#update",
updateQueryBuilder.updateAccessInstitutionContainer(value.id, value.accessInstitution)
updateInstitutionContainer(value, targetField)
)
else -> KeyValue(key, null)
}
......@@ -196,4 +205,24 @@ class KafkaTopology(
.mapValues { value -> JSON.queryToJson(value!!) }
.to(updateTopic)
}
private fun updateInstitutionContainer(recordSet: RecordSetSearchDoc, targetField: String): UpdateQuery {
return when (targetField) {
"masterInstitution" -> updateQueryBuilder.updateInstitutionContainers(
recordSet.id,
targetField,
recordSet.masterInstitution
)
"originalInstitution" -> updateQueryBuilder.updateInstitutionContainers(
recordSet.id,
targetField, recordSet.originalInstitution
)
"accessInstitution" -> updateQueryBuilder.updateInstitutionContainers(
recordSet.id,
targetField,
recordSet.accessInstitution
)
else -> throw Exception("Unknown institution type. Set the wrong constant somewhere...")
}
}
}
......@@ -51,13 +51,13 @@ class UpdateQueryBuilder {
)
}
fun updateAccessInstitutionContainer(recordSet: String, institution: List<FacetContainer>): UpdateQuery {
fun updateInstitutionContainers(recordSet: String, targetField: String, institutions: List<FacetContainer>): UpdateQuery {
return UpdateQuery(
recordSetFacetTerm,
recordSet,
"ctx._source['institutionsOnSite'] = params.containers",
"ctx._source['${targetField}'] = params.containers",
mapOf(
Pair("containers", institution)
Pair("containers", institutions)
)
)
}
......
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