Commit 599efd4f authored by Jonas Waeber's avatar Jonas Waeber

Catch invalid date parser error.

parent 81553a90
Pipeline #16457 failed with stages
in 1 minute and 48 seconds
......@@ -78,6 +78,8 @@ class SearchDocTransform(private val mediaUrl: String) {
val digitalIdentifierReferences = Extract.identifiers(digitalObject?.get("identifiedBy"))
val digitalIdentifierEntities = mutableListOf<JsonObject>()
val id = record["@id"] as String
for (item in input.entries) {
for (builder: IFieldBuilder in listOf(
personFacetBuilder,
......@@ -106,7 +108,7 @@ class SearchDocTransform(private val mediaUrl: String) {
suggestContainerBuilder
)) {
if (builder.filter(item.value)) {
builder.append(item.value)
builder.append(id, item.value)
}
if (digitalIdentifierReferences.contains(item.key))
......@@ -114,7 +116,7 @@ class SearchDocTransform(private val mediaUrl: String) {
}
}
val id = record["@id"] as String
val recordIdentifiers = Filter.entitiesByProperty("identifiedBy", record, input)
val recordTitles = Filter.entitiesByProperty("hasTitle", record, input)
......
......@@ -52,7 +52,7 @@ class AgentContainerBuilder(
}
}
override fun append(jsonObject: JsonObject): String {
override fun append(key: String, jsonObject: JsonObject): String {
val names = Extract.languageContainer("agent-name", jsonObject[KEYS.name])
val name = if (names.isNotEmpty())
names.reduce { acc, languageContainer -> acc.merge(languageContainer) }
......
package org.memobase.builders
import com.beust.klaxon.JsonObject
import org.apache.logging.log4j.LogManager
import org.memobase.KEYS
import org.memobase.helpers.DateFacetBuildHelpers
import org.memobase.model.DateContainer
import org.memobase.rdf.NS
import java.lang.NumberFormatException
class DateContainerBuilder(private val containedIds: List<String>) : IFieldBuilder {
private val log = LogManager.getLogger("DateContainerBuilder")
private val dateContainers = mutableListOf<DateContainer>()
......@@ -17,7 +20,7 @@ class DateContainerBuilder(private val containedIds: List<String>) : IFieldBuild
false
}
override fun append(jsonObject: JsonObject): String {
override fun append(key: String, jsonObject: JsonObject): String {
val isNormalized = jsonObject.containsKey("normalizedDateValue")
val date = if (isNormalized) {
jsonObject["normalizedDateValue"] as String
......@@ -37,9 +40,16 @@ class DateContainerBuilder(private val containedIds: List<String>) : IFieldBuild
DateFacetBuildHelpers.buildFromNormalizedSingleDate(date)
else emptyList()
NS.rico + "DateRange" ->
if (isNormalized)
DateFacetBuildHelpers.buildFromNormalizedDateRange(date)
else emptyList()
if (isNormalized) {
try {
DateFacetBuildHelpers.buildFromNormalizedDateRange(date)
} catch (ex: NumberFormatException) {
log.error("Could not parse normalized date $date in resource $key.")
emptyList<String>()
}
} else {
emptyList()
}
else -> emptyList()
}
dateContainers.add(
......
......@@ -41,7 +41,7 @@ class FacettedContainerBuilder(
return identifiers.contains(jsonObject[KEYS.entityId])
}
override fun append(jsonObject: JsonObject): String {
override fun append(key: String, jsonObject: JsonObject): String {
val filterAndFacet = facetFunction(jsonObject)
containers.add(
FacettedContainer(
......
......@@ -23,6 +23,6 @@ import com.beust.klaxon.JsonObject
interface IFieldBuilder {
fun filter(jsonObject: JsonObject): Boolean
fun append(jsonObject: JsonObject): String
fun append(key: String, jsonObject: JsonObject): String
fun build(): List<Any>
}
......@@ -38,7 +38,7 @@ class PersonFacetBuilder : IFieldBuilder {
}
}
override fun append(jsonObject: JsonObject): String {
override fun append(key: String, jsonObject: JsonObject): String {
val result = FacetBuildHelpers.person(jsonObject)
return if (result.second.isNotEmpty()) {
personFacetValues.addAll(result.second)
......
......@@ -38,7 +38,7 @@ class PlaceFacetBuilder : IFieldBuilder {
}
}
override fun append(jsonObject: JsonObject): String {
override fun append(key: String, jsonObject: JsonObject): String {
val result = FacetBuildHelpers.place(jsonObject)
return if (result.second.isNotEmpty()) {
placeFacetValues.addAll(result.second)
......
......@@ -41,7 +41,7 @@ class SuggestContainerBuilder(private val hasSubjectIds: List<String>) : IFieldB
}
}
override fun append(jsonObject: JsonObject): String {
override fun append(key: String, jsonObject: JsonObject): String {
return when (jsonObject[KEYS.atType]) {
NS.skos + KEYS.Concept -> parseKeywords(jsonObject)
NS.rico + KEYS.Title -> parseTitles(jsonObject)
......
......@@ -80,9 +80,11 @@ object DateFacetBuildHelpers {
while (fromDecadeAsInt != untilDecadeAsInt) {
fromDecadeAsInt += 10
results.add(
"$level_2$separator$fromCentury$separator${getDecade(
fromDecadeAsInt
)}$separator"
"$level_2$separator$fromCentury$separator${
getDecade(
fromDecadeAsInt
)
}$separator"
)
}
results
......@@ -96,9 +98,12 @@ object DateFacetBuildHelpers {
while (fromCenturyAsInt != untilCenturyAsInt) {
results.add(
"$level_1$separator${getCentury(
fromCenturyAsInt
)}$separator")
"$level_1$separator${
getCentury(
fromCenturyAsInt
)
}$separator"
)
fromCenturyAsInt += 1
}
results.add(
......@@ -110,11 +115,15 @@ object DateFacetBuildHelpers {
while (fromDecadeAsInt != untilDecadeAsInt) {
fromDecadeAsInt += 10
results.add(
"$level_2$separator${getCentury(
fromDecadeAsInt / 100
)}$separator${getDecade(
fromDecadeAsInt
)}$separator"
"$level_2$separator${
getCentury(
fromDecadeAsInt / 100
)
}$separator${
getDecade(
fromDecadeAsInt
)
}$separator"
)
}
results
......
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