Commit 269f8e04 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Prevent crash on persons & relations without names.

parent 4d427842
Pipeline #16164 passed with stages
in 5 minutes and 51 seconds
......@@ -19,10 +19,12 @@
package org.memobase.builders
import com.beust.klaxon.JsonObject
import org.apache.logging.log4j.LogManager
import org.memobase.KEYS
import org.memobase.helpers.Extract
import org.memobase.helpers.FacetBuildHelpers
import org.memobase.model.AgentWithRelationContainer
import org.memobase.model.LanguageContainer
import org.memobase.rdf.NS
class AgentContainerBuilder(
......@@ -31,7 +33,7 @@ class AgentContainerBuilder(
private val creationRelationType: String?,
private val inputMap: Map<String, JsonObject>
) : IFieldBuilder {
private val log = LogManager.getLogger("AgentContainerBuilder")
private val containers = mutableListOf<AgentWithRelationContainer>()
override fun filter(jsonObject: JsonObject): Boolean {
......@@ -51,15 +53,24 @@ class AgentContainerBuilder(
}
override fun append(jsonObject: JsonObject): String {
val name = Extract.languageContainer("agent-name", jsonObject[KEYS.name])
.reduce { acc, languageContainer -> acc.merge(languageContainer) }
val names = Extract.languageContainer("agent-name", jsonObject[KEYS.name])
val name = if (names.isNotEmpty())
names.reduce { acc, languageContainer -> acc.merge(languageContainer) }
else
LanguageContainer(emptyList(), emptyList(), emptyList(), listOf("NoNameFound"))
log.warn("Creation relation without names in agent ${jsonObject["@id"]}")
val relation = if (jsonObject.containsKey(KEYS.agentIsTargetOfCreationRelation)) {
val creationRelation = inputMap[jsonObject[KEYS.agentIsTargetOfCreationRelation]]
creationRelation.let {
if (it != null)
Extract.languageContainer("creation-relation-name", it["name"])
.reduce { acc, languageContainer -> acc.merge(languageContainer) }
else
if (it != null) {
val languages = Extract.languageContainer("creation-relation-name", it["name"])
if (languages.isNotEmpty())
languages.reduce { acc, languageContainer -> acc.merge(languageContainer) }
else {
log.warn("Creation relation without names in agent ${jsonObject["@id"]}")
LanguageContainer(emptyList(), emptyList(), emptyList(), emptyList())
}
} else
null
}
} else {
......
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