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 ...@@ -22,7 +22,7 @@ targetCompatibility = 1.8
repositories { repositories {
jcenter() jcenter()
maven { maven {
url "https://dl.bintray.com/memoriav/memobase" url "https://gitlab.switch.ch/api/v4/projects/1324/packages/maven"
} }
} }
...@@ -34,7 +34,7 @@ ext { ...@@ -34,7 +34,7 @@ ext {
dependencies { dependencies {
compile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-high-level-client', version: '7.6.1' 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' implementation 'org.apache.jena:apache-jena:3.14.0'
// Logging Framework // Logging Framework
......
...@@ -39,6 +39,7 @@ import org.memobase.model.DocumentsSearchDoc ...@@ -39,6 +39,7 @@ import org.memobase.model.DocumentsSearchDoc
import org.memobase.model.InstitutionSearchDoc import org.memobase.model.InstitutionSearchDoc
import org.memobase.model.RecordSetSearchDoc import org.memobase.model.RecordSetSearchDoc
import org.memobase.model.Schema import org.memobase.model.Schema
import org.memobase.model.UpdateQuery
class KafkaTopology( class KafkaTopology(
private val settings: SettingsLoader, private val settings: SettingsLoader,
...@@ -183,11 +184,19 @@ class KafkaTopology( ...@@ -183,11 +184,19 @@ class KafkaTopology(
.mapValues { value -> JSON.queryToJson(value!!) } .mapValues { value -> JSON.queryToJson(value!!) }
.to(updateTopic) .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) { when (value) {
is RecordSetSearchDoc -> KeyValue( is RecordSetSearchDoc -> KeyValue(
"$key#update", "$key#update",
updateQueryBuilder.updateAccessInstitutionContainer(value.id, value.accessInstitution) updateInstitutionContainer(value, targetField)
) )
else -> KeyValue(key, null) else -> KeyValue(key, null)
} }
...@@ -196,4 +205,24 @@ class KafkaTopology( ...@@ -196,4 +205,24 @@ class KafkaTopology(
.mapValues { value -> JSON.queryToJson(value!!) } .mapValues { value -> JSON.queryToJson(value!!) }
.to(updateTopic) .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 { ...@@ -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( return UpdateQuery(
recordSetFacetTerm, recordSetFacetTerm,
recordSet, recordSet,
"ctx._source['institutionsOnSite'] = params.containers", "ctx._source['${targetField}'] = params.containers",
mapOf( 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