Commit c32da60c authored by Jonas Waeber's avatar Jonas Waeber

Refactor constants and stuff

parent ec4a54d4
......@@ -21,8 +21,23 @@ package org.memobase
import ch.memobase.rdf.NS
import com.beust.klaxon.JsonObject
import org.apache.logging.log4j.LogManager
import org.memobase.builders.*
import org.memobase.helpers.*
import org.memobase.builders.AgentContainerBuilder
import org.memobase.builders.DateContainerBuilder
import org.memobase.builders.EnrichedFacetContainerBuilder
import org.memobase.builders.FacettedContainerBuilder
import org.memobase.builders.IFieldBuilder
import org.memobase.builders.PersonFacetBuilder
import org.memobase.builders.PlaceFacetBuilder
import org.memobase.builders.SuggestContainerBuilder
import org.memobase.helpers.AspectRatio
import org.memobase.helpers.DocumentTypeMapper
import org.memobase.helpers.Extract
import org.memobase.helpers.FacetBuildHelpers
import org.memobase.helpers.Filter
import org.memobase.helpers.InstitutionAndRecordSetExtractionHelper.extractInstitution
import org.memobase.helpers.InstitutionAndRecordSetExtractionHelper.extractRecordSet
import org.memobase.helpers.KEYS
import org.memobase.helpers.ReuseStatementMap
import org.memobase.model.DocumentsSearchDoc
import org.memobase.model.EnrichedDigitalMetadata
import org.memobase.model.LanguageContainer
......@@ -201,8 +216,8 @@ class DocumentsSearchDocBuilder(
sameAs = Extract.listOfStrings(record["sameAs"]),
abstract = Extract.languageContainer("abstract", record["abstract"]),
recordId = id,
institution = Meta.extractInstitution(record),
recordSet = Meta.extractRecordSet(record),
institution = extractInstitution(record),
recordSet = extractRecordSet(record),
descriptiveNote = Extract.languageContainer("descriptiveNote", record["descriptiveNote"]),
scopeAndContent = Extract.languageContainer("scopeAndContent", record["scopeAndContent"]),
relatedMaterial = Extract.languageContainer("relation", record["relation"]),
......
......@@ -33,7 +33,6 @@ import org.memobase.helpers.DocumentTypeMapper
import org.memobase.helpers.ElasticSearchWrapper
import org.memobase.helpers.InstitutionTypeMapper
import org.memobase.helpers.JSON
import org.memobase.helpers.KEYS
import org.memobase.helpers.KEYS.SettingsProps
import org.memobase.model.DocumentsSearchDoc
import org.memobase.model.InstitutionSearchDoc
......@@ -69,9 +68,9 @@ class KafkaTopology(private val settings: SettingsLoader) {
.filter { _, value -> value.isNotEmpty() }
.mapValues { value -> JSON.unpack(value) }
.branch(
Predicate { _, value -> value.containsKey(JSON.record) },
Predicate { _, value -> value.containsKey(JSON.institution) },
Predicate { _, value -> value.containsKey(JSON.recordSet) },
Predicate { _, value -> value.containsKey(JSON.recordTag) },
Predicate { _, value -> value.containsKey(JSON.institutionTag) },
Predicate { _, value -> value.containsKey(JSON.recordSetTag) },
Predicate { _, _ -> true }
)
......
......@@ -53,7 +53,7 @@ object Filter {
}
}
is JsonObject ->
when (val newValue = fullGraph[it["@id"]]) {
when (val newValue = fullGraph[it[KEYS.entityId]]) {
is JsonObject -> listOf(newValue)
else -> {
log.error("Could not extract json-object from entity $it in property $sourceProperty.")
......@@ -64,16 +64,16 @@ object Filter {
it.mapNotNull { child ->
when (child) {
is String -> fullGraph[child]
is JsonObject -> fullGraph[child["@id"]]
is JsonObject -> fullGraph[child[KEYS.entityId]]
else -> null
}
}
null -> {
log.info("Property $sourceProperty is not defined in resource ${sourceResource["@id"]}.")
log.info("Property $sourceProperty is not defined in resource ${sourceResource[KEYS.entityId]}.")
emptyList()
}
else -> {
log.error("Unexpected JSON structure for property $sourceProperty in resource ${sourceResource["@id"]}.")
log.error("Unexpected JSON structure for property $sourceProperty in resource ${sourceResource[KEYS.entityId]}.")
emptyList()
}
}
......
......@@ -24,9 +24,9 @@ import org.memobase.model.FacetContainer
import org.memobase.model.LanguageContainer
/**
Extraction helpers for institutions and record sets.
* Extraction helpers for institutions and record sets.
*/
object Meta {
object InstitutionAndRecordSetExtractionHelper {
private val log = LogManager.getLogger("InstitutionAndRecordSetExtractionHelper")
fun extractInstitution(record: JsonObject): List<FacetContainer> {
......
......@@ -30,16 +30,13 @@ object JSON {
private val log = LogManager.getLogger("JsonParser")
private const val graph = "@graph"
private const val atId = "@id"
const val atType = "@type" // rdf:type
const val type = "type" // rico:type
private const val Record = "Record"
private const val RecordSet = "RecordSet"
private const val CorporateBody = "CorporateBody"
private const val memobaseInstitution = "memobaseInstitution"
const val institution = "institution"
const val record = "record"
const val recordSet = "recordSet"
private const val memobaseInstitutionType = "memobaseInstitution"
const val institutionTag = "institution"
const val recordTag = "record"
const val recordSetTag = "recordSet"
private val klaxon = Klaxon()
......@@ -55,14 +52,14 @@ object JSON {
fun unpack(input: JsonObject): Map<String, JsonObject> {
val graph = input[graph] as JsonArray<JsonObject>
return graph.map {
if (it[atType] == NS.rico + Record) {
Pair(record, it)
} else if (it[atType] == NS.rico + RecordSet) {
Pair(recordSet, it)
} else if (it[atType] == NS.rico + CorporateBody && it[type] == memobaseInstitution) {
Pair(institution, it)
if (it[KEYS.atType] == NS.rico + Record) {
Pair(recordTag, it)
} else if (it[KEYS.atType] == NS.rico + RecordSet) {
Pair(recordSetTag, it)
} else if (it[KEYS.atType] == NS.rico + CorporateBody && it[KEYS.ricoType] == memobaseInstitutionType) {
Pair(institutionTag, it)
} else {
Pair(it[atId] as String, it)
Pair(it[KEYS.entityId] as String, it)
}
}.toMap()
}
......
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