Commit da6bbc41 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Add getFieldName to improve logging.

parent 7a09a8e8
......@@ -108,9 +108,11 @@ class ResourceBuilder(
try {
recordFieldMapper.apply(source, record!!)
} catch (ex: InvalidInputException) {
errorMessages.add(ex.localizedMessage + " Could not apply ${recordFieldMapper::class.simpleName} for record.")
errorMessages.add("Could not apply ${recordFieldMapper::class.simpleName} for record for field " +
"'${recordFieldMapper.getFieldName()}', because: ${ex::class.java}: ${ex.localizedMessage}.")
} catch (ex: Exception) {
errorMessages.add(ex.localizedMessage + " Could not apply ${recordFieldMapper::class.simpleName} for record.")
errorMessages.add("Could not apply ${recordFieldMapper::class.simpleName} for record for field " +
"'${recordFieldMapper.getFieldName()}', because: ${ex::class.java}: ${ex.localizedMessage}.")
isFatal = true
}
}
......@@ -164,7 +166,8 @@ class ResourceBuilder(
countExpanded += 1
}
if (count == countExpanded) {
val message = "Removed digital object from resource as there are no properties extracted from the data."
val message =
"Removed digital object from resource as there are no properties extracted from the data."
log.warn(message)
errorMessages.add(message)
null
......
package ch.memobase.mapping.mappers
abstract class AbstractFieldMapper() : IFieldMapper
abstract class AbstractFieldMapper : IFieldMapper
......@@ -20,6 +20,11 @@ package ch.memobase.mapping.mappers
import ch.memobase.builder.IResource
import ch.memobase.mapping.KEYS
import ch.memobase.mapping.fields.ConstantField
import ch.memobase.mapping.fields.DirectMapField
import ch.memobase.mapping.fields.LanguageField
import ch.memobase.mapping.fields.ListField
import ch.memobase.mapping.fields.PrefixField
class AgentFieldMapper : TypeFieldMapper() {
var sourceKey: String = ""
......@@ -38,4 +43,16 @@ class AgentFieldMapper : TypeFieldMapper() {
}
}
}
override fun getFieldName(): String {
return fields[0].let {
when (it) {
is ConstantField -> it.key
is PrefixField -> it.key
is DirectMapField -> it.key
is ListField -> it.key
is LanguageField -> it.key
}
}
}
}
......@@ -63,4 +63,13 @@ class CarrierTypeMapper(val field: AnnotationField) : AbstractFieldMapper() {
}
}
}
override fun getFieldName(): String {
return when (field) {
is MappedAnnotationField -> field.key
is ConstantField -> field.key
is LanguageField -> field.key
is ListField -> field.key
}
}
}
......@@ -25,4 +25,8 @@ class ConstantFieldMapper(val constantField: ConstantField) : AbstractFieldMappe
override fun apply(source: Map<String, Any>, subject: IResource) {
subject.addLiteral(constantField.key, constantField.toLiteral())
}
override fun getFieldName(): String {
return constantField.key
}
}
......@@ -41,4 +41,8 @@ class DateFieldMapper(private val directMapField: DirectMapField) : AbstractFiel
}
}
}
override fun getFieldName(): String {
return directMapField.directKey
}
}
......@@ -41,4 +41,8 @@ class DirectFieldMapper(private val directMapField: DirectMapField) : AbstractFi
}
}
}
override fun getFieldName(): String {
return directMapField.directKey
}
}
......@@ -21,10 +21,13 @@ package ch.memobase.mapping.mappers
import ch.memobase.builder.IResource
import ch.memobase.mapping.fields.ConfigField
import ch.memobase.mapping.fields.ConstantField
import ch.memobase.mapping.fields.DirectMapField
import ch.memobase.mapping.fields.FieldParsers
import ch.memobase.mapping.fields.LanguageField
import ch.memobase.mapping.fields.ListField
import ch.memobase.mapping.fields.MappedAnnotationField
import ch.memobase.mapping.fields.PrefixField
import ch.memobase.mapping.fields.SimpleAnnotationField
import ch.memobase.mapping.fields.SourceElement
import ch.memobase.mapping.fields.SourceElement.Empty
import ch.memobase.mapping.fields.SourceElement.SimpleString
......@@ -101,4 +104,16 @@ class ExpandedRuleFieldMapper(
subject.addRule(ricoType, it)
}
}
override fun getFieldName(): String {
return configField[0].let {
when (it) {
is ConstantField -> it.key
is PrefixField -> it.key
is DirectMapField -> it.key
is ListField -> it.key
is LanguageField -> it.key
}
}
}
}
......@@ -22,4 +22,5 @@ import ch.memobase.builder.IResource
interface IFieldMapper {
fun apply(source: Map<String, Any>, subject: IResource)
fun getFieldName(): String
}
......@@ -30,4 +30,8 @@ class LanguageFieldMapper(private val languageField: LanguageField) : AbstractFi
}
}
}
override fun getFieldName(): String {
return languageField.key
}
}
......@@ -30,4 +30,8 @@ class ListFieldMapper(private val listField: ListField) :
}
}
}
override fun getFieldName(): String {
return listField.key
}
}
......@@ -19,6 +19,11 @@
package ch.memobase.mapping.mappers
import ch.memobase.builder.IResource
import ch.memobase.mapping.fields.ConstantField
import ch.memobase.mapping.fields.DirectMapField
import ch.memobase.mapping.fields.LanguageField
import ch.memobase.mapping.fields.ListField
import ch.memobase.mapping.fields.PrefixField
class PlaceFieldMapper : TypeFieldMapper() {
override fun apply(source: Map<String, Any>, subject: IResource) {
......@@ -27,4 +32,16 @@ class PlaceFieldMapper : TypeFieldMapper() {
subject.addPlace(agentClassType, it)
}
}
override fun getFieldName(): String {
return fields[0].let {
when (it) {
is ConstantField -> it.key
is PrefixField -> it.key
is DirectMapField -> it.key
is ListField -> it.key
is LanguageField -> it.key
}
}
}
}
......@@ -41,4 +41,8 @@ class PrefixFieldMapper(private val prefixField: PrefixField) : AbstractFieldMap
}
}
}
override fun getFieldName(): String {
return prefixField.key
}
}
......@@ -63,4 +63,13 @@ class RicoConceptMapper(private val rdfType: String, val field: AnnotationField)
}
}
}
override fun getFieldName(): String {
return when (field) {
is MappedAnnotationField -> field.key
is ConstantField -> field.key
is LanguageField -> field.key
is ListField -> field.key
}
}
}
......@@ -22,10 +22,12 @@ import ch.memobase.builder.IResource
import ch.memobase.mapping.KEYS
import ch.memobase.mapping.fields.ConfigField
import ch.memobase.mapping.fields.ConstantField
import ch.memobase.mapping.fields.DirectMapField
import ch.memobase.mapping.fields.FieldParsers
import ch.memobase.mapping.fields.LanguageField
import ch.memobase.mapping.fields.ListField
import ch.memobase.mapping.fields.MappedAnnotationField
import ch.memobase.mapping.fields.PrefixField
import ch.memobase.mapping.fields.SourceElement.Empty
import ch.memobase.mapping.fields.SourceElement.SimpleString
import ch.memobase.mapping.fields.SourceElement.StringList
......@@ -69,4 +71,16 @@ class RuleFieldMapper(private val configField: ConfigField) : AbstractFieldMappe
}
}
}
override fun getFieldName(): String {
return configField.let {
when (it) {
is ConstantField -> it.key
is PrefixField -> it.key
is DirectMapField -> it.key
is ListField -> it.key
is LanguageField -> it.key
}
}
}
}
......@@ -19,6 +19,11 @@
package ch.memobase.mapping.mappers
import ch.memobase.builder.IResource
import ch.memobase.mapping.fields.ConstantField
import ch.memobase.mapping.fields.DirectMapField
import ch.memobase.mapping.fields.LanguageField
import ch.memobase.mapping.fields.ListField
import ch.memobase.mapping.fields.PrefixField
import ch.memobase.rdf.SKOS
class SkosConceptFieldMapper : TypeFieldMapper() {
......@@ -32,4 +37,16 @@ class SkosConceptFieldMapper : TypeFieldMapper() {
}
}
}
override fun getFieldName(): String {
return fields[0].let {
when (it) {
is ConstantField -> it.key
is PrefixField -> it.key
is DirectMapField -> it.key
is ListField -> it.key
is LanguageField -> it.key
}
}
}
}
Supports Markdown
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