Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
memoriav
Memobase 2020
services
Elasticsearch Services
Search Doc Service
Commits
269f8e04
Commit
269f8e04
authored
Oct 27, 2020
by
Jonas Waeber
Browse files
Prevent crash on persons & relations without names.
parent
4d427842
Pipeline
#16164
passed with stages
in 5 minutes and 51 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/main/kotlin/builders/AgentContainerBuilder.kt
View file @
269f8e04
...
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment