Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
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
58952c37
Commit
58952c37
authored
Feb 16, 2021
by
Jonas Waeber
Browse files
Improve logging & exception handling of elastic functions.
parent
dde8a912
Pipeline
#21865
passed with stages
in 5 minutes and 17 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/main/kotlin/helpers/ElasticSearchWrapper.kt
View file @
58952c37
...
...
@@ -145,16 +145,26 @@ class ElasticSearchWrapper(
fun
getInstitutionName
(
identifier
:
String
):
FacetContainer
{
return
try
{
log
.
info
(
"Attempting to retrieve institution record."
)
log
.
debug
(
"Attempting to retrieve institution record."
)
val
request
=
GetRequest
(
institutionIndex
,
identifier
)
val
response
=
client
.
get
(
request
,
RequestOptions
.
DEFAULT
)
if
(
response
.
isExists
)
{
log
.
info
(
"Successfully retrieved institution name."
)
FacetContainer
(
LanguageContainer
.
fromMap
(
response
.
sourceAsMap
.
getValue
(
"name"
)),
identifier
,
emptyList
()
)
val
map
=
response
.
sourceAsMap
[
"name"
]
if
(
map
==
null
)
{
log
.
error
(
"Found institution for id $identifier in index $institutionIndex, but could not extract name."
)
FacetContainer
(
LanguageContainer
.
EMPTY
,
identifier
,
emptyList
()
)
}
else
{
log
.
debug
(
"Retrieval of institution names was successful."
)
FacetContainer
(
LanguageContainer
.
fromMap
(
map
),
identifier
,
emptyList
()
)
}
}
else
{
log
.
error
(
"Could not find institution $identifier in index $institutionIndex."
)
FacetContainer
(
...
...
@@ -163,8 +173,6 @@ class ElasticSearchWrapper(
emptyList
()
)
}
}
catch
(
ex
:
ElasticsearchException
)
{
log
.
error
(
ex
.
detailedMessage
)
FacetContainer
(
...
...
@@ -173,19 +181,22 @@ class ElasticSearchWrapper(
emptyList
()
)
}
}
fun
getRecordSetName
(
identifier
:
String
):
LanguageContainer
{
return
try
{
log
.
info
(
"Attempting to retrieve record set document from $recordSetIndex."
)
log
.
debug
(
"Attempting to retrieve record set document from $recordSetIndex."
)
val
request
=
GetRequest
(
recordSetIndex
,
identifier
)
val
response
=
client
.
get
(
request
,
RequestOptions
.
DEFAULT
)
if
(
response
.
isExists
)
{
val
map
=
response
.
sourceAsMap
.
getValue
(
"name"
)
log
.
info
(
"Successfully retrieved record set names: $map."
)
LanguageContainer
.
fromMap
(
map
)
val
map
=
response
.
sourceAsMap
[
"name"
]
if
(
map
==
null
)
{
log
.
error
(
"Found record set for id $identifier in $recordSetIndex, but could not retrieve names in field 'name'."
)
LanguageContainer
.
EMPTY
}
else
{
log
.
debug
(
"Retrieval of record set names was successful."
)
LanguageContainer
.
fromMap
(
map
)
}
}
else
{
log
.
error
(
"Could not find record set $identifier in index $recordSetIndex."
)
LanguageContainer
.
EMPTY
...
...
src/main/kotlin/model/LanguageContainer.kt
View file @
58952c37
...
...
@@ -41,21 +41,36 @@ data class LanguageContainer(
return
LanguageContainer
(
listOf
(
placeholder
),
listOf
(
placeholder
),
listOf
(
placeholder
),
listOf
(
placeholder
))
}
fun
fromMap
(
map
:
Any
):
LanguageContainer
{
fun
fromMap
(
map
:
Any
?
):
LanguageContainer
{
return
when
(
map
)
{
is
Map
<
*
,
*
>
->
{
LanguageContainer
(
map
[
"de"
]
as
List
<
String
>,
map
[
"fr"
]
as
List
<
String
>,
map
[
"it"
]
as
List
<
String
>,
map
[
"un"
]
as
List
<
String
>
)
val
languageContainer
=
LanguageContainer
(
extractMapItem
(
map
as
Map
<
String
,
Any
?
>,
"de"
),
extractMapItem
(
map
,
"fr"
),
extractMapItem
(
map
,
"it"
),
extractMapItem
(
map
,
"unt"
)
)
languageContainer
}
else
->
EMPTY
}
}
private
fun
extractMapItem
(
map
:
Map
<
String
,
Any
?
>,
language
:
String
):
List
<
String
>
{
return
when
(
val
item
=
map
[
language
])
{
is
String
->
listOf
(
item
)
is
List
<
*
>
->
try
{
item
as
List
<
String
>
}
catch
(
ex
:
ClassCastException
)
{
emptyList
<
String
>()
}
else
->
emptyList
()
}
}
const
val
valueJsonLDFieldName
=
"@value"
const
val
languageJsonLDFieldName
=
"@language"
}
fun
add
(
value
:
Any
?):
LanguageContainer
{
...
...
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