Commit 28f50d76 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Add rico:type for Record as required property.

parent 12a52710
......@@ -22,12 +22,13 @@ import org.apache.jena.rdf.model.Resource
import org.memobase.rdf.NS
import org.memobase.rdf.RICO
class Record(id: String, recordSetId: String, institutionId: String) :
class Record(id: String, type: String, recordSetId: String, institutionId: String) :
RecordResource(institutionId) {
override val resource: Resource = model.createResource(NS.memr + institutionId + "-" + id)
init {
addRdfType(RICO.Record)
resource.addProperty(RICO.type, type)
resource.addProperty(RICO.isPartOf, recordSetUri(recordSetId))
resource.addProperty(RICO.heldBy, institutionUri)
resource.addProperty(RICO.hasProvenance, institutionUri)
......
......@@ -26,6 +26,7 @@ import java.io.StringWriter
class ResourceBuilder(
recordIdField: String,
recordType: String,
recordFieldMappers: List<IFieldMapper>,
physicalObjectFieldMappers: List<IFieldMapper>,
source: Map<String, String>,
......@@ -43,7 +44,7 @@ class ResourceBuilder(
throw InvalidMappingException("No id for record found in field '$recordIdField'.")
}
record =
Record(recordId, recordSetId, institutionId)
Record(recordId, recordType, recordSetId, institutionId)
for (recordFieldMapper in recordFieldMappers) {
recordFieldMapper.apply(source, record)
}
......
......@@ -26,6 +26,7 @@ import org.memobase.rdf.RICO
object KEYS {
const val uri = "uri"
const val type = "type"
// Literal Mappings
......
......@@ -45,6 +45,7 @@ import kotlin.system.exitProcess
class MappingConfig(directory: String) {
var uriField: String = ""
var recordType = ""
val recordFieldMappers = mutableListOf<IFieldMapper>()
val physicalObjectFieldMappers = mutableListOf<IFieldMapper>()
val digitalObjectFieldMappers = mutableListOf<IFieldMapper>()
......@@ -54,6 +55,8 @@ class MappingConfig(directory: String) {
private val languageTypes = listOf("content", "caption")
private val ruleTypes = listOf("rights", "access", "holder", "usage")
private val recordTypes = listOf("Film", "Foto", "Radio", "Ton", "Tonbildschau", "TV", "Video")
private val log = LogManager.getLogger("MappingConfigParser")
init {
......@@ -81,6 +84,9 @@ class MappingConfig(directory: String) {
log.error("Mapping is missing uri field in record, which is required.")
exitProcess(1)
}
if (recordType == "") {
log.error("Mapping is missing record.type field which is required. Assign one value out of $recordTypes.")
}
}
......@@ -88,6 +94,14 @@ class MappingConfig(directory: String) {
for (entry in source) {
when (val key = entry.key) {
KEYS.uri -> uriField = entry.value as String
KEYS.type -> {
val value = entry.value as String
if (recordTypes.contains(value)) {
recordType = value
} else {
throw InvalidMappingException("Record Type mapping is not a valid value. Choose one of $recordTypes.")
}
}
// literal properties
KEYS.name, KEYS.title, KEYS.descriptiveNote, KEYS.scopeAndContent,
KEYS.abstract, KEYS.source, KEYS.hasSponsoringAgent, KEYS.hasFindingAid ->
......
......@@ -48,6 +48,7 @@ class Tests {
val values = Klaxon().parse<Map<String, String>>(text)
val resourceBuilder = ResourceBuilder(
config.uriField,
config.recordType,
config.recordFieldMappers,
config.physicalObjectFieldMappers,
values!!,
......
record:
uri: original_id
type: Foto # is always a constant!
title:
de: titel
descriptiveNote: # rico:descriptiveNote
......
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