In order to mitigate against the brute force attacks against Gitlab accounts, we are moving to all edu-ID Logins. We would like to remind you to link your account with your edu-id. Login will be possible only by edu-ID after November 30, 2021. Here you can find the instructions for linking your account.

If you don't have a SWITCH edu-ID, you can create one with this guide here

kind regards

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

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