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

Merge branch 'proxyType' into 'master'

Proxy type

Adds an internal proxyType value to the digital object.
The default value is `proxydirect`.
The field can be a direct mapped field, a constant or a prefixed field.

See merge request !1
parents 94f3d008 c14145b8
Pipeline #33458 passed with stages
in 2 minutes and 58 seconds
......@@ -46,7 +46,7 @@ dependencies {
//compile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-high-level-client', version: '7.1.0'
implementation "org.apache.logging.log4j:log4j-api:${log4jV}"
implementation 'org.memobase:memobase-service-utilities:3.0.1'
implementation 'org.memobase:memobase-service-utilities:3.0.3'
// YAML Parser
implementation 'org.snakeyaml:snakeyaml-engine:2.1'
......
......@@ -20,11 +20,12 @@ package ch.memobase.builder
import ch.memobase.helpers.StringHelpers
import ch.memobase.mapping.KEYS
import ch.memobase.rdf.MB
import ch.memobase.rdf.NS
import ch.memobase.rdf.RICO
import org.apache.jena.rdf.model.Resource
class DigitalObject(sourceId: String, recordSetId: String, institutionId: String, count: Int) :
class DigitalObject(sourceId: String, recordSetId: String, institutionId: String, count: Int, hasProxyType: Boolean) :
Instantiation(institutionId) {
private val id = recordSetId + "-" + StringHelpers.normalizeId(sourceId) + "-" + count
override val resource: Resource = model.createResource(NS.mbdo + id)
......@@ -33,5 +34,13 @@ class DigitalObject(sourceId: String, recordSetId: String, institutionId: String
addRdfType(RICO.Instantiation)
resource.addProperty(RICO.type, "digitalObject")
addRicoConcept(KEYS.identifiers, "main", listOf(literal(id)))
// no supplied proxy type present.
if (!hasProxyType) {
addDefaultProxyType()
}
}
private fun addDefaultProxyType() {
resource.addProperty(MB.proxyType, KEYS.defaultProxyType)
}
}
......@@ -24,10 +24,10 @@ import ch.memobase.mapping.MapperConfiguration
import ch.memobase.mapping.fields.ConstantField
import ch.memobase.mapping.fields.MappedAnnotationField
import com.beust.klaxon.JsonArray
import java.io.StringWriter
import org.apache.jena.riot.RDFDataMgr
import org.apache.jena.riot.RDFFormat
import org.apache.logging.log4j.LogManager
import java.io.StringWriter
class ResourceBuilder(
private val source: Map<String, Any>,
......@@ -50,11 +50,13 @@ class ResourceBuilder(
when (val id = source[config.uri]) {
is String -> recordId = id
is Int -> recordId = id.toString()
is JsonArray<*> -> errorMessages.add("Found multiple values in the field '${config.uri}' for identifiers: ${
id.joinToString(
", "
)
}.")
is JsonArray<*> -> errorMessages.add(
"Found multiple values in the field '${config.uri}' for identifiers: ${
id.joinToString(
", "
)
}."
)
null -> errorMessages.add("The value for id is 'null' in field '${config.uri}'.")
else -> errorMessages.add("Invalid value '$id' for id in field '${config.uri}'.")
}
......@@ -94,7 +96,14 @@ class ResourceBuilder(
}
fun generateRecord(): ResourceBuilder {
record = Record(recordId, recordTypeValue, recordSetId, institutionId, config.sponsoredByMemoriav, isPublished)
record = Record(
recordId,
recordTypeValue,
recordSetId,
institutionId,
config.sponsoredByMemoriav,
isPublished
)
for (recordFieldMapper in config.recordFieldMappers) {
try {
recordFieldMapper.apply(source, record!!)
......@@ -105,6 +114,7 @@ class ResourceBuilder(
isFatal = true
}
}
return this
}
......@@ -134,7 +144,7 @@ class ResourceBuilder(
fun generateDigitalObject(): ResourceBuilder {
digitalObject =
if (config.digitalFieldMappers.isNotEmpty()) {
val digitalObject = DigitalObject(recordId, recordSetId, institutionId, 1)
val digitalObject = DigitalObject(recordId, recordSetId, institutionId, 1, config.hasProxyType)
config.digitalFieldMappers.forEach {
try {
it.apply(source, digitalObject)
......
......@@ -18,12 +18,7 @@
package ch.memobase.mapping
import ch.memobase.rdf.DC
import ch.memobase.rdf.EBUCORE
import ch.memobase.rdf.NS
import ch.memobase.rdf.RDA
import ch.memobase.rdf.RICO
import ch.memobase.rdf.SCHEMA
import ch.memobase.rdf.*
object KEYS {
......@@ -34,7 +29,7 @@ object KEYS {
const val uri = "uri"
const val type = "type"
// Literal Mappings
// Literal Mappings on Record (mostly)
const val name = "name"
const val descriptiveNote = "descriptiveNote"
......@@ -48,6 +43,8 @@ object KEYS {
const val relation = "relation"
const val conditionsOfUse = "conditionsOfUse"
const val conditionsOfAccess = "conditionsOfAccess"
const val proxyType = "proxy"
const val defaultProxyType = "proxydirect"
// Rules
......@@ -154,6 +151,7 @@ object KEYS {
val keysToPropertyMap = mapOf(
Pair(abstract, DC.abstract),
Pair(proxyType, MB.proxyType),
Pair(relatedPlaces, DC.spatial),
Pair(name, RICO.name),
Pair(title, RICO.title),
......
......@@ -6,6 +6,7 @@ import ch.memobase.mapping.mappers.AbstractFieldMapper
data class MapperConfiguration(
val uri: String,
val sponsoredByMemoriav: Boolean,
val hasProxyType: Boolean,
val recordType: SimpleAnnotationField,
val recordFieldMappers: List<AbstractFieldMapper>,
val physicalFieldMappers: List<AbstractFieldMapper>,
......
......@@ -30,6 +30,7 @@ import org.apache.logging.log4j.LogManager
class MappingConfigurationParser(data: ByteArray) {
private var uriField: String = ""
private var localRecordType: SimpleAnnotationField? = null
private var hasProxyType: Boolean = false
private val recordType: SimpleAnnotationField
private val recordFieldMappers = mutableListOf<AbstractFieldMapper>()
private val physicalObjectFieldMappers = mutableListOf<AbstractFieldMapper>()
......@@ -74,6 +75,7 @@ class MappingConfigurationParser(data: ByteArray) {
fun get() = MapperConfiguration(
uriField,
sponsoredByMemoriav,
hasProxyType,
recordType,
recordFieldMappers,
physicalObjectFieldMappers,
......@@ -138,6 +140,12 @@ class MappingConfigurationParser(data: ByteArray) {
private fun parseDigitalInstantiationConfig(source: Map<String, Any>) {
for (entry in source) {
when (val key = entry.key) {
// checks of the proxy type is defined locally.
KEYS.proxyType -> {
val field = FieldParsers.parseSimpleAnnotationField(key, entry.value)
digitalObjectFieldMappers.add(MapperParsers.buildAnnotationMappers(field))
hasProxyType = true
}
KEYS.locator, KEYS.descriptiveNote, KEYS.duration, KEYS.conditionsOfUse, KEYS.conditionsOfAccess ->
digitalObjectFieldMappers.add(MapperParsers.buildAnnotationMappers(entry))
KEYS.identifiers ->
......
......@@ -28,6 +28,7 @@ class TestMappingParser {
MapperConfiguration(
"TestField",
false,
false,
FieldParsers.parseSimpleAnnotationField("type", mapOf(Pair("const", "Foto"))),
emptyList(),
emptyList(),
......@@ -44,6 +45,7 @@ class TestMappingParser {
MapperConfiguration(
"TestField",
true,
false,
FieldParsers.parseSimpleAnnotationField("type", mapOf(Pair("const", "Foto"))),
emptyList(),
emptyList(),
......
{"digitalFieldMappers" : [{"field" : {"directField" : "MainID", "directKey" : "main", "field" : "MainID", "key" : "main"}}], "physicalFieldMappers" : [{"field" : {"directField" : "MainID", "directKey" : "main", "field" : "MainID", "key" : "main"}}], "recordFieldMappers" : [{"field" : {"directField" : "MainID", "directKey" : "main", "field" : "MainID", "key" : "main"}}], "recordType" : {"constant" : "Foto", "key" : "type"}, "sponsoredByMemoriav" : true, "uri" : "TestField"}
\ No newline at end of file
{"digitalFieldMappers" : [{"field" : {"directField" : "MainID", "directKey" : "main", "field" : "MainID", "key" : "main"}}], "hasProxyType" : false, "physicalFieldMappers" : [{"field" : {"directField" : "MainID", "directKey" : "main", "field" : "MainID", "key" : "main"}}], "recordFieldMappers" : [{"field" : {"directField" : "MainID", "directKey" : "main", "field" : "MainID", "key" : "main"}}], "recordType" : {"constant" : "Foto", "key" : "type"}, "sponsoredByMemoriav" : true, "uri" : "TestField"}
\ No newline at end of file
{"digitalFieldMappers" : [], "physicalFieldMappers" : [], "recordFieldMappers" : [{"agentClassType" : "subject", "fields" : [{"fields" : [{"sources" : [{"directField" : "Schlagworte", "directKey" : "prefLabel", "field" : "Schlagworte", "key" : "prefLabel"}], "tag" : "fr"}], "key" : "prefLabel"}, {"constant" : "Ursprungsfeld: Mots clés", "key" : "editorialNote"}]}, {"agentClassType" : "genre", "fields" : [{"fields" : [{"sources" : [{"directField" : "Genre", "directKey" : "prefLabel", "field" : "Genre", "key" : "prefLabel"}], "tag" : "fr"}], "key" : "prefLabel"}, {"constant" : "Ursprungsfeld: Genre", "key" : "editorialNote"}]}], "recordType" : {"constant" : "Foto", "key" : "type"}, "sponsoredByMemoriav" : false, "uri" : "id"}
\ No newline at end of file
{"digitalFieldMappers" : [], "hasProxyType" : false, "physicalFieldMappers" : [], "recordFieldMappers" : [{"agentClassType" : "subject", "fields" : [{"fields" : [{"sources" : [{"directField" : "Schlagworte", "directKey" : "prefLabel", "field" : "Schlagworte", "key" : "prefLabel"}], "tag" : "fr"}], "key" : "prefLabel"}, {"constant" : "Ursprungsfeld: Mots clés", "key" : "editorialNote"}]}, {"agentClassType" : "genre", "fields" : [{"fields" : [{"sources" : [{"directField" : "Genre", "directKey" : "prefLabel", "field" : "Genre", "key" : "prefLabel"}], "tag" : "fr"}], "key" : "prefLabel"}, {"constant" : "Ursprungsfeld: Genre", "key" : "editorialNote"}]}], "recordType" : {"constant" : "Foto", "key" : "type"}, "sponsoredByMemoriav" : false, "uri" : "id"}
\ No newline at end of file
......@@ -5,6 +5,16 @@
@prefix ebucore: <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
_:b0 a rico:CreationRelation ;
rico:creationRelationHasSource <https://memobase.ch/record/rs1-1> ;
rico:creationRelationHasTarget [ a rico:Person ;
rico:agentIsTargetOfCreationRelation
_:b0 ;
rico:name "Third Person"
] ;
rico:name "Relation 3" ;
rico:type "creator" .
<https://memobase.ch/record/rs1-1>
a rico:Record ;
rdau:P60451 <https://memobase.ch/institution/mrv> ;
......@@ -17,34 +27,24 @@
] ;
rico:isPartOf <https://memobase.ch/recordSet/rs1> ;
rico:recordResourceOrInstantiationIsSourceOfCreationRelation
_:b0 , _:b1 , _:b2 ;
_:b1 , _:b2 , _:b0 ;
rico:type "Foto" .
_:b2 a rico:CreationRelation ;
rico:creationRelationHasSource <https://memobase.ch/record/rs1-1> ;
rico:creationRelationHasTarget [ a rico:Person ;
rico:agentIsTargetOfCreationRelation
_:b2 ;
rico:name "Second Person"
] ;
rico:type "creator" .
_:b1 a rico:CreationRelation ;
rico:creationRelationHasSource <https://memobase.ch/record/rs1-1> ;
rico:creationRelationHasTarget [ a rico:Person ;
rico:agentIsTargetOfCreationRelation
_:b1 ;
rico:name "Third Person"
rico:name "First Person"
] ;
rico:name "Relation 3" ;
rico:name "Relation 1" ;
rico:type "creator" .
_:b0 a rico:CreationRelation ;
_:b2 a rico:CreationRelation ;
rico:creationRelationHasSource <https://memobase.ch/record/rs1-1> ;
rico:creationRelationHasTarget [ a rico:Person ;
rico:agentIsTargetOfCreationRelation
_:b0 ;
rico:name "First Person"
_:b2 ;
rico:name "Second Person"
] ;
rico:name "Relation 1" ;
rico:type "creator" .
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