Commit 56bc317a authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Documents can now properly get the full institution name list from the record set index.

parent 56338a33
...@@ -247,7 +247,7 @@ class DocumentsSearchDocBuilder( ...@@ -247,7 +247,7 @@ class DocumentsSearchDocBuilder(
sameAs = Extract.listOfStrings(record["sameAs"]), sameAs = Extract.listOfStrings(record["sameAs"]),
abstract = Extract.languageContainer("abstract (record id: $key)", record["abstract"]), abstract = Extract.languageContainer("abstract (record id: $key)", record["abstract"]),
recordId = key, recordId = key,
institution = extractInstitution(record).map { value -> elasticSearchWrapper.getInstitutionName(value) }, institution = elasticSearchWrapper.getInstitutionNamesFromRecordSet(recordSetId),
recordSet = FacetContainer( recordSet = FacetContainer(
elasticSearchWrapper.getRecordSetName(recordSetId), elasticSearchWrapper.getRecordSetName(recordSetId),
null, null,
......
...@@ -160,6 +160,61 @@ class ElasticSearchWrapper( ...@@ -160,6 +160,61 @@ class ElasticSearchWrapper(
} }
} }
/***
* This function exists because some record sets are managed by multiple institutions. However, the document itself
* always assumes that there is only one. As a result the institution names must be retrieved from the
* record set in that case.
*/
fun getInstitutionNamesFromRecordSet(recordSetIdentifier: String): List<FacetContainer> {
return try {
log.debug("Attempting to retrieve record set document.")
val request = GetRequest(recordSetIndex, recordSetIdentifier)
val response = client.get(request, RequestOptions.DEFAULT)
if (response.isExists) {
val map = response.sourceAsMap["institution"]
if (map == null) {
log.error("Found record set for id $recordSetIdentifier in " +
"index $recordSetIndex, but could not extract name.")
listOf(FacetContainer(
LanguageContainer.EMPTY,
recordSetIdentifier,
emptyList()
))
} else {
log.info("Retrieval of institution names was successful.")
when (map) {
is List<*> -> {
map.map {
FacetContainer.fromMap(it)
}
}
is Map<*, *> -> {
listOf(FacetContainer.fromMap(map))
}
else -> {
log.error("The retrieved data is not valid: $map.")
listOf(FacetContainer.EMPTY)
}
}
}
} else {
log.error("Could not find record set id $recordSetIdentifier in index $recordSetIndex.")
listOf(FacetContainer(
LanguageContainer.EMPTY,
recordSetIdentifier,
emptyList()
))
}
} catch (ex: ElasticsearchException) {
log.error(ex.detailedMessage)
listOf(FacetContainer(
LanguageContainer.EMPTY,
recordSetIdentifier,
emptyList()
))
}
}
fun getInstitutionName(identifier: String): FacetContainer { fun getInstitutionName(identifier: String): FacetContainer {
return try { return try {
log.debug("Attempting to retrieve institution record.") log.debug("Attempting to retrieve institution record.")
......
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